{"id":11166,"library":"jshint","title":"JSHint - JavaScript Static Analysis Tool","description":"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.","status":"maintenance","version":"2.13.6","language":"javascript","source_language":"en","source_url":"https://github.com/jshint/jshint","tags":["javascript"],"install":[{"cmd":"npm install jshint","lang":"bash","label":"npm"},{"cmd":"yarn add jshint","lang":"bash","label":"yarn"},{"cmd":"pnpm add jshint","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { JSHINT } from 'jshint';","symbol":"JSHINT","correct":"const { JSHINT } = require('jshint');"},{"note":"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.","wrong":"require('jshint').cli.run()","symbol":"cli","correct":"npx jshint your-file.js"},{"note":"After running JSHINT on code, detailed analysis data (e.g., global variables, functions) can be accessed via `JSHINT.data()`.","symbol":"JSHINT.data()","correct":"const result = JSHINT(code, options, globals); const data = JSHINT.data();"}],"quickstart":{"code":"const { JSHINT } = require('jshint');\n\nconst javascriptCode = `\nfunction greet(name) {\n    console.log('Hello, ' + name)\n    // Missing semicolon here intentionally\n}\n\nconst myName = 'World';\ngreet(myName);\n\n// A variable not defined in this scope\nundefinedVar = 1;\n`;\n\n// JSHint options: enforce strict mode, allow console\nconst options = {\n    strict: true,\n    browser: false, // For Node.js environment\n    node: true,     // For Node.js globals like console\n    undef: true     // Warn if variables are used without being declared\n};\n\n// Lint the code\nJSHINT(javascriptCode, options);\n\n// Log any errors found\nif (JSHINT.errors.length > 0) {\n    console.log('JSHint found issues:');\n    JSHINT.errors.forEach(error => {\n        if (error) {\n            console.error(`  Line ${error.line}, Col ${error.character}: ${error.reason} (${error.code})`);\n        }\n    });\n} else {\n    console.log('No JSHint issues found.');\n}\n","lang":"javascript","description":"Demonstrates programmatic usage of JSHint to lint a JavaScript string, configured for a Node.js environment, and prints any detected errors or warnings."},"warnings":[{"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.","message":"JSHint'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.","severity":"gotcha","affected_versions":">=2.13.6"},{"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.","message":"JSHint does not natively support TypeScript or JSX. Attempting to lint such files will likely result in numerous parsing errors.","severity":"gotcha","affected_versions":"*"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"*"},{"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.","message":"The `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.","severity":"breaking","affected_versions":">=2.13.4"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"A variable was used without being declared, or it's a global variable not explicitly defined in JSHint's globals option.","error":"'variableName' is not defined. (E008)"},{"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`).","cause":"JSHint expects a semicolon at the end of a statement, following JavaScript's Automatic Semicolon Insertion (ASI) rules but enforcing explicit semicolons.","error":"Missing semicolon. (W033)"},{"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.","cause":"This often occurs when using newer ECMAScript keywords (e.g., `const`, `let`, `async`, `await`) without enabling the appropriate ECMAScript version in JSHint options.","error":"Expected an identifier and instead saw 'keyword'. (E002)"},{"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.","cause":"JSHint stopped linting after encountering a large number of errors to prevent excessive output, often indicating a fundamental issue or misconfiguration.","error":"Too many errors. (E043)"}],"ecosystem":"npm"}