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 jshintVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage of JSHint to lint a JavaScript string, configured for a Node.js environment, and prints any detected errors or warnings.
Consider migrating to ESLint for projects requiring modern JavaScript features, plugin ecosystems, or TypeScript support. ESLint offers broader community support and more frequent updates.
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.
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.
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.
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.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`).
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.
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.
No dependency data recorded yet.