GithubHelp home page GithubHelp logo

zeitport / eslint-plugin-json-es Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 3.0 726 KB

A ESLint plugin to lint JSON files with existing or custom rules.

License: MIT License

JavaScript 100.00%
eslint eslint-plugin json json-parser linter linting

eslint-plugin-json-es's People

Contributors

cschuller avatar dependabot[bot] avatar edg2s avatar michaelw85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eslint-plugin-json-es's Issues

You should add "parserOptions.extraFileExtensions" to your config

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

Confusing unexpected parsing error.

Problem

Given invalid JSON like

{

or

{"foo": [}}

Then the plugin returns this message:

1:1 Parsing error: Unexpected token )

Explanation

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.

Slow performance on long files

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

ESLint core rule "accessor-pairs" fails in JSON files

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.

Add an example of adding custom rules using eslint-parser-json

Give plugin a unique name

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:

  1. es-json / esjson
  2. json-as-js

indent rule miscounts indentation for comments in JSON

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]
      }
    }
  ]
}

Parsing error: Unexpected end of JSON input

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.