Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This plugin breaks other plugins that lint JSON #40

Open
EvgenyOrekhov opened this issue Dec 4, 2019 · 6 comments
Open

This plugin breaks other plugins that lint JSON #40

EvgenyOrekhov opened this issue Dec 4, 2019 · 6 comments

Comments

@EvgenyOrekhov
Copy link
Contributor

eslint-plugin-json stops working (stops giving any warnings about *.json files) when I add json-files to my .eslintrc:

{
  "extends": ["plugin:json/recommended"],
  "plugins": ["json-files"]
}

If I remove "plugins": ["json-files"] from the above config, eslint-plugin-json starts working again.

@MichaelHettmer
Copy link

Try to explicitly add eslint-plugin-json to the plugins array. Did not test this, but in my understanding your plugins array with only "json-files" in it overwrites the plugins section of the default eslint-plugin-json config so it is not included and therefore never started.

{
  "extends": ["plugin:json/recommended"],
  "plugins": ["json", "json-files"]
}

@EvgenyOrekhov
Copy link
Contributor Author

Just tried it. It doesn't help.

@barakyosi
Copy link

Any update on this issue?
I think this line breaks it:
https://github.com/kellyselden/eslint-plugin-json-files/blob/master/lib/processors/json.js#L25

Wonder if we can allow configuring it from outside, or add a better check there.

My current solution is to use patch-package to change this file 😕

@jerone
Copy link

jerone commented Aug 19, 2022

I fixed this by using ESLint overrides:

{
  "root": true,
  "overrides": [
    /*
     * JSON files.
     */
    {
      "files": ["*.json"],
      "extends": [
        "plugin:json/recommended-with-comments"
      ]
    },

    /*
     * `package.json` file.
     * This needs it's own configuration, because it doesn't work together with `plugin:json`.
     * See https://github.com/kellyselden/eslint-plugin-json-files/issues/40
     */
    {
      "files": ["package.json"],
      "plugins": ["json-files"],
      "extends": [ ],
      "rules": {
        "json-files/rule-name": "error"
      }
    }
  ]
}

@a-c-m
Copy link

a-c-m commented Aug 23, 2023

I am also hitting this. Using override trick didn't work for me, as I want to lint package.json specifically with the other module.

@barakyosi can you share what about /lib/processors/json.js#L25 that you are changing to fix it? and or submit a PR to fix it?

@steveszc
Copy link

steveszc commented Mar 12, 2024

I think this is happening because this plugin adds a (deprecated) file extension-based processor for all .json files, and the processor's postprocess method filters out any message where the ruleId is not prefixed with json-files/, so any other custom rules from other plugins will have a different ruleId prefix and those messages will be filtered out.

I can't find any way around this (other than patch-package), since there doesn't seem to be a way to override a file extension based processor (at least that I can find). I think the only way to fix this may be an internal refactor of this plugin to use a different approach for preventing it's rules from running on non-json files (which is the intent of the postprocessor), or to migrate away from the deprecated file-extension-based processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants