eslint-plugin-jsonc
eslint-plugin-jsonc uses eslint to lint json, jsonc and json5 (extended JSON with comments & more).
- To override default configuration, create a
.eslintrc-json.json
custom configuration file applicable to your project - If you have
.json
files with comments in your project, you may disablejsonlint
to avoid false positive errors, by adding the following content in your.mega-linter.yml
configuration file
DISABLE_LINTERS:
- JSON_JSONLINT
- If you have your own local
.eslintrc.json
(or.yaml
or.js
equivalent) config in your project, you must- add
JSON_ESLINT_PLUGIN_JSONC_FILE_NAME: .eslintrc.json
(or.yaml
or.js
equivalent) in your.mega-linter.yml
config file -
add
overrides
property in itSee code
{ "overrides": [ { "files": [".json"], "extends": [ "plugin:jsonc/recommended-with-json" ], "parser": "jsonc-eslint-parser", "parserOptions": { "jsonSyntax": "JSON" } }, { "files": [".jsonc"], "extends": [ "plugin:jsonc/recommended-with-jsonc" ], "parser": "jsonc-eslint-parser", "parserOptions": { "jsonSyntax": "JSONC" } }, { "files": ["*.json5"], "extends": [ "plugin:jsonc/recommended-with-json5" ], "parser": "jsonc-eslint-parser", "parserOptions": { "jsonSyntax": "JSON5" } } ] }
- add
eslint-plugin-jsonc documentation
- Version in MegaLinter: 2.10.0
- Visit Official Web Site
- See How to configure eslint-plugin-jsonc rules
- If custom
.eslintrc-json.json
config file isn't found, .eslintrc-json.json will be used
- If custom
- See How to disable eslint-plugin-jsonc rules in files
- See How to ignore files and directories with eslint-plugin-jsonc
- You can define a
.eslintignore
file to ignore files and folders
- You can define a
- See Index of problems detected by eslint-plugin-jsonc
Configuration in MegaLinter
- Enable eslint-plugin-jsonc by adding
JSON_ESLINT_PLUGIN_JSONC
in ENABLE_LINTERS variable - Disable eslint-plugin-jsonc by adding
JSON_ESLINT_PLUGIN_JSONC
in DISABLE_LINTERS variable
- Enable autofixes by adding
JSON_ESLINT_PLUGIN_JSONC
in APPLY_FIXES variable
Variable | Description | Default value |
---|---|---|
JSON_ESLINT_PLUGIN_JSONC_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
JSON_ESLINT_PLUGIN_JSONC_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
JSON_ESLINT_PLUGIN_JSONC_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
JSON_ESLINT_PLUGIN_JSONC_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
JSON_ESLINT_PLUGIN_JSONC_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 |
JSON_ESLINT_PLUGIN_JSONC_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".json", ".json5", ".jsonc"] |
JSON_ESLINT_PLUGIN_JSONC_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 |
JSON_ESLINT_PLUGIN_JSONC_PRE_COMMANDS | List of bash commands to run before the linter | None |
JSON_ESLINT_PLUGIN_JSONC_POST_COMMANDS | List of bash commands to run after the linter | None |
JSON_ESLINT_PLUGIN_JSONC_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling JSON_ESLINT_PLUGIN_JSONC and its pre/post commands | None |
JSON_ESLINT_PLUGIN_JSONC_CONFIG_FILE | eslint-plugin-jsonc configuration file nameUse LINTER_DEFAULT to let the linter find it |
.eslintrc-json.json |
JSON_ESLINT_PLUGIN_JSONC_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
JSON_ESLINT_PLUGIN_JSONC_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
JSON_ESLINT_PLUGIN_JSONC_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
JSON_ESLINT_PLUGIN_JSONC_CLI_EXECUTABLE | Override CLI executable | ['eslint'] |
IDE Integration
Use eslint-plugin-jsonc in your favorite IDE to catch errors before MegaLinter !
IDE | Extension Name | Install | |
---|---|---|---|
Visual Studio Code | vscode-eslint | Visit Web Site |
MegaLinter Flavours
This linter is available in the following flavours
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
all | Default MegaLinter Flavor | 117 | ||
ci_light | Optimized for CI items (Dockerfile, Jenkinsfile, JSON/YAML schemas,XML | 22 | ||
cupcake | MegaLinter for the most commonly used languages | 85 | ||
documentation | MegaLinter for documentation projects | 51 | ||
dotnet | Optimized for C, C++, C# or VB based projects | 63 | ||
dotnetweb | Optimized for C, C++, C# or VB based projects with JS/TS | 72 | ||
go | Optimized for GO based projects | 53 | ||
java | Optimized for JAVA based projects | 55 | ||
javascript | Optimized for JAVASCRIPT or TYPESCRIPT based projects | 60 | ||
php | Optimized for PHP based projects | 54 | ||
python | Optimized for PYTHON based projects | 62 | ||
ruby | Optimized for RUBY based projects | 51 | ||
rust | Optimized for RUST based projects | 51 | ||
salesforce | Optimized for Salesforce based projects | 54 | ||
swift | Optimized for SWIFT based projects | 51 | ||
terraform | Optimized for TERRAFORM based projects | 55 |
Behind the scenes
How are identified applicable files
- File extensions:
.json
,.json5
,.jsonc
How the linting is performed
- eslint-plugin-jsonc is called once with the list of files as arguments (
list_of_files
CLI lint mode)
Example calls
eslint myfile.json
eslint -c .eslintrc-json.json --no-eslintrc --no-ignore myfile.json
eslint -c .eslintrc-json.json --no-eslintrc --no-ignore myfile.json5
eslint -c .eslintrc-json.json --no-eslintrc --no-ignore myfile.jsonc
eslint --fix -c .eslintrc-json.json --no-eslintrc --no-ignore myfile.json
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
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
- NPM packages (node.js):