Skip to content

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

eslint-plugin-react - GitHub

Configuration in Mega-Linter

Variable Description Default value
TSX_ESLINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
TSX_ESLINT_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
TSX_ESLINT_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
TSX_ESLINT_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
{linter.cli_lint_mode}
TSX_ESLINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".tsx"]
TSX_ESLINT_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
TSX_ESLINT_PRE_COMMANDS List of bash commands to run before the linter None
TSX_ESLINT_POST_COMMANDS List of bash commands to run after the linter None
TSX_ESLINT_CONFIG_FILE eslint configuration file name
Use LINTER_DEFAULT to let the linter find it
.eslintrc.json
TSX_ESLINT_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter default rules
TSX_ESLINT_DISABLE_ERRORS Run linter but consider errors as warnings false
TSX_ESLINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use eslint in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Atom linter-eslint Visit Web Site
Brackets brackets-eslint Visit Web Site
Eclipse Tern-Linter-ESLint Visit Web Site
Emacs flycheck Visit Web Site
IDEA ESLint Plugin
Sublime Text SublimeLinter-eslint Visit Web Site
vim ale Visit Web Site
vim Syntastic Visit Web Site
Visual Studio Code vscode-eslint Install in VsCode

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 93 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 48 Docker Image Size (tag) Docker Pulls

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
  • File extensions: .tsx

How the linting is performed

  • eslint is called once with the list of files as arguments

Example calls

eslint myfile.tsx
eslint -c .eslintrc.json --no-eslintrc --no-ignore myfile.tsx
eslint --fix -c .eslintrc.json --no-eslintrc --no-ignore myfile.tsx

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

Specifying rules and plugins:
  --rulesdir [path::String]       Use additional rules from this directory
  --plugin [String]               Specify plugins
  --rule Object                   Specify rules

Fixing 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 (problem, suggestion, layout)

Ignoring 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)

Using stdin:
  --stdin                         Lint code provided on <STDIN> - default: false
  --stdin-filename String         Specify filename to process STDIN as

Handling 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 directives

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

Example success log

Results of eslint linter (version 7.15.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/tsx_eslint/
-----------------------------------------------

[SUCCESS] .automation/test/tsx/tsx_good_1.tsx
    Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .

Example error log

Results of eslint linter (version 7.15.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/tsx_eslint/
-----------------------------------------------

[ERROR] .automation/test/tsx/tsx_bad_1.tsx

    .automation/test/tsx/tsx_bad_1.tsx
      7:10  error  Parsing error: '=' expected

    ✖ 1 problem (1 error, 0 warnings)