azeemba / eslint-plugin-json

Lint your JSON files
MIT License
209 stars 29 forks source link

How do you get this to work? #54

Open trusktr opened 3 years ago

trusktr commented 3 years ago

I have a config file like this:

.eslintrc.js ```js module.exports = { root: true, parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, env: { browser: true, node: true, es2017: true, }, plugins: [ 'json', // doesn't seem to do anything with JSON files 'promise', // https://github.com/xjamundx/eslint-plugin-promise 'html', ], extends: [ // Uses the recommended rules from the @typescript-eslint/eslint-plugin 'plugin:@typescript-eslint/recommended', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 'prettier/@typescript-eslint', 'plugin:json/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. 'plugin:prettier/recommended', ], // add your custom rules here rules: { 'no-debugger': 'error', 'prefer-const': 'error', 'one-var': ['error', 'never'], 'no-var': 'error', 'no-return-assign': ['error', 'except-parens'], 'brace-style': ['error', '1tbs', {allowSingleLine: false}], 'quote-props': ['error', 'as-needed'], curly: ['error', 'multi-or-nest', 'consistent'], // --- PROMISE --------------------------------- // from https://github.com/xjamundx/eslint-plugin-promise 'promise/always-return': 'off', 'promise/no-return-wrap': 'error', 'promise/param-names': 'error', 'promise/catch-or-return': 'error', 'promise/no-new-statics': 'error', 'promise/no-return-in-finally': 'error', // --- TYPESCRIPT ------------------------------ 'no-undef': 0, 'no-unused-vars': 0, '@typescript-eslint/naming-convention': 'off', // — Require community JS/TS variable naming conventions. TODO, this one has lots of options. '@typescript-eslint/adjacent-overload-signatures': 'error', // — Require that member overloads be consecutive '@typescript-eslint/explicit-function-return-type': 'error', // — Require explicit return types on functions and class methods '@typescript-eslint/explicit-module-boundary-types': 'off', // — Require explicit types on all things that are exported from modules. Off because we handle this with the explicit-function-return-type rule paired with (soon) the noImplicitAny option in tsconfig. '@typescript-eslint/consistent-type-assertions': 'error', // — Enforces the use of `as` Type assertions instead of assertions. '@typescript-eslint/no-array-constructor': 'error', // — Disallow generic Array constructors '@typescript-eslint/no-explicit-any': 'off', // — Disallow usage of the any type '@typescript-eslint/no-inferrable-types': 'off', // — Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. '@typescript-eslint/no-namespace': 'off', // — Disallow the use of custom TypeScript modules and namespaces '@typescript-eslint/triple-slash-reference': 'error', // — Disallow /// comments '@typescript-eslint/no-unused-vars': 'off', // — Off beacuse TypeScript gives us these errors already. '@typescript-eslint/no-var-requires': 'off', // — Disallows the use of require statements except in import statements '@typescript-eslint/type-annotation-spacing': ['error', {}], // — Require consistent spacing around type annotations '@typescript-eslint/no-non-null-assertion': 'off', // — Prevents non-null assertiong with `!` }, settings: {}, } ```

And then I try to run

eslint package.json

and it finishes without outputting anything to console, regardless of what format I have in my package.json.


I've tried getting eslint-plugin-json to work a few times over the past couple years, over several versions of eslint, but it always seems not to do anything.

trusktr commented 3 years ago

I previously had babel-eslint parser (and an override only for .ts files) but that also didn't seem to do anything with respect to JSON files (it looked the same as above except parser: 'babel-eslint' and no typescript stuff).

trusktr commented 3 years ago

Random thought: if I have a custom eslintrc, do I perhaps need to make an item for JSON files to overrides to return some settings back to normal?

trusktr commented 3 years ago

Hmm, I don't have json in my plugins now, but I do have 'plugin:json/recommended' listed in extends, and I do see an error like

/home/trusktr/src/velodyne_sw+vella-frontend-projects/pkgs/mapper-annotated-scene/tsconfig.json
  2:17  error  Comment not allowed  json/*

Getting somewhere. I don't see red squigglies in the code while looking at JSON files (only other types of files) in VS Code.

EDIT: Oh, interesting, now that I removed json I see a bunch of errors as if it is checking it as a .js file. So it's working to some degree.

My main motivation is to get red squigglies in VS Code, but if I can't, then I think prettier is enough and eslint-plugin-json is probably not needed.

Maks-Yaremenko commented 3 years ago

faced with the same issue

BoisAuLit commented 2 years ago

Same issue here, this plugin isn't running at all

romenrg commented 1 year ago

After some attempts I got this to work today. Here are some things you might be missing:

I suspect that if we didn't have a tsconfig file (e.g. if it was a JS project), then adding something like extraFileExtensions: [".json"] to the parserOptions: in the eslint config file might work. But when there is a tsconfig file, it seems to take precedence.

Other notes: