Top Related Projects
Prettier is an opinionated code formatter.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
🌟 JavaScript Style Guide, with linter & automatic code fixer
:vertical_traffic_light: An extensible linter for the TypeScript language
A mighty CSS linter that helps you avoid errors and enforce conventions.
A JavaScript checker and optimizer.
Quick Overview
ESLint is a popular, open-source JavaScript linting tool that helps developers identify and fix problems in their code. It is highly configurable, supports plugins, and can be integrated into various development environments and workflows.
Pros
- Highly customizable with a wide range of built-in rules and support for custom rules
- Extensible through plugins, allowing for additional functionality and language support
- Integrates well with popular editors, build tools, and CI/CD pipelines
- Active community and regular updates
Cons
- Configuration can be complex, especially for large projects with many rules
- Some rules may conflict with each other, requiring careful configuration
- Performance can be impacted when linting large codebases
- Learning curve for creating custom rules and plugins
Code Examples
- Basic usage with the ESLint CLI:
// Run ESLint on a file
npx eslint yourfile.js
// Run ESLint on a directory
npx eslint src/
- Configuring ESLint in a project:
// .eslintrc.js
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
rules: {
'no-unused-vars': 'warn',
'no-console': 'error',
},
};
- Using ESLint in a Node.js script:
const { ESLint } = require("eslint");
async function lintFiles() {
const eslint = new ESLint();
const results = await eslint.lintFiles(["src/**/*.js"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);
}
lintFiles().catch((error) => {
process.exitCode = 1;
console.error(error);
});
Getting Started
-
Install ESLint in your project:
npm install eslint --save-dev
-
Initialize ESLint configuration:
npx eslint --init
-
Add a lint script to your
package.json
:{ "scripts": { "lint": "eslint ." } }
-
Run ESLint:
npm run lint
Competitor Comparisons
Prettier is an opinionated code formatter.
Pros of Prettier
- Opinionated formatting with minimal configuration required
- Faster and more consistent code formatting across projects
- Supports a wider range of file types beyond JavaScript
Cons of Prettier
- Less flexibility in customizing code style rules
- Limited linting capabilities compared to ESLint
- May require additional setup for integration with other tools
Code Comparison
ESLint configuration example:
{
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"],
"indent": ["error", 2]
}
}
Prettier configuration example:
{
"semi": true,
"singleQuote": true,
"tabWidth": 2
}
Summary
ESLint is a highly configurable linting tool that focuses on identifying and fixing code quality issues, while Prettier is a code formatter that aims to enforce a consistent style across projects. ESLint provides more granular control over coding rules and can detect potential errors, whereas Prettier excels at quickly formatting code with minimal setup. While both tools can work together, Prettier is often preferred for its simplicity and speed in formatting, while ESLint remains essential for maintaining code quality and catching potential bugs.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
Pros of JSHint
- Simpler configuration and setup process
- Faster execution for small to medium-sized projects
- Lighter weight with fewer dependencies
Cons of JSHint
- Less flexible and customizable than ESLint
- Slower development cycle and fewer updates
- Limited support for modern JavaScript features and frameworks
Code Comparison
JSHint configuration:
{
"esversion": 6,
"node": true,
"unused": true
}
ESLint configuration:
{
"parserOptions": {
"ecmaVersion": 2018
},
"env": {
"node": true
},
"rules": {
"no-unused-vars": "error"
}
}
ESLint offers more granular control over rules and supports a wider range of modern JavaScript features. JSHint's configuration is simpler but less flexible.
Both tools aim to improve code quality and catch potential errors, but ESLint has become more popular due to its extensibility and active development. JSHint is still used in some projects, especially those that prioritize simplicity and quick setup.
ESLint's plugin system allows for custom rules and integration with various frameworks, while JSHint is more focused on core JavaScript linting. For larger projects or teams requiring specific coding standards, ESLint is generally the preferred choice. However, JSHint can be sufficient for smaller projects or developers who prefer a more straightforward linting solution.
🌟 JavaScript Style Guide, with linter & automatic code fixer
Pros of Standard
- Zero configuration required, works out of the box
- Enforces a consistent style across projects without debates
- Simpler setup process, especially for beginners
Cons of Standard
- Less flexibility in customizing rules
- Fewer rule options compared to ESLint's extensive set
- May not align with specific team or project preferences
Code Comparison
Standard:
function example () {
const x = 1
if (x) console.log('test')
}
ESLint (with default config):
function example() {
const x = 1;
if (x) {
console.log('test');
}
}
Summary
Standard offers a simpler, opinionated approach to linting with zero configuration, making it ideal for quick setups and consistent style across projects. ESLint provides more flexibility and customization options, allowing teams to tailor rules to their specific needs. The choice between the two depends on project requirements, team preferences, and the desired level of control over linting rules.
:vertical_traffic_light: An extensible linter for the TypeScript language
Pros of TSLint
- Specifically designed for TypeScript, offering better integration with TS features
- Includes built-in rules for TypeScript-specific syntax and patterns
- Provides more detailed type-aware linting capabilities
Cons of TSLint
- Smaller community and ecosystem compared to ESLint
- Less frequent updates and maintenance (now deprecated in favor of ESLint)
- Limited support for JavaScript files
Code Comparison
TSLint configuration:
{
"rules": {
"no-any": true,
"no-unsafe-any": true,
"strict-boolean-expressions": true
}
}
ESLint configuration:
{
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/strict-boolean-expressions": "error"
}
}
Additional Notes
TSLint has been deprecated, and the TypeScript team now recommends using ESLint with TypeScript-specific plugins. ESLint offers broader language support, a larger ecosystem, and more frequent updates. However, TSLint may still be found in older TypeScript projects or those with specific requirements.
A mighty CSS linter that helps you avoid errors and enforce conventions.
Pros of stylelint
- Specialized for CSS and preprocessor languages (SCSS, Less, etc.)
- Extensive built-in rules for CSS-specific issues and best practices
- Supports custom parsers for non-standard syntax (e.g., CSS-in-JS)
Cons of stylelint
- Limited to styling languages, not as versatile as ESLint
- Smaller ecosystem and fewer third-party plugins compared to ESLint
- Less frequent updates and potentially slower bug fixes
Code Comparison
ESLint (JavaScript):
module.exports = {
extends: 'eslint:recommended',
rules: {
'no-unused-vars': 'error',
'semi': ['error', 'always']
}
};
stylelint (CSS):
{
"extends": "stylelint-config-standard",
"rules": {
"color-hex-case": "lower",
"selector-class-pattern": "^[a-z][a-zA-Z0-9]+$"
}
}
Both ESLint and stylelint are popular linting tools, but they serve different purposes. ESLint is a versatile JavaScript linter that can also handle TypeScript and JSX, while stylelint focuses specifically on CSS and its preprocessors. ESLint has a larger community and more frequent updates, making it more suitable for complex JavaScript projects. stylelint, on the other hand, excels in providing detailed and specialized rules for CSS, making it an excellent choice for projects with complex styling requirements.
A JavaScript checker and optimizer.
Pros of Closure Compiler
- Advanced optimization capabilities, including dead code elimination and minification
- Type checking and inference for enhanced code quality
- Supports transpilation from modern JavaScript to older versions
Cons of Closure Compiler
- Steeper learning curve and more complex setup compared to ESLint
- Less focus on code style and formatting rules
- Slower processing time, especially for large projects
Code Comparison
ESLint configuration example:
{
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"]
}
}
Closure Compiler usage example:
java -jar closure-compiler.jar --js_output_file=output.min.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
input1.js input2.js
ESLint is primarily a linting tool focused on identifying and fixing code quality issues and enforcing coding standards. It's lightweight, easy to set up, and highly customizable with a vast ecosystem of plugins.
Closure Compiler, on the other hand, is a more comprehensive tool that not only checks for code quality but also optimizes and compiles JavaScript. It offers advanced features like type checking and code optimization, making it suitable for large-scale projects that require performance optimization.
While ESLint excels in maintaining code quality and consistency, Closure Compiler shines in optimizing code for production environments. The choice between the two depends on project requirements, with many developers using both tools in their workflow for different purposes.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ESLint
Website | Configure ESLint | Rules | Contribute to ESLint | Report Bugs | Code of Conduct | Twitter | Discord | Mastodon
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
- ESLint uses Espree for JavaScript parsing.
- ESLint uses an AST to evaluate patterns in code.
- ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
Table of Contents
- Installation and Usage
- Configuration
- Version Support
- Code of Conduct
- Filing Issues
- Frequently Asked Questions
- Releases
- Security Policy
- Semantic Versioning Policy
- Stylistic Rule Updates
- License
- Team
- Sponsors
- Technology Sponsors
Installation and Usage
Prerequisites: Node.js (^18.18.0
, ^20.9.0
, or >=21.1.0
) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
You can install and configure ESLint using this command:
npm init @eslint/config@latest
After that, you can run ESLint on any file or directory like this:
npx eslint yourfile.js
Configuration
You can configure rules in your eslint.config.js
files as in this example:
export default [
{
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
rules: {
"prefer-const": "warn",
"no-constant-binary-expression": "error"
}
}
];
The names "prefer-const"
and "no-constant-binary-expression"
are the names of rules in ESLint. The first value is the error level of the rule and can be one of these values:
"off"
or0
- turn the rule off"warn"
or1
- turn the rule on as a warning (doesn't affect exit code)"error"
or2
- turn the rule on as an error (exit code will be 1)
The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the configuration docs).
Version Support
The ESLint team provides ongoing support for the current version and six months of limited support for the previous version. Limited support includes critical bug fixes, security issues, and compatibility issues only.
ESLint offers commercial support for both current and previous versions through our partners, Tidelift and HeroDevs.
See Version Support for more details.
Code of Conduct
ESLint adheres to the OpenJS Foundation Code of Conduct.
Filing Issues
Before filing an issue, please be sure to read the guidelines for what you're reporting:
Frequently Asked Questions
Does ESLint support JSX?
Yes, ESLint natively supports parsing JSX syntax (this must be enabled in configuration). Please note that supporting JSX syntax is not the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using eslint-plugin-react if you are using React and want React semantics.
Does Prettier replace ESLint?
No, ESLint and Prettier have different jobs: ESLint is a linter (looking for problematic patterns) and Prettier is a code formatter. Using both tools is common, refer to Prettier's documentation to learn how to configure them to work well with each other.
What ECMAScript versions does ESLint support?
ESLint has full support for ECMAScript 3, 5, and every year from 2015 up until the most recent stage 4 specification (the default). You can set your desired ECMAScript syntax and other settings (like global variables) through configuration.
What about experimental features?
ESLint's parser only officially supports the latest final ECMAScript standard. We will make changes to core rules in order to avoid crashes on stage 3 ECMAScript syntax proposals (as long as they are implemented using the correct experimental ESTree syntax). We may make changes to core rules to better work with language extensions (such as JSX, Flow, and TypeScript) on a case-by-case basis.
In other cases (including if rules need to warn on more or fewer cases due to new syntax, rather than just not crashing), we recommend you use other parsers and/or rule plugins. If you are using Babel, you can use @babel/eslint-parser and @babel/eslint-plugin to use any option available in Babel.
Once a language feature has been adopted into the ECMAScript standard (stage 4 according to the TC39 process), we will accept issues and pull requests related to the new feature, subject to our contributing guidelines. Until then, please use the appropriate parser and plugin(s) for your experimental feature.
Which Node.js versions does ESLint support?
ESLint updates the supported Node.js versions with each major release of ESLint. At that time, ESLint's supported Node.js versions are updated to be:
- The most recent maintenance release of Node.js
- The lowest minor version of the Node.js LTS release that includes the features the ESLint team wants to use.
- The Node.js Current release
ESLint is also expected to work with Node.js versions released after the Node.js Current release.
Refer to the Quick Start Guide for the officially supported Node.js versions for a given ESLint release.
Where to ask for help?
Open a discussion or stop by our Discord server.
Why doesn't ESLint lock dependency versions?
Lock files like package-lock.json
are helpful for deployed applications. They ensure that dependencies are consistent between environments and across deployments.
Packages like eslint
that get published to the npm registry do not include lock files. npm install eslint
as a user will respect version constraints in ESLint's package.json
. ESLint and its dependencies will be included in the user's lock file if one exists, but ESLint's own lock file would not be used.
We intentionally don't lock dependency versions so that we have the latest compatible dependency versions in development and CI that our users get when installing ESLint in a project.
The Twilio blog has a deeper dive to learn more.
Releases
We have scheduled releases every two weeks on Friday or Saturday. You can follow a release issue for updates about the scheduling of any particular release.
Security Policy
ESLint takes security seriously. We work hard to ensure that ESLint is safe for everyone and that security issues are addressed quickly and responsibly. Read the full security policy.
Semantic Versioning Policy
ESLint follows semantic versioning. However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
- Patch release (intended to not break your lint build)
- A bug fix in a rule that results in ESLint reporting fewer linting errors.
- A bug fix to the CLI or core (including formatters).
- Improvements to documentation.
- Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
- Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
- Minor release (might break your lint build)
- A bug fix in a rule that results in ESLint reporting more linting errors.
- A new rule is created.
- A new option to an existing rule that does not result in ESLint reporting more linting errors by default.
- A new addition to an existing rule to support a newly-added language feature (within the last 12 months) that will result in ESLint reporting more linting errors by default.
- An existing rule is deprecated.
- A new CLI capability is created.
- New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
- A new formatter is created.
eslint:recommended
is updated and will result in strictly fewer linting errors (e.g., rule removals).
- Major release (likely to break your lint build)
eslint:recommended
is updated and may result in new linting errors (e.g., rule additions, most rule option updates).- A new option to an existing rule that results in ESLint reporting more linting errors by default.
- An existing formatter is removed.
- Part of the public API is removed or changed in an incompatible way. The public API includes:
- Rule schemas
- Configuration schema
- Command-line options
- Node.js API
- Rule, formatter, parser, plugin APIs
According to our policy, any minor update may report more linting errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (~
) in package.json
e.g. "eslint": "~3.1.0"
to guarantee the results of your builds.
Stylistic Rule Updates
Stylistic rules are frozen according to our policy on how we evaluate new rules and rule changes. This means:
- Bug fixes: We will still fix bugs in stylistic rules.
- New ECMAScript features: We will also make sure stylistic rules are compatible with new ECMAScript features.
- New options: We will not add any new options to stylistic rules unless an option is the only way to fix a bug or support a newly-added ECMAScript feature.
License
Team
These folks keep the project moving and are resources for help.
Technical Steering Committee (TSC)
The people who manage releases, review feature requests, and meet regularly to ensure ESLint is properly maintained.
Nicholas C. Zakas |
Francesco Trotta |
Milos Djermanovic |
Reviewers
The people who review and implement new features.
å¯ç¶ |
Nitin Kumar |
Committers
The people who review and fix bugs and help triage issues.
Josh Goldberg ⨠|
Tanuj Kanti |
Website Team
Team members who focus specifically on eslint.org
Amaresh S M |
Strek |
Percy Ma |
Sponsors
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. Become a Sponsor to get your logo on our READMEs and website.
Platinum Sponsors
Gold Sponsors
Silver Sponsors
Bronze Sponsors
Technology Sponsors
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.Top Related Projects
Prettier is an opinionated code formatter.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
🌟 JavaScript Style Guide, with linter & automatic code fixer
:vertical_traffic_light: An extensible linter for the TypeScript language
A mighty CSS linter that helps you avoid errors and enforce conventions.
A JavaScript checker and optimizer.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot