prettier / prettier-eslint

Code :arrow_right: prettier :arrow_right: eslint --fix :arrow_right: Formatted Code :sparkles:
http://npm.im/prettier-eslint
MIT License
4k stars 172 forks source link

Error: `reportUnusedDisableDirectives` must be any of "error", "warn", "off", and null #802

Closed qyurila closed 1 year ago

qyurila commented 2 years ago

Versions:

Have you followed the debugging tips?

Yes

Relevant code or config

.eslintrc

{
    "reportUnusedDisableDirectives": true
}

What I did:

I set reportUnusedDisableDirectives option to true and ran prettier-eslint via prettier-eslint-cli.

What happened:

prettier-eslint [ERROR]: There was trouble creating the ESLint CLIEngine.
prettier-eslint-cli [ERROR]: There was an error formatting "C:\Dev\Playground\debug-eslint\test.js":
    Error: Invalid Options:
    - 'reportUnusedDisableDirectives' must be any of "error", "warn", "off", and null.
        at processOptions (C:\Dev\Playground\debug-eslint\node_modules\.pnpm\eslint@8.25.0\node_modules\eslint\lib\eslint\eslint.js:282:15)
        at new ESLint (C:\Dev\Playground\debug-eslint\node_modules\.pnpm\eslint@8.25.0\node_modules\eslint\lib\eslint\eslint.js:429:34)
        at getESLint (C:\Dev\Playground\debug-eslint\node_modules\.pnpm\prettier-eslint@15.0.1\node_modules\prettier-eslint\dist\utils.js:386:12)
        at eslintFix (C:\Dev\Playground\debug-eslint\node_modules\.pnpm\prettier-eslint@15.0.1\node_modules\prettier-eslint\dist\index.js:176:41)
        at format (C:\Dev\Playground\debug-eslint\node_modules\.pnpm\prettier-eslint@15.0.1\node_modules\prettier-eslint\dist\index.js:113:10)
        at async C:\Dev\Playground\debug-eslint\node_modules\.pnpm\prettier-eslint-cli@7.1.0_prettier-eslint@15.0.1\node_modules\prettier-eslint-cli\dist\format-files.js:255:26
failure formatting 1 file with prettier-eslint

Reproduction repository:

https://github.com/qyurila/reprod-prettier-eslint

Problem description:

The property reportUnusedDisableDirectives should be boolean. What must be "error", "warn", "off", or null is one of API options which has the identical name.

If reportUnusedDisableDirectives is set to "error", null or something, not only ESLint throws an error but also prettier-eslint does not fix any ESLint rule triggered.

This problem prevents the use of any ESLint config package that contains reportUnusedDisableDirectives (e.g. eslint-config-xo), because no matter what type of value is overwritten to reportUnusedDisableDirectives there are still be a problem that makes it unusable. It's urgent to me because I cannot use vs-code-prettier-eslint for my project until the main repo gets fixed!


Suggested solution:

Separate ESLintOptions.overrideConfig from other ESLintOptions properties

Actually, I made a PR about this issue a while ago (#798), but I came out with a more reasonable solution and I thought there should be a discussion about the implementation so I'm creating this issue.

696 made some ESLint config options that changed in ESLint v8 to be manually moved inside of overrideConfig to "lessen the upgrade overhead". I don't know if there was reportUnusedDisableDirectives option at that time, but anyway, the patch requires a change now because of this option which has an overlapping name. It seems there is no desirable solution that follows the current method because that will eventually make one of the options not configurable.

Given that, I think it would be good solution that adding new eslintOptions option to format.option and move ESLintOptions to it except ESLintOptions.overrideConfig. That's because eslintConfig was named and documented as it accepts ESLint configs, but no other options (e.g. fix, useEslintrc). So creating another format.options for them makes more sense.

Also, it's notable that the proper documentation would be followed, which is actually good because there are kinds of ESLintOptions supports already despite no clear mention of it in docs.

Another (and I originally PRed - #798) solution would be creating a new property apiOptions for format.options. It requires a bit fewer changes than the above solution, but I don't think it's clearly better. You can see how this implementation would look like if you want.

What do you think about it?

github-actions[bot] commented 1 year ago

Stale issue

Nonemoticoner commented 1 year ago

I've just faced the same problem. This is still an issue. Should be reopened!