zeitport / eslint-plugin-json-es Goto Github PK
View Code? Open in Web Editor NEWA ESLint plugin to lint JSON files with existing or custom rules.
License: MIT License
A ESLint plugin to lint JSON files with existing or custom rules.
License: MIT License
if I give the following command in terminal
eslint ./test.json --fix
I get:
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: test.json.
The extension for the file (.json) is non-standard. You should add "parserOptions.extraFileExtensions" to your config
WHY?
thanks in advance
Is it possible to check that files are valid JSON while using this plugin?
Given invalid JSON like
{
or
{"foo": [}}
Then the plugin returns this message:
1:1 Parsing error: Unexpected token )
Internally the given JSON {
will be transformed to a statement ({)
.
The statement is not correct and can not be parsed by the espree (AST) parser and a generic parse error is thrown.
Custom rules are not called after a generic parser error.
In case you are not aware, there is a https://github.com/ota-meshi/eslint-plugin-jsonc built with correct jsonc-eslint-parser
, I think we should work together to benefit to the whole community.
cc @ota-meshi
Linting a file with ~30k lines takes about 6s with eslint, but ~280s with the eslint-plugin-json-es
parser. It doesn't appear to spend longer in any specific rule, so maybe some overhead which is causing the slow down?
eslint-plugin-json-es
parser:
> TIMING=1 time npx eslint tests/cases/en-big-oldparser/en-big-oldparser.json
Rule | Time (ms) | Relative
:--------------------|----------:|--------:
indent | 639.483 | 54.7%
max-len | 45.934 | 3.9%
key-spacing | 42.217 | 3.6%
comma-style | 39.928 | 3.4%
no-extra-parens | 34.074 | 2.9%
no-trailing-spaces | 30.201 | 2.6%
...
Command exited with non-zero status 1
279.81user 1.59system 4:35.25elapsed 102%CPU (0avgtext+0avgdata 300768maxresident)k
0inputs+0outputs (0major+82500minor)pagefaults 0swaps
Regular parser:
Rule | Time (ms) | Relative
:------------------|----------:|--------:
indent | 657.560 | 42.5%
quote-props | 258.444 | 16.7%
quotes | 98.567 | 6.4%
key-spacing | 49.780 | 3.2%
max-len | 45.074 | 2.9%
comma-style | 44.753 | 2.9%
...
Command exited with non-zero status 1
6.41user 0.33system 0:05.18elapsed 130%CPU (0avgtext+0avgdata 392144maxresident)k
0inputs+0outputs (0major+108247minor)pagefaults 0swaps
I can't see how to use the rule configurations as shared configs?
Thanks,
When rule "accessor-pairs" is active, linting a JSON file fails with
Oops! Something went wrong! :(
ESLint: 7.20.0
TypeError: Cannot read property 'type' of null
Occurred while linting package.json:1
at isPropertyDescriptor (node_modules/eslint/lib/rules/accessor-pairs.js:127:24)
at checkObjectExpression (node_modules/eslint/lib/rules/accessor-pairs.js:325:17)
at node_modules/eslint/lib/linter/safe-emitter.js:45:58
...
This rule should be disabled for JSON files in the set of recommended rules.
It would be cool to have a basic example of how to use this to create custom rules.
Refs:
Having to prefix rules and directives with a username is difficult. It would be better if this plugin just had a unique name. It could then be published on npm as well.
Suggestions:
4:1 error Expected indentation of 4 spaces but found 3 indent
.eslintrc.json
{
"root": true,
"overrides": [
// Misc overrides
{
"files": ["**/*.json"],
"plugins": [
"eslint-plugin-json-es"
],
"parser": "eslint-plugin-json-es",
"extends": [
"plugin:json-es/recommended"
],
"rules": {
"indent": ["error", 2]
}
}
]
}
After doing a super simple setup to use this as the json parser in my project, every file fails with the error Parsing error: Unexpected end of JSON input
Here is my setup
{
//...
overrides: [
{
files: ['*.json'],
parser: 'eslint-plugin-json-es'
}
],
}
and after running eslint on a simple json file
{
"test": "paragraph"
}
here is the result i get :
[...]% yarn eslint src/test.json
yarn run v1.22.18
$ /Users/[...]/node_modules/.bin/eslint src/test.json
[...]/src/test.json
1:3 error Parsing error: Unexpected end of JSON input
โ 1 problem (1 error, 0 warnings)
error Command failed with exit code 1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.