ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
181 stars 17 forks source link

Limit flat preset to certain file formats #348

Closed daniel-shuy closed 5 days ago

daniel-shuy commented 5 days ago

How can I apply a flat preset to only certain file formats (e.g. .json5)?

I tried:

import eslintPluginJsonc from 'eslint-plugin-jsonc';

export default [
    ...eslintPluginJsonc.configs['flat/recommended-with-json5'],
    {
        files: ["*.json5"],
        rules: {
          // ...
        },
    },
];

but it is applying the rules to other file formats (e.g. .js) as well

ota-meshi commented 5 days ago

Could you please create a minimal repository that reproduces the issue and share it?

daniel-shuy commented 5 days ago

Ah, I figured out the issue. Because I can't apply the eslint-plugin-jsonc flat preset to subset of files, e.g.

import eslintPluginJsonc from 'eslint-plugin-jsonc';

export default [
    {
        files: ["*.json5"],
        ...eslintPluginJsonc.configs['flat/recommended-with-json5'],
        rules: {
          // ...
        },
    },
];

it is detecting files generated by my build with eslint-disable directives (in my case, jquery-ui.js).

I solved it by configuring ESLint to use my .gitignore file.

It would be nice if the flat presets can be applied to a subset of files, but it can be worked around as far as this issue is concerned.