eslint
eslint requires a custom configuration file applicable to your project.
You can create it by typing npx eslint --init
in the root of your repository
eslint documentation
- Version in MegaLinter: 8.57.1
- Visit Official Web Site
- See How to configure eslint rules
- See How to disable eslint rules in files
- See How to ignore files and directories with eslint
- You can define a
.eslintignore
file to ignore files and folders
- You can define a
- See Index of problems detected by eslint
Configuration in MegaLinter
- Enable eslint by adding
TYPESCRIPT_ES
in ENABLE_LINTERS variable - Disable eslint by adding
TYPESCRIPT_ES
in DISABLE_LINTERS variable
- Enable autofixes by adding
TYPESCRIPT_ES
in APPLY_FIXES variable
Variable | Description | Default value |
---|---|---|
TYPESCRIPT_ES_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
TYPESCRIPT_ES_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
TYPESCRIPT_ES_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
TYPESCRIPT_ES_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
TYPESCRIPT_ES_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- list_of_files : Call the linter with the list of files as argument- project : Call the linter from the root of the project |
list_of_files |
TYPESCRIPT_ES_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".ts"] |
TYPESCRIPT_ES_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
TYPESCRIPT_ES_PRE_COMMANDS | List of bash commands to run before the linter | None |
TYPESCRIPT_ES_POST_COMMANDS | List of bash commands to run after the linter | None |
TYPESCRIPT_ES_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling TYPESCRIPT_ES and its pre/post commands | None |
TYPESCRIPT_ES_CONFIG_FILE | eslint configuration file nameUse LINTER_DEFAULT to let the linter find it |
.eslintrc.json |
TYPESCRIPT_ES_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
TYPESCRIPT_ES_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
TYPESCRIPT_ES_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
TYPESCRIPT_ES_CLI_EXECUTABLE | Override CLI executable | ['eslint'] |
IDE Integration
Use eslint in your favorite IDE to catch errors before MegaLinter !
MegaLinter Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 125 | |
cupcake | MegaLinter for the most commonly used languages | 85 | ||
dotnetweb | Optimized for C, C++, C# or VB based projects with JS/TS | 70 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 58 |
Behind the scenes
How are identified applicable files
- Activated only if one of these files is found:
.eslintrc.json, .eslintrc.yml, .eslintrc.yaml, .eslintrc.js, .eslintrc.cjs, package.json:eslintConfig
- File extensions:
.ts
How the linting is performed
- eslint is called once with the list of files as arguments (
list_of_files
CLI lint mode)
Example calls
eslint myfile.ts
eslint -c .eslintrc.json --no-eslintrc --no-ignore myfile.ts
eslint --fix -c .eslintrc.json --no-eslintrc --no-ignore myfile.ts
Help content
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-eslintrc Disable use of configuration from .eslintrc.*
-c, --config path::String Use this configuration, overriding .eslintrc.* config options if present
--env [String] Specify environments
--ext [String] Specify JavaScript file extensions
--global [String] Define global variables
--parser String Specify the parser to be used
--parser-options Object Specify parser options
--resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default
Specify Rules and Plugins:
--plugin [String] Specify plugins
--rule Object Specify rules
--rulesdir [path::String] Load additional rules from this directory. Deprecated: Use rules from plugins
Fix Problems:
--fix Automatically fix problems
--fix-dry-run Automatically fix problems without saving the changes to the file system
--fix-type Array Specify the types of fixes to apply (directive, problem, suggestion, layout)
Ignore Files:
--ignore-path path::String Specify path of ignore file
--no-ignore Disable use of ignore files and patterns
--ignore-pattern [String] Pattern of files to ignore (in addition to those in .eslintignore)
Use stdin:
--stdin Lint code provided on <STDIN> - default: false
--stdin-filename String Specify filename to process STDIN as
Handle Warnings:
--quiet Report errors only - default: false
--max-warnings Int Number of warnings to trigger nonzero exit code - default: -1
Output:
-o, --output-file path::String Specify file to write report to
-f, --format String Use a specific output format - default: stylish
--color, --no-color Force enabling/disabling of color
Inline configuration comments:
--no-inline-config Prevent comments from changing config or rules
--report-unused-disable-directives Adds reported errors for unused eslint-disable and eslint-enable directives
--report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and eslint-enable directives - either: off, warn, error, 0, 1, or 2
Caching:
--cache Only check changed files - default: false
--cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache
--cache-location path::String Path to the cache file or directory
--cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata
Miscellaneous:
--init Run config initialization wizard - default: false
--env-info Output execution environment information - default: false
--no-error-on-unmatched-pattern Prevent errors when pattern is unmatched
--exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false
--debug Output debugging information
-h, --help Show help
-v, --version Output the version number
--print-config path::String Print the configuration for the given file
Installation on mega-linter Docker image
- Dockerfile commands :
# Parent descriptor install
# renovate: datasource=npm depName=typescript
ARG NPM_TYPESCRIPT_VERSION=5.7.3
# Linter install
# renovate: datasource=npm depName=eslint
ARG NPM_ESLINT_VERSION=8.57.1
# renovate: datasource=npm depName=eslint-config-airbnb
ARG NPM_ESLINT_CONFIG_AIRBNB_VERSION=19.0.4
# renovate: datasource=npm depName=eslint-config-prettier
ARG NPM_ESLINT_CONFIG_PRETTIER_VERSION=10.0.1
# renovate: datasource=npm depName=eslint-config-standard
ARG NPM_ESLINT_CONFIG_STANDARD_VERSION=17.1.0
# renovate: datasource=npm depName=eslint-plugin-import
ARG NPM_ESLINT_PLUGIN_IMPORT_VERSION=2.31.0
# renovate: datasource=npm depName=eslint-plugin-jest
ARG NPM_ESLINT_PLUGIN_JEST_VERSION=28.11.0
# renovate: datasource=npm depName=eslint-plugin-n
ARG NPM_ESLINT_PLUGIN_N_VERSION=16.6.2
# renovate: datasource=npm depName=eslint-plugin-prettier
ARG NPM_ESLINT_PLUGIN_PRETTIER_VERSION=5.2.3
# renovate: datasource=npm depName=eslint-plugin-promise
ARG NPM_ESLINT_PLUGIN_PROMISE_VERSION=6.6.0
# renovate: datasource=npm depName=@babel/eslint-parser
ARG NPM_BABEL_ESLINT_PARSER_VERSION=7.26.8
# renovate: datasource=npm depName=prettier
ARG NPM_PRETTIER_VERSION=3.5.1
# renovate: datasource=npm depName=prettyjson
ARG NPM_PRETTYJSON_VERSION=1.2.5
# renovate: datasource=npm depName=@typescript-eslint/eslint-plugin
ARG NPM_TYPESCRIPT_ESLINT_ESLINT_PLUGIN_VERSION=8.24.0
# renovate: datasource=npm depName=@typescript-eslint/parser
ARG NPM_TYPESCRIPT_ESLINT_PARSER_VERSION=8.24.0
# renovate: datasource=npm depName=@microsoft/eslint-formatter-sarif
ARG NPM_MICROSOFT_ESLINT_FORMATTER_SARIF_VERSION=3.1.0
- NPM packages (node.js):
- typescript@5.7.3
- eslint@8.57.1
- eslint-config-airbnb@19.0.4
- eslint-config-prettier@10.0.1
- eslint-config-standard@17.1.0
- eslint-plugin-import@2.31.0
- eslint-plugin-jest@28.11.0
- eslint-plugin-n@16.6.2
- eslint-plugin-prettier@5.2.3
- eslint-plugin-promise@6.6.0
- @babel/eslint-parser@7.26.8
- prettier@3.5.1
- prettyjson@1.2.5
- @typescript-eslint/eslint-plugin@8.24.0
- @typescript-eslint/parser@8.24.0
- @microsoft/eslint-formatter-sarif@3.1.0