ESLint
ESLint is a popular linting tool for JavaScript, TypeScript, and LWC. It provides numerous static-analysis rules that help developers write quality code.
Code Analyzer v5 currently supports only ESLint v8.x, and not v9.x.
Run this command to view detailed information about all the ESLint rules that are bundled with Code Analyzer:
For details about the bundled rules, see:
- ESLint rules for JavaScript
- TypeScript-ESLint rules for TypeScript
- ESLint-LWC rules for JavaScript Lightning Web Components
For information on how to modify the settings of these bundled ESLint rules, such as their severity or tags, see Customize Your Configuration.
ESLint itself, outside of the Code Analyzer context, is highly configurable. For example, you can disable rules, change whether an existing rule is a warning or an error, add custom rules, and more. You typically use a configuration file to change the configuration. ESLint provides many options for the name of the configuration file, but for simplicity, this document assumes it's called .eslint.json
.
By default, Code Analyzer doesn't use your ESLint config file because it can conflict with the base configuration of the bundled rules. If you want to apply your ESLint config file, then either directly specify it with the eslint_config_file
option or set the auto_discover_eslint_config
option to true
in your Code Analyzer configuration file. This example shows how to configure the file using an absolute path; you can also specify its location relative to the config_root
top-level option:
Alternatively, you can specify that Code Analyzer dynamically find the ESLint configuration file:
If Code Analyzer finds an ESLint config file, it automatically attempts to merge it with base configurations associated with the built-in rules. Let's look at a few examples to see how this works.
- You update your
.eslint.json
configuration file and change an existing ESLint rule to be an error rather than a warning. Code Analyzer honors this change and reflects the new severity; you can see this change by runningsf code-analyzer rules --rule-selector eslint:RuleName
. As with all Code Analyzer rules, you can then override this severity by updating thecode-analyzer.yml
file. - You add a custom ESLint rule, Code Analyzer automatically adds it to the list of ESLint rules that you can view and run. And you can then modify the settings of this custom rule, such as its severity or tags, just like you can modify all the other rules that Code Analyzer knows about.
It's possible that your custom configuration file conflicts with the Code Analyzer base configuration files, resulting in an error. If a conflict occurs, you can either update your ESLint configuration file to make it compatible with the base configurations or disable the base configuration that is causing the conflict. For example, set disable_javascript_base_config
to true
to disable the base ESLint rules for JavaScript.
Field | Type | Description |
---|---|---|
disable_engine | boolean | Whether to turn off the 'eslint' engine so that it is not included when running Code Analyzer commands. Default value is false . |
eslint_config_file | string | Your project's main ESLint configuration file. May be an absolute path or a path relative to the config_root. If null and auto_discover_eslint_config is true, then Code Analyzer will attempt to discover/apply it automatically. Currently only legacy ESLInt config files are supported. See https://eslint.org/docs/v8.x/use/configure/configuration-files to learn more. Default value is null . |
eslint_ignore_file | string | Your project's ".eslintignore" file. May be an absolute path or a path relative to the config_root. If null and auto_discover_eslint_config is true, then Code Analyzer will attempt to discover/apply it automatically. See https://eslint.org/docs/v8.x/use/configure/ignore#the-eslintignore-file to learn more. Default value is null . |
auto_discover_eslint_config | boolean | Whether to have Code Analyzer automatically discover/apply any ESLint configuration and ignore files from your workspace. Default value is false . |
disable_javascript_base_config | boolean | Whether to turn off the default base configuration that supplies the standard ESLint rules for javascript files. Default value is false . |
disable_lwc_base_config | boolean | Whether to turn off the default base configuration that supplies the LWC rules for javascript files. Default value is false . |
disable_typescript_base_config | boolean | Whether to turn off the default base configuration that supplies the standard rules for typescript files. Default value is false . |
javascript_file_extensions | array | Extensions of the javascript files in your workspace that will be associated with javascript and LWC rules. Default value is [".js",".cjs",".mjs"] . |
typescript_file_extensions | array | Extensions of the typescript files in your workspace that will be associated with typescript rules. Default value is [".ts"] . |