### Initiate Config Inspector (bun) Source: https://eslint.org/docs/latest/use/configure/debug Use this command to start the ESLint config inspector, which helps determine if specific configuration objects in your configuration file match a given filename. It installs and starts the '@eslint/config-inspector' package. ```bash bunx eslint --inspect-config ``` -------------------------------- ### Initiate Config Inspector (npm) Source: https://eslint.org/docs/latest/use/configure/debug Use this command to start the ESLint config inspector, which helps determine if specific configuration objects in your configuration file match a given filename. It installs and starts the '@eslint/config-inspector' package. ```bash npx eslint --inspect-config ``` -------------------------------- ### Install an npm-installed formatter Source: https://eslint.org/docs/latest/use/command-line-interface Install a formatter package from npm to use it with ESLint. This example shows installing the `eslint-formatter-pretty` package. ```bash npm install eslint-formatter-pretty ``` ```bash yarn add eslint-formatter-pretty ``` ```bash pnpm add eslint-formatter-pretty ``` ```bash bun add eslint-formatter-pretty ``` -------------------------------- ### Install Dependencies with bun Source: https://eslint.org/docs/latest/contribute/development-environment After cloning the repository, install all necessary development dependencies using bun. ```bash cd eslint bun add ``` -------------------------------- ### Initiate Config Inspector (pnpm) Source: https://eslint.org/docs/latest/use/configure/debug Use this command to start the ESLint config inspector, which helps determine if specific configuration objects in your configuration file match a given filename. It installs and starts the '@eslint/config-inspector' package. ```bash pnpm dlx eslint --inspect-config ``` -------------------------------- ### Configuration example Source: https://eslint.org/docs/latest/rules/template-tag-spacing Example of how to configure the 'template-tag-spacing' rule in your ESLint configuration file. ```json { "template-tag-spacing": ["error", "never"] } ``` -------------------------------- ### Configuration Example Source: https://eslint.org/docs/latest/rules/capitalized-comments This example shows how to configure the rule with options to ignore specific patterns and inline comments. ```json { "capitalized-comments": [ "error", "always", { "ignorePattern": "pragma|ignored", "ignoreInlineComments": true } ] } ``` -------------------------------- ### Install Dependencies with pnpm Source: https://eslint.org/docs/latest/contribute/development-environment After cloning the repository, install all necessary development dependencies using pnpm. ```bash cd eslint pnpm add ``` -------------------------------- ### Initiate Config Inspector (yarn) Source: https://eslint.org/docs/latest/use/configure/debug Use this command to start the ESLint config inspector, which helps determine if specific configuration objects in your configuration file match a given filename. It installs and starts the '@eslint/config-inspector' package. ```bash yarn dlx eslint --inspect-config ``` -------------------------------- ### Example Indentation Styles Source: https://eslint.org/docs/latest/rules/indent-legacy Illustrates common indentation scenarios for nested blocks and statements, aligning with various style guides. ```javascript function hello(indentSize, type) { if (indentSize === 4 && type !== 'tab') { console.log('Each next indentation will increase on 4 spaces'); } } 1 2 3 4 5 ``` -------------------------------- ### Install Dependencies with npm Source: https://eslint.org/docs/latest/contribute/development-environment After cloning the repository, install all necessary development dependencies using npm. ```bash cd eslint npm install ``` -------------------------------- ### JSCS airbnb preset example Source: https://eslint.org/docs/latest/use/migrating-from-jscs Example of a JSCS configuration file using the 'airbnb' preset. ```json { "preset": "airbnb" } ``` -------------------------------- ### Install ESLint Configuration with Bun Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use this command to install the Airbnb base configuration for ESLint when using Bun. ```bash bun add --dev eslint-config-airbnb-base 1 ``` -------------------------------- ### Install Dependencies with yarn Source: https://eslint.org/docs/latest/contribute/development-environment After cloning the repository, install all necessary development dependencies using yarn. ```bash cd eslint yarn add ``` -------------------------------- ### ESLint config file example Source: https://eslint.org/docs/latest/use/migrate-to-9.0.0 Example of an ESLint configuration file using flat config syntax. ```javascript // eslint.config.js export default [ { rules: { curly: ["error", "multi"], } }, ]; ``` -------------------------------- ### Install ESLint with bun Source: https://eslint.org/docs/latest/integrate/integration-tutorial Installs the ESLint package as a project dependency using bun. ```bash bun add eslint 1 ``` -------------------------------- ### Install ESLint Configuration with pnpm Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use this command to install the Airbnb base configuration for ESLint when using pnpm. ```bash pnpm add --save-dev eslint-config-airbnb-base 1 ``` -------------------------------- ### Install ESLint with bun Source: https://eslint.org/docs/latest/use/getting-started Installs the latest versions of ESLint and its JavaScript configuration package using bun. ```bash bun add --dev eslint@latest @eslint/js@latest ``` -------------------------------- ### Install ESLint Configuration with Yarn Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use this command to install the Airbnb base configuration for ESLint when using Yarn. ```bash yarn add --dev eslint-config-airbnb-base 1 ``` -------------------------------- ### Install ESLint with Yarn Source: https://eslint.org/docs/latest/component-library/code-tabs Use this command to install ESLint as a development dependency using Yarn. ```bash yarn install 1 ``` -------------------------------- ### Install ESLinteslintrc with Bun Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the @eslint/eslintrc package as a development dependency using Bun to enable compatability. ```bash bun add --dev @eslint/eslintrc ``` -------------------------------- ### Set up custom rule project Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Commands to create a new directory, initialize an npm project, and create the custom rule file. ```bash mkdir eslint-custom-rule-example # create directory cd eslint-custom-rule-example # enter the directory npm init -y # init new npm project touch enforce-foo-bar.js # create file enforce-foo-bar.js 1 2 3 4 ``` -------------------------------- ### Install ESLint with npm Source: https://eslint.org/docs/latest/component-library/code-tabs Use this command to install ESLint as a development dependency using npm. ```bash npm install --save-dev 1 ``` -------------------------------- ### Install ESLint Plugin with bun Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Install your published ESLint plugin as a development dependency using bun. ```bash # Add your package name here bun add --dev eslint-plugin-example ``` -------------------------------- ### Hello World Example Source: https://eslint.org/docs/latest/extend/code-path-analysis A simple console log statement. ```javascript console.log("Hello world"); ``` -------------------------------- ### Install ESLint with npm Source: https://eslint.org/docs/latest/use/getting-started Installs the latest versions of ESLint and its JavaScript configuration package using npm. ```bash npm install --save-dev eslint@latest @eslint/js@latest ``` -------------------------------- ### Run Configuration Initialization Wizard Source: https://eslint.org/docs/latest/use/command-line-interface Start the interactive wizard to help set up an ESLint configuration file. By default, this is disabled. ```bash --init ``` -------------------------------- ### Show Help Information Source: https://eslint.org/docs/latest/use/command-line-interface Display the help message, listing all available command-line options. ```bash -h, --help ``` -------------------------------- ### Initialize bun Project Source: https://eslint.org/docs/latest/integrate/integration-tutorial Initializes a new Node.js project with a package.json file using bun. ```bash bun init -y 1 ``` -------------------------------- ### Get ESLint Version Source: https://eslint.org/docs/latest/integrate/nodejs-api Access the static `version` property to retrieve the currently installed version of ESLint as a string. ```javascript const version = ESLint.version; ``` -------------------------------- ### Initialize npm Project Source: https://eslint.org/docs/latest/integrate/integration-tutorial Initializes a new Node.js project with a package.json file using npm. ```bash npm init -y 1 ``` -------------------------------- ### Install ESLint as Dev Dependency (bun) Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Install the `eslint` package as a development dependency using bun. This is required for running tests. ```bash bun add --dev eslint ``` -------------------------------- ### Disallow Unicode BOM ('always' - incorrect) Source: https://eslint.org/docs/latest/rules/unicode-bom This example shows incorrect code when the 'always' option is used, as the file does not start with a BOM. ```javascript /*eslint unicode-bom: ["error", "always"]*/ let abc; 1 2 3 ``` -------------------------------- ### Basic Linting Example Source: https://eslint.org/docs/latest/integrate/nodejs-api Demonstrates how to create an ESLint instance, lint files, load a formatter, and output the results. ```APIDOC ## Basic Linting Example ### Description This example shows the fundamental usage of the ESLint Node.js API to lint files. ### Method ```javascript const { ESLint } = require("eslint"); (async function main() { // 1. Create an instance. const eslint = new ESLint(); // 2. Lint files. const results = await eslint.lintFiles(["lib/**/*.js"]); // 3. Format the results. const formatter = await eslint.loadFormatter("stylish"); const resultText = formatter.format(results); // 4. Output it. console.log(resultText); })().catch(error => { process.exitCode = 1; console.error(error); }); ``` ``` -------------------------------- ### Correct import with allowImportNamePattern Source: https://eslint.org/docs/latest/rules/no-restricted-imports This example demonstrates a correct import when `allowImportNamePattern` is configured to allow imports starting with 'is', and 'isEmpty' is imported. ```javascript /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["utils/*"], allowImportNamePattern: '^is' }]}]*/ import { isEmpty } from 'utils/collection-utils'; ``` -------------------------------- ### Initial examples of function spacing Source: https://eslint.org/docs/latest/rules/space-before-function-parentheses These examples illustrate variations in spacing before function parentheses in named and anonymous functions. ```javascript function withoutSpace(x) { // ... } function withSpace (x) { // ... } var anonymousWithoutSpace = function() {}; var anonymousWithSpace = function () {}; ``` -------------------------------- ### Incorrect import with allowImportNamePattern Source: https://eslint.org/docs/latest/rules/no-restricted-imports This example shows an incorrect import when `allowImportNamePattern` is configured to only allow imports starting with 'has', but 'isEmpty' is imported. ```javascript /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["utils/*"], allowImportNamePattern: '^has' }]}]*/ import { isEmpty } from 'utils/collection-utils'; ``` -------------------------------- ### Initialize ESLint Configuration with bun Source: https://eslint.org/docs/latest/use/getting-started Use this command to install and configure ESLint for your project using bun. Ensure you have a package.json file. ```bash bun create @eslint/config@latest 1 ``` -------------------------------- ### Run All ESLint Unit Tests Source: https://eslint.org/docs/latest/contribute/tests Execute all unit tests in the `tests` directory. This command is used after initial setup with `npm install`. ```bash npm test ``` -------------------------------- ### Correct code with 'initializations' option Source: https://eslint.org/docs/latest/rules/one-var-declaration-per-line Examples of correct code when using the default 'initializations' option. ```javascript /*eslint one-var-declaration-per-line: ["error", "initializations"]*/ var a, b; let c, d; let e, f = 0; 1 2 3 4 5 6 7 8 9 ``` -------------------------------- ### Require Unicode BOM ('never' - incorrect) Source: https://eslint.org/docs/latest/rules/unicode-bom This example shows incorrect code when the 'never' option is used, as the file incorrectly starts with a BOM. ```javascript // U+FEFF at the beginning /*eslint unicode-bom: ["error", "never"]*/ let abc; 1 2 3 4 5 ``` -------------------------------- ### Complete ESLint Integration Example Source: https://eslint.org/docs/latest/integrate/integration-tutorial A comprehensive example demonstrating ESLint integration, including instance creation, linting, fixing, and result output. ```javascript const { ESLint } = require("eslint"); // Create an instance of ESLint with the configuration passed to the function function createESLintInstance(overrideConfig) { return new ESLint({ overrideConfigFile: true, overrideConfig, fix: true, }); } // Lint the specified files and return the results async function lintAndFix(eslint, filePaths) { const results = await eslint.lintFiles(filePaths); // Apply automatic fixes and output fixed code await ESLint.outputFixes(results); return results; } // Log results to console if there are any problems function outputLintingResults(results) { // Identify the number of problems found const problems = results.reduce( (acc, result) => acc + result.errorCount + result.warningCount, 0, ); if (problems > 0) { console.log("Linting errors found!"); console.log(results); } else { console.log("No linting errors found."); } return results; } // Put previous functions all together async function lintFiles(filePaths) { // The ESLint configuration. Alternatively, you could load the configuration // from an eslint.config.js file or just use the default config. const overrideConfig = { languageOptions: { ecmaVersion: 2018, sourceType: "commonjs", }, rules: { "no-console": "error", "no-unused-vars": "warn", }, }; const eslint = createESLintInstance(overrideConfig); const results = await lintAndFix(eslint, filePaths); return outputLintingResults(results); } // Export integration module.exports = { lintFiles }; ``` -------------------------------- ### Correct variable sorting Source: https://eslint.org/docs/latest/rules/sort-vars Variables declared in the same block should be sorted alphabetically. This example shows correctly sorted variables, including those starting with underscores. ```javascript /*eslint sort-vars: "error"*/ let a, b, c, d; let _a = 10; let _b = 20; let E, e; let G, f, h; ``` -------------------------------- ### Correct code examples for newline-before-return Source: https://eslint.org/docs/latest/rules/newline-before-return Provides examples of code that adheres to the rule, with proper empty lines before return statements. ```javascript /*eslint newline-before-return: "error"*/ function foo1() { return; } function foo2() { return; } function foo3(bar) { if (!bar) return; } function foo4(bar) { if (!bar) { return }; } function foo5(bar) { if (!bar) { return; } } function foo6(bar) { if (!bar) { return; } return bar; } function foo7(bar) { if (!bar) { return; } } function foo8() { // comment return; } ``` -------------------------------- ### Initialize ESLint Configuration with npm Source: https://eslint.org/docs/latest/use/getting-started Use this command to install and configure ESLint for your project using npm. Ensure you have a package.json file. ```bash npm init @eslint/config@latest 1 ``` -------------------------------- ### Incorrect import with importNamePattern (single pattern) Source: https://eslint.org/docs/latest/rules/no-restricted-imports This example shows an incorrect import when `importNamePattern` is set to '^is', restricting imports that do not start with 'is'. ```javascript /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["utils/*"], importNamePattern: '^is', message: "Use 'is*' functions from lodash instead." }]}]*/ import { isEmpty } from 'utils/collection-utils'; ``` -------------------------------- ### Using Migrated Flat Config in User Project Source: https://eslint.org/docs/latest/extend/plugin-migration-flat-config Example of how a user would import and use a plugin that has been migrated to the flat config format. ```javascript import { defineConfig } from "eslint/config"; import example from "eslint-plugin-example"; export default defineConfig([ // use recommended config and provide your own overrides { files: ["**/*.js", "**/*.cjs", "**/*.mjs"], plugins: { example, }, extends: ["example/recommended"], rules: { "example/rule1": "warn", }, }, ]); ``` -------------------------------- ### Allow non-warning comments (default) Source: https://eslint.org/docs/latest/rules/no-warning-comments This example demonstrates comments that are permitted by the default rule settings, as they do not contain the predefined warning terms at the start. ```javascript /*eslint no-warning-comments: "error"*/ function callback(err, results) { if (err) { console.error(err); return; } // NOT READY FOR PRIME TIME // but too bad, it is not a predefined warning term } ``` -------------------------------- ### Disallow warning comments (default) Source: https://eslint.org/docs/latest/rules/no-warning-comments This example shows comments that violate the default rule settings, which flag 'TODO' and 'FIXME' at the start of comments. ```javascript /*eslint no-warning-comments: "error"*/ /* FIXME */ function callback(err, results) { if (err) { console.error(err); return; } // TODO } ``` -------------------------------- ### Correct code with ignored decoration characters Source: https://eslint.org/docs/latest/rules/no-warning-comments This example shows comments that are considered correct when specific decoration characters are configured to be ignored at the start of comments. ```javascript /*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/ //!TODO preceded by non-decoration character /** *!TODO preceded by non-decoration character in a block comment */ ``` -------------------------------- ### Correct code examples for space-return-throw-case Source: https://eslint.org/docs/latest/rules/space-return-throw-case These examples demonstrate code that adheres to the `space-return-throw-case` rule, with proper spacing after `throw`, `return`, and `case`. ```javascript /*eslint space-return-throw-case: "error"*/ throw {a: 0}; function f(){ return -a; } switch(a){ case 'a': break; } 1 2 3 4 5 6 7 ``` -------------------------------- ### Correct code with 'always' padding Source: https://eslint.org/docs/latest/rules/padded-blocks This example demonstrates correct code when the 'always' option is used, showing blocks with required empty lines at the start and end. ```javascript /*eslint padded-blocks: ["error", "always"]*/ if (a) { b(); } if (a) { b(); } if (a) { // comment b(); } class C { static { a(); } } ``` -------------------------------- ### Initialize ESLint configuration with npm Source: https://eslint.org/docs/latest/use/command-line-interface Use this command with npm to start the ESLint configuration initialization wizard, which helps create an eslint.config.js file. ```bash npx eslint --init 1 ``` -------------------------------- ### Correct code examples for 'smart' option Source: https://eslint.org/docs/latest/rules/eqeqeq These examples show correct usage when the `eqeqeq` rule is configured with the `smart` option, demonstrating allowed exceptions for literals, typeof, and null comparisons. ```javascript /*eslint eqeqeq: ["error", "smart"]*/ typeof foo == 'undefined' 'hello' != 'world' 0 == 0 true == true foo == null ``` -------------------------------- ### Ignore multiple decoration characters Source: https://eslint.org/docs/latest/rules/no-warning-comments This example demonstrates ignoring multiple types of decoration characters (like '/' and '*') at the start of comments when searching for warning terms. ```javascript /*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/ ////// TODO decorative slashes and whitespace are ignored ////// //***** todo decorative asterisks are also ignored *****// /** * TODO new lines are also ignored in block comments. */ ``` -------------------------------- ### Disallow /=foo/ regex Source: https://eslint.org/docs/latest/rules/no-div-regex This example shows incorrect usage where a regular expression starts with '/=', which can be mistaken for a division assignment operator. This pattern is flagged by the rule. ```javascript function bar() { return /=foo/; } ``` -------------------------------- ### Using capIsNewExceptionPattern with ^Foo prefix Source: https://eslint.org/docs/latest/rules/new-cap This example illustrates using `capIsNewExceptionPattern` to allow calls that start with `Foo`, such as `Foo(42)`, `Foobar(42)`, and `Foo.Bar(42)`. ```javascript /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Foo" }]*/ const x = Foo(42); const y = Foobar(42); const z = Foo.Bar(42); 1 2 3 4 5 6 7 ``` -------------------------------- ### Initialize ESLint Configuration with pnpm Source: https://eslint.org/docs/latest/use/getting-started Use this command to install and configure ESLint for your project using pnpm. Ensure you have a package.json file. ```bash pnpm create @eslint/config@latest 1 ``` -------------------------------- ### Using capIsNewExceptionPattern with person.* Source: https://eslint.org/docs/latest/rules/new-cap This example demonstrates how to use the `capIsNewExceptionPattern` option to allow calls to `person.Acquaintance()` and `person.Friend()` even though they don't start with an uppercase letter. ```javascript /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^person\\.." }]*/ const friend = person.Acquaintance(); const bestFriend = person.Friend(); 1 2 3 4 ``` -------------------------------- ### Correct usage of `require` and instantiation Source: https://eslint.org/docs/latest/rules/no-new-require This code demonstrates the recommended pattern: first, require the module, then create a new instance of the exported constructor. ```javascript /*eslint no-new-require: "error"*/ var AppHeader = require('app-header'); var appHeader = new AppHeader(); ``` -------------------------------- ### Ignore Default Patterns Source: https://eslint.org/docs/latest/rules/lines-around-comment By default, comments starting with specific keywords like 'eslint', 'jshint', etc., are ignored. This example shows a comment that is ignored due to these defaults. ```javascript /*eslint lines-around-comment: ["error"]*/ foo(); /* jshint mentioned in this comment */ bar(); ``` -------------------------------- ### Alphabetical list maintenance Source: https://eslint.org/docs/latest/rules/sort-vars The rule maintains an alphabetical list starting from the first variable, excluding problems. This example shows how multiple problems can be reported in a single declaration block. ```javascript /*eslint sort-vars: "error"*/ let c, d, a, b; ``` -------------------------------- ### Initialize ESLint configuration with bun Source: https://eslint.org/docs/latest/use/command-line-interface Use this command with bun to start the ESLint configuration initialization wizard, which helps create an eslint.config.js file. ```bash bunx eslint --init 1 ``` -------------------------------- ### Initialize pnpm Project Source: https://eslint.org/docs/latest/integrate/integration-tutorial Initializes a new Node.js project with a package.json file using pnpm. ```bash pnpm init -y 1 ``` -------------------------------- ### Ignoring Arguments by Pattern - Correct Code Source: https://eslint.org/docs/latest/rules/no-unused-vars This example demonstrates the `argsIgnorePattern` option, which allows ignoring arguments that match a specified regular expression. Here, arguments starting with an underscore are ignored. ```javascript /*eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]*/ function foo(x, _y) { return x + 1; } foo(); 1 2 3 4 5 6 ``` -------------------------------- ### Ignore Specific Comment Patterns Source: https://eslint.org/docs/latest/rules/line-comment-position Allows configuration of a custom regular expression to ignore specific line comments, in addition to default patterns. This example ignores comments starting with 'pragma'. ```javascript /*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/ 1 + 1; // pragma valid comment ``` ```javascript /*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/ 1 + 1; // invalid comment ``` -------------------------------- ### Install Polyjuice via bun Source: https://eslint.org/docs/latest/use/migrating-from-jscs Install the Polyjuice utility globally using bun for converting JSCS configuration files to ESLint format. ```bash bun add --global polyjuice ``` -------------------------------- ### Initialize ESLint config via npm Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use the ESLint configuration wizard to create a new ESLint configuration file from scratch using npm. ```bash npm init @eslint/config@latest ``` -------------------------------- ### Install ESLint with pnpm Source: https://eslint.org/docs/latest/integrate/integration-tutorial Installs the ESLint package as a project dependency using pnpm. ```bash pnpm add eslint 1 ``` -------------------------------- ### Examples of Function Calls Source: https://eslint.org/docs/latest/rules/func-call-spacing Demonstrates equivalent function calls with and without spacing before the parentheses. ```javascript alert('Hello'); alert ('Hello'); console.log(42); console.log (42); new Date(); new Date (); ``` -------------------------------- ### Install ESLint with yarn Source: https://eslint.org/docs/latest/integrate/integration-tutorial Installs the ESLint package as a project dependency using yarn. ```bash yarn add eslint 1 ``` -------------------------------- ### Install ESLint with npm Source: https://eslint.org/docs/latest/integrate/integration-tutorial Installs the ESLint package as a project dependency using npm. ```bash npm install eslint 1 ``` -------------------------------- ### Initialize yarn Project Source: https://eslint.org/docs/latest/integrate/integration-tutorial Initializes a new Node.js project with a package.json file using yarn. ```bash yarn init -y 1 ``` -------------------------------- ### ESLint configuration comment example Source: https://eslint.org/docs/latest/use/migrate-to-9.0.0 Example of an ESLint configuration comment in a JavaScript file. ```javascript // my-file.js /* eslint curly: "warn" */ ``` -------------------------------- ### Incorrect Code Examples (Default) Source: https://eslint.org/docs/latest/rules/no-useless-rename Examples of code that violates the 'no-useless-rename' rule by default. ```javascript /*eslint no-useless-rename: "error"*/ import { foo1 as foo1 } from "bar"; import { "foo2" as foo2 } from "bar"; export { foo1 as foo1 }; export { foo2 as "foo2" }; export { foo3 as foo3 } from "bar"; export { "foo4" as "foo4" } from "bar"; let { foo3: foo3 } = bar; let { 'foo4': foo4 } = bar; function foo({ bar: bar }) {} ({ foo: foo }) => {} ``` -------------------------------- ### Initialize ESLint Configuration with yarn Source: https://eslint.org/docs/latest/use/getting-started Use this command to install and configure ESLint for your project using yarn. Ensure you have a package.json file. ```bash yarn create @eslint/config 1 ``` -------------------------------- ### Correct Code Examples for Default Configuration Source: https://eslint.org/docs/latest/rules/semi-spacing Demonstrates code that adheres to the default semi-spacing rule (no space before, space after semicolon). ```javascript /*eslint semi-spacing: "error"*/ var foo; var foo; var bar; throw new Error("error"); while (a) { break; } for (i = 0; i < 10; i++) {} for (;;) {} if (true) {;} ;foo(); 1 2 3 4 5 6 7 8 9 10 ``` -------------------------------- ### Create ESLint Integration File Source: https://eslint.org/docs/latest/integrate/integration-tutorial Creates a new JavaScript file named 'example-eslint-integration.js' in the project root. ```bash touch example-eslint-integration.js 1 ``` -------------------------------- ### Configure max complexity using shorthand syntax Source: https://eslint.org/docs/latest/rules/complexity This example demonstrates the shorthand syntax for setting the maximum complexity threshold in the ESLint configuration. ```json "complexity": ["error", 2] ``` -------------------------------- ### Initialize ESLint config via pnpm Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use the ESLint configuration wizard to create a new ESLint configuration file from scratch using pnpm. ```bash pnpm create @eslint/config@latest ``` -------------------------------- ### Correct Code Examples (Default) Source: https://eslint.org/docs/latest/rules/no-useless-rename Examples of code that is considered correct by the 'no-useless-rename' rule by default. ```javascript /*eslint no-useless-rename: "error"*/ import * as foo1 from "foo"; import { foo2 } from "bar"; import { foo as bar1 } from "baz"; import { "foo" as bar2 } from "baz"; export { foo }; export { foo as bar1 }; export { foo as "bar2" }; export { foo as bar3 } from "foo"; export { "foo" as "bar4" } from "foo"; let { foo } = bar; let { foo: bar } = baz; let { [qux]: qux } = bar; function foo3({ bar }) {} function foo4({ bar: baz }) {} ({ foo }) => {} ({ foo: bar }) => {} ``` -------------------------------- ### Correct Usage with Configuration File Source: https://eslint.org/docs/latest/rules/no-process-env This snippet shows the recommended approach by importing configuration from a separate file, thus avoiding direct `process.env` usage. This promotes better maintainability and avoids global dependencies. ```javascript /*eslint no-process-env: "error"*/ var config = require("./config"); if(config.env === "development") { //... } ``` -------------------------------- ### Example Prompts for ESLint MCP Server Source: https://eslint.org/docs/latest/use/mcp These prompts demonstrate how to instruct an LLM to use the configured ESLint MCP server for linting and fixing code. ```prompt Lint the current file and explain any issues found ``` ```prompt Lint and fix #file:index.js ``` -------------------------------- ### Example of unused label Source: https://eslint.org/docs/latest/rules/no-unused-labels This example demonstrates an unused label `OUTER_LOOP` which is likely a refactoring error. ```javascript OUTER_LOOP: for (const student of students) { if (checkScores(student.scores)) { continue; } doSomething(student); } ``` -------------------------------- ### Install @eslint/js for predefined configs (npm) Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the `@eslint/js` package using npm to access predefined ESLint configurations like `eslint:recommended` and `eslint:all` in flat config. ```bash npm install --save-dev @eslint/js ``` -------------------------------- ### Install ESLinteslintrc with pnpm Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the @eslint/eslintrc package as a development dependency using pnpm to enable compatability. ```bash pnpm add --save-dev @eslint/eslintrc ``` -------------------------------- ### Correct Code Examples for Space Before, No Space After Source: https://eslint.org/docs/latest/rules/semi-spacing Shows code that correctly follows the configuration enforcing space before and disallowing space after semicolons. ```javascript /*eslint semi-spacing: ["error", { "before": true, "after": false }]*/ var foo ; var foo ;var bar ; throw new Error("error") ; while (a) {break ;} for (i = 0 ;i < 10 ;i++) {} 1 2 3 4 5 6 7 ``` -------------------------------- ### Install ESLinteslintrc with yarn Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the @eslint/eslintrc package as a development dependency using yarn to enable compatability. ```bash yarn add --dev @eslint/eslintrc ``` -------------------------------- ### Install ESLinteslintrc with npm Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the @eslint/eslintrc package as a development dependency using npm to enable compatability. ```bash npm install --save-dev @eslint/eslintrc ``` -------------------------------- ### Initialize ESLint Configuration Source: https://eslint.org/docs/latest/use/migrating-from-jscs Use `eslint --init` and select 'Inspect your JavaScript file(s)' to create a configuration based on your existing code, similar to JSCS's `--auto-configure`. ```bash eslint --init ? How would you like to configure ESLint? (Use arrow keys) > Answer questions about your style Use a popular style guide Inspect your JavaScript file(s) 1 2 3 4 5 ``` -------------------------------- ### Create ESLint Configuration File Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Initialize an ESLint configuration file using `eslint.config.js`. This file will define project-wide ESLint settings. ```bash touch eslint.config.js ``` -------------------------------- ### Configure no-shadow Rule Options Source: https://eslint.org/docs/latest/rules/no-shadow This example shows how to configure the no-shadow rule with various options, including `builtinGlobals`, `hoist`, `allow`, and `ignoreOnInitialization`. ```json { "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [], "ignoreOnInitialization": false }] } ``` -------------------------------- ### Install ESLint with pnpm Source: https://eslint.org/docs/latest/use/getting-started Installs the latest versions of ESLint and its JavaScript configuration package using pnpm. ```bash pnpm add --save-dev eslint@latest @eslint/js@latest ``` -------------------------------- ### Install @eslint/js for predefined configs (pnpm) Source: https://eslint.org/docs/latest/use/configure/migration-guide Install the `@eslint/js` package using pnpm to access predefined ESLint configurations like `eslint:recommended` and `eslint:all` in flat config. ```bash pnpm add --save-dev @eslint/js ``` -------------------------------- ### Install ESLint with yarn Source: https://eslint.org/docs/latest/use/getting-started Installs the latest versions of ESLint and its JavaScript configuration package using yarn. ```bash yarn add --dev eslint@latest @eslint/js@latest ``` -------------------------------- ### Top-level require() example Source: https://eslint.org/docs/latest/rules/global-require Demonstrates a standard `require()` call at the top level of a module. ```javascript var fs = require("fs"); ``` -------------------------------- ### Run ESLint using bunx Source: https://eslint.org/docs/latest/use/command-line-interface Use bunx to execute ESLint from the command line. This is an alternative to npx for Bun users. ```bash bunx eslint [options] [file|dir|glob]* ``` -------------------------------- ### Flat Config with Default Glob Pattern Source: https://eslint.org/docs/latest/use/configure/migration-guide An example of a flat config file using the default glob pattern. It includes the recommended config and custom rule overrides. ```javascript // eslint.config.js import { defineConfig } from "eslint/config"; import js from "@eslint/js"; export default defineConfig([ js.configs.recommended, // Recommended config applied to all files // Override the recommended config { rules: { indent: ["error", 2], "no-unused-vars": "warn" } // ...other configuration } ]); ``` -------------------------------- ### Install ESLint Plugin with pnpm Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Install your published ESLint plugin as a development dependency using pnpm. ```bash # Add your package name here pnpm add --save-dev eslint-plugin-example ``` -------------------------------- ### Install ESLint Plugin with yarn Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Install your published ESLint plugin as a development dependency using yarn. ```bash # Add your package name here yarn add --dev eslint-plugin-example ``` -------------------------------- ### Install ESLint Plugin with npm Source: https://eslint.org/docs/latest/extend/custom-rule-tutorial Install your published ESLint plugin as a development dependency using npm. ```bash # Add your package name here npm install --save-dev eslint-plugin-example ``` -------------------------------- ### Install ESLint Yeoman Generator with bun Source: https://eslint.org/docs/latest/contribute/development-environment Install the ESLint-specific Yeoman generator globally using bun. ```bash bun add --global generator-eslint ```