# Introduction
eslint-plugin-jsonc (opens new window) is ESLint plugin for JSON (opens new window), JSONC (opens new window) and JSON5 (opens new window) files.
(opens new window)
(opens new window)
(opens new window)
(opens new window)
(opens new window)
(opens new window)
(opens new window)
(opens new window)
(opens new window)
# 📛 Features
This ESLint plugin provides linting rules relate to better ways to help you avoid problems when using JSON (opens new window), JSONC (opens new window) and JSON5 (opens new window).
- You can use ESLint to lint JSON (opens new window).
- You can apply rules similar to the rules you use for JavaScript to JSON using the
"jsonc/auto"
rule provided by this plugin. - You can choose the appropriate config provided by this plugin depending on whether you are using JSON (opens new window), JSONC (opens new window) or JSON5 (opens new window).
- Supports Vue SFC (opens new window) custom blocks such as
<i18n>
.
Requirementsvue-eslint-parser
v7.3.0 and above. - Supports ESLint directives. e.g.
// eslint-disable-next-line
- You can check your code in real-time using the ESLint editor integrations.
You can check on the Online DEMO.
# ❓ Why is it ESLint plugin?
ESLint is a great linter for JavaScript.
Since JSON (opens new window) is a subset of JavaScript, the same parser and rules can be applied to JSON (opens new window).
Also, JSONC (opens new window) and JSON5 (opens new window), which are variants of JSON (opens new window), are more similar to JavaScript than JSON (opens new window). Applying a JavaScript linter to JSON (opens new window) is more rational than creating a JSON-specific linter.
# How does eslint-plugin-jsonc
work?
This plugin parses .json
with its own parser, but this parser just converts AST parsed by acorn
(It is used internally by the ESLint standard parser) into AST with another name. However, ASTs that do not exist in JSON (opens new window) and the superset of JSON syntaxes are reported as parsing errors. By converting the AST to another name, we prevent false positives from ESLint core rules.
Moreover, You can do the same linting using the extended rules of the ESLint core rules provided by this plugin.
The parser package used by this plugin is jsonc-eslint-parser (opens new window).
# ❓ How is it different from other JSON plugins?
# Plugins that do not use AST
e.g. eslint-plugin-json (opens new window)
These plugins use the processor to parse and return the results independently, without providing the ESLint engine with AST and source code text.
Plugins don't provide AST, so you can't use directive comments (e.g. /* eslint-disable */
).
Plugins don't provide source code text, so you can't use it with plugins and rules that use text (e.g. eslint-plugin-prettier (opens new window), eol-last (opens new window)).
Also, most plugins don't support JSON5.
eslint-plugin-jsonc works by providing AST and source code text to ESLint.
# Plugins that use the same AST as JavaScript
e.g. eslint-plugin-json-files (opens new window), eslint-plugin-json-es (opens new window)
These plugins use the same AST as JavaScript for linting.
Since the plugin uses the same AST as JavaScript, it may not report syntax that is not available in JSON (e.g. 1 + 1
, (42)
). Also, ESLint core rules and other plugin rules can false positives (e.g. quote-props (opens new window) rule reports quote on keys), which can complicate the your configuration.
The AST used by eslint-plugin-jsonc is similar to JavaScript AST, but with a different node name. This will prevent false positives. This means that it can be easily used in combination with other plugins.
# 📖 Usage
See User Guide.
# ✅ Rules
See Available Rules.
# 🚀 To Do More Verification
# Verify using JSON Schema
You can verify using JSON Schema by checking and installing eslint-plugin-json-schema-validator (opens new window).
# Verify the Vue I18n (opens new window) message resource files
You can verify the message files by checking and installing @intlify/eslint-plugin-vue-i18n (opens new window).
# 👫 Related Packages
- eslint-plugin-yml (opens new window) ... ESLint plugin for YAML.
- eslint-plugin-toml (opens new window) ... ESLint plugin for TOML.
- eslint-plugin-json-schema-validator (opens new window) ... ESLint plugin that validates data using JSON Schema Validator.
- jsonc-eslint-parser (opens new window) ... JSON, JSONC and JSON5 parser for use with ESLint plugins.
- yaml-eslint-parser (opens new window) ... YAML parser for use with ESLint plugins.
- toml-eslint-parser (opens new window) ... TOML parser for use with ESLint plugins.
# 🔒 License
See the LICENSE (opens new window) file for license rights and limitations (MIT).