Add JSHint Static Analysis and Configuration#52
Open
sittingthyme wants to merge 1 commit intomainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's the fully revised version:
JSHint Integration Report
What Is JSHint?
JSHint is a community-driven JavaScript static analysis tool that scans source files to detect errors, unsafe patterns, and style violations without executing any code. It was designed as a more configurable alternative to JSLint, and excels in projects like NodeBB where JavaScript runs in multiple environments — both server-side (Node.js) and client-side (browser).
📄 Documentation · 🔗 Source on GitHub
Static vs. Dynamic Analysis
JSHint is strictly a static analysis tool. It reads and reasons about source code at rest — no code is ever executed. This makes it fast and safe to run anywhere, but it also means it cannot observe runtime behavior, track dynamic type changes, or catch errors that only manifest during execution.
What Was Added
jshintdevDependency andnpm run lint:jshintscript inpackage.json.jshintrcconfigured foresversion: 2021, dualnode/browserenvironments, and rules covering strict equality, unused variables, curly braces, quote style, line length (140 chars), and dangerous API usageapp,ajaxify,socket,config,$,jQuery) declared to suppress false positives from NodeBB's runtime-injected variables.jshintignoreexcludingnode_modules/,build/,coverage/,public/,logs/,vendor/Full output from
npm run lint:jshintis saved tojshint-output.txt. Most warnings relate to unused variables, loose equality comparisons, and line length violations.Types of Problems It Catches
JSHint targets a focused set of JavaScript quality issues:
JSHint does not catch runtime errors, logic bugs, async/await misuse, or type-level issues. Those require deeper tooling such as ESLint plugins, TypeScript, or dedicated SAST tools.
Customization Options
JSHint is configured via
.jshintrc(JSON) and.jshintignore. Key customization axes include:node,browser,esversion) declare which globals and syntax are valid, preventing false positives for environment-specific APIsmaxlen: 140)app,$,socket, etc..jshintrcthat inherits from or overrides the root config, enabling different rules for legacy vs. modern codeFor this project, the dual
node/browserenvironment setup and theglobalslist are the most important customizations given NodeBB's mixed server/client architecture.Integration into the Development Process
JSHint is best treated as a lightweight first-pass gate rather than a primary linter. Recommended integration points:
npm run lint:jshintviahuskyto catch issues before they reach a PRjshint public/src/for client-side code orjshint src/for server modules to reduce noise and execution timeFalse Positives, False Negatives, and Low-Value Warnings
False Positives
JSHint generates a moderate number of false positives on a codebase like NodeBB. The most common sources:
globalsconfig will trigger a spuriousundefwarningimport/exportsupport depends onesversionand module mode settings; mismatches generate misleading errorsFalse Negatives
JSHint's shallow analysis means it misses many real bugs. It does not track data flow, so a variable assigned incorrectly won't be flagged if it's technically "used." It also has no understanding of async patterns, promises, or complex program semantics — a mishandled
awaitwill not register as an issue.True Positives You May Not Care About
Running JSHint across a large existing codebase will surface many technically valid warnings that are low priority in practice:
maxlenviolations in legacy or generated files that are harmlessunusedwarnings on intentional(err, result)callback parameters whereerris deliberately ignoredquotmarkruleThe output in
jshint-output.txtreflects this — warnings are high in volume but individually low in severity.Strategic Assessment
Pros: Fast, lightweight, easy to run locally or in CI, highly configurable, and handles mixed Node/browser environments cleanly.
Cons: Meaningful overlap with ESLint creates maintenance overhead. JSHint has a smaller, less active ecosystem and lacks the semantic depth of modern ESLint rules or TypeScript.
Recommended Next Steps
- Scope JSHint to specific directories (e.g., legacy or client-side code) to reduce redundancy with ESLint
- Narrow the ruleset to focus on gaps ESLint doesn't currently cover — particularly
- Add a
- Use inline overrides or scoped
Here's the fully revised version:latedef,freeze, andnoarghuskypre-commit hook to run JSHint automatically on changed files.jshintrcfiles to suppress known-good patterns and reduce noise in the reported outputJSHint Integration Report
What Is JSHint?
JSHint is a community-driven JavaScript static analysis tool that scans source files to detect errors, unsafe patterns, and style violations without executing any code. It was designed as a more configurable alternative to JSLint, and excels in projects like NodeBB where JavaScript runs in multiple environments — both server-side (Node.js) and client-side (browser).
📄 [Documentation](https://jshint.com/docs/) · 🔗 [Source on GitHub](https://github.com/jshint/jshint)
Static vs. Dynamic Analysis
JSHint is strictly a static analysis tool. It reads and reasons about source code at rest — no code is ever executed. This makes it fast and safe to run anywhere, but it also means it cannot observe runtime behavior, track dynamic type changes, or catch errors that only manifest during execution.
What Was Added
jshintdevDependency andnpm run lint:jshintscript inpackage.json.jshintrcconfigured foresversion: 2021, dualnode/browserenvironments, and rules covering strict equality, unused variables, curly braces, quote style, line length (140 chars), and dangerous API usageapp,ajaxify,socket,config,$,jQuery) declared to suppress false positives from NodeBB's runtime-injected variables.jshintignoreexcludingnode_modules/,build/,coverage/,public/,logs/,vendor/Full output from
npm run lint:jshintis saved tojshint-output.txt. Most warnings relate to unused variables, loose equality comparisons, and line length violations.Types of Problems It Catches
JSHint targets a focused set of JavaScript quality issues:
undefunusedeqeqeq==instead of===, which causes type-coercion bugscurlylatedefnoargarguments.caller/arguments.calleefreezenonbspquotmarkmaxlenJSHint does not catch runtime errors, logic bugs, async/await misuse, or type-level issues. Those require deeper tooling such as ESLint plugins, TypeScript, or dedicated SAST tools.
Customization Options
JSHint is configured via
.jshintrc(JSON) and.jshintignore. Key customization axes include:node,browser,esversion) declare which globals and syntax are valid, preventing false positives for environment-specific APIsmaxlen: 140)app,$,socket, etc..jshintrcthat inherits from or overrides the root config, enabling different rules for legacy vs. modern codeFor this project, the dual
node/browserenvironment setup and theglobalslist are the most important customizations given NodeBB's mixed server/client architecture.Integration into the Development Process
JSHint is best treated as a lightweight first-pass gate rather than a primary linter. Recommended integration points:
npm run lint:jshintviahuskyto catch issues before they reach a PRjshint public/src/for client-side code orjshint src/for server modules to reduce noise and execution timeFalse Positives, False Negatives, and Low-Value Warnings
False Positives
JSHint generates a moderate number of false positives on a codebase like NodeBB. The most common sources:
globalsconfig will trigger a spuriousundefwarningimport/exportsupport depends onesversionand module mode settings; mismatches generate misleading errorsFalse Negatives
JSHint's shallow analysis means it misses many real bugs. It does not track data flow, so a variable assigned incorrectly won't be flagged if it's technically "used." It also has no understanding of async patterns, promises, or complex program semantics — a mishandled
awaitwill not register as an issue.True Positives You May Not Care About
Running JSHint across a large existing codebase will surface many technically valid warnings that are low priority in practice:
maxlenviolations in legacy or generated files that are harmlessunusedwarnings on intentional(err, result)callback parameters whereerris deliberately ignoredquotmarkruleThe output in
jshint-output.txtreflects this — warnings are high in volume but individually low in severity.Strategic Assessment
Pros: Fast, lightweight, easy to run locally or in CI, highly configurable, and handles mixed Node/browser environments cleanly.
Cons: Meaningful overlap with ESLint creates maintenance overhead. JSHint has a smaller, less active ecosystem and lacks the semantic depth of modern ESLint rules or TypeScript.
Recommended Next Steps
latedef,freeze, andnoarghuskypre-commit hook to run JSHint automatically on changed files.jshintrcfiles to suppress known-good patterns and reduce noise in the reported output