Registry / testing / jshint

jshint

JSON →
library2.13.6jsnpmunverified

JSHint is a static code analysis tool for JavaScript that identifies errors and potential problems, including typos, syntax errors, implicit type conversions, and variable leaks. Its primary goal is to help developers prevent common mistakes in complex JavaScript programs. The current stable version is 2.13.6, with its most recent update in November 2022. While it previously saw regular bug-fix releases, its development cadence has slowed considerably compared to its peak. A key differentiator for JSHint is its focus on detecting bugs and structural issues in the code rather than primarily enforcing code style, offering high configurability through `.jshintrc` files and inline comments to adapt to diverse execution environments. It predates many modern linters and has historically been crucial for spotting critical 'red flags' that could lead to extensive debugging if left unaddressed.

npm install jshint
INSTALL
IMPORT
SIG · JSHINT
J
jshint
testingjavascriptv2.13.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSHINT
const { JSHINT } = require('jshint');
import { JSHINT } from 'jshint';
JSHint is primarily a CommonJS module. While bundlers can handle ESM imports, direct Node.js ESM usage for programmatic linting is not the standard or officially supported way for the core library.
cli
npx jshint your-file.js
require('jshint').cli.run()
The primary way to use JSHint is via its command-line interface, typically invoked through `npx` or a globally installed package. Direct programmatic access to the CLI runner is not a documented API for users.
JSHINT.data()
const result = JSHINT(code, options, globals); const data = JSHINT.data();
After running JSHINT on code, detailed analysis data (e.g., global variables, functions) can be accessed via `JSHINT.data()`.

Demonstrates programmatic usage of JSHint to lint a JavaScript string, configured for a Node.js environment, and prints any detected errors or warnings.

const { JSHINT } = require('jshint'); const javascriptCode = ` function greet(name) { console.log('Hello, ' + name) // Missing semicolon here intentionally } const myName = 'World'; greet(myName); // A variable not defined in this scope undefinedVar = 1; `; // JSHint options: enforce strict mode, allow console const options = { strict: true, browser: false, // For Node.js environment node: true, // For Node.js globals like console undef: true // Warn if variables are used without being declared }; // Lint the code JSHINT(javascriptCode, options); // Log any errors found if (JSHINT.errors.length > 0) { console.log('JSHint found issues:'); JSHINT.errors.forEach(error => { if (error) { console.error(` Line ${error.line}, Col ${error.character}: ${error.reason} (${error.code})`); } }); } else { console.log('No JSHint issues found.'); }
jshint --version
Debug
Known issues
gotchaJSHint's development has significantly slowed, with the last major update in late 2022. For new projects, or those requiring support for the latest ECMAScript features (ES2023+), JSX, or TypeScript, more actively maintained alternatives like ESLint are generally preferred due to their extensibility and ecosystem.
fix
Consider migrating to ESLint for projects requiring modern JavaScript features, plugin ecosystems, or TypeScript support. ESLint offers broader community support and more frequent updates.
affects: >=2.13.6
gotchaJSHint does not natively support TypeScript or JSX. Attempting to lint such files will likely result in numerous parsing errors.
fix
Use dedicated linters for TypeScript (e.g., ESLint with `@typescript-eslint/parser`) or JSX (e.g., ESLint with `eslint-plugin-react`). JSHint is strictly for JavaScript.
affects: *
gotchaThe primary programmatic interface for JSHint uses CommonJS modules (`require`). Direct ESM `import` statements for `jshint` might not work as expected in all Node.js environments without transpilation or specific bundler configurations.
fix
When using JSHint programmatically in Node.js, stick to CommonJS `require` statements. For browser environments, include `jshint.js` via a `<script>` tag or use a bundler.
affects: *
breakingThe `shelljs` dependency was removed in JSHint v2.13.4. While this primarily affected JSHint's internal build process, any user who might have implicitly relied on `shelljs` being a transient dependency of `jshint` could experience issues if they upgrade and `shelljs` is no longer available.
fix
Ensure `shelljs` is explicitly listed as a direct dependency in your project's `package.json` if your code has a direct reliance on it, rather than depending on transitive dependencies.
affects: >=2.13.4
Errors
Common errors & fixes
'variableName' is not defined. (E008)
A variable was used without being declared, or it's a global variable not explicitly defined in JSHint's globals option.
fix
Declare the variable using `var`, `let`, or `const`. If it's a global, add it to your `.jshintrc` `globals` array (e.g., `"globals": { "jQuery": true }`) or pass it in the `globals` argument when calling `JSHINT` programmatically.
Missing semicolon. (W033)
JSHint expects a semicolon at the end of a statement, following JavaScript's Automatic Semicolon Insertion (ASI) rules but enforcing explicit semicolons.
fix
Add a semicolon (`;`) at the end of the problematic statement. You can configure JSHint to be more lenient with semicolons using the `asi` option (e.g., `"asi": true`) or disable the warning for unused expressions (`"expr": true`).
Expected an identifier and instead saw 'keyword'. (E002)
This often occurs when using newer ECMAScript keywords (e.g., `const`, `let`, `async`, `await`) without enabling the appropriate ECMAScript version in JSHint options.
fix
Update your JSHint configuration to specify the target ECMAScript version using the `esversion` option (e.g., `"esversion": 2017` for `async/await`). Ensure your JSHint version itself supports the desired ES version.
Too many errors. (E043)
JSHint stopped linting after encountering a large number of errors to prevent excessive output, often indicating a fundamental issue or misconfiguration.
fix
Address the initial errors reported by JSHint. This error is a threshold, not a specific syntax problem. Once some errors are fixed, JSHint will process more of the file. Check your `maxerr` option if you intentionally expect many errors.
Upgrade
Version history
2.13.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
jshint — npm install jshint · libregistry