prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.39k stars 255 forks source link

Compatibility with new eslint config spec (flat config) #231

Closed jjangga0214 closed 1 year ago

jjangga0214 commented 1 year ago

Eslint announced a new config spec. https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new

스크린샷 2022-09-09 오후 10 07 49

According to eslint's official blog, though backward compatibility was taken care of, not all shareable configs continue to work with the new config system.

Is eslint-config-prettier compatible with the new config?

Thanks.

lydell commented 1 year ago

I tried it out quickly, and in short: Yes, it works. But there are some things to do as well.

eslint.config.js:

import prettier from "eslint-config-prettier";

export default [
    "eslint:recommended",
    prettier,
];

The above successfully disables the no-mixed-spaces-and-tabs rule from eslint:recommended! 🎉

And this:

import prettier from "eslint-config-prettier";

export default [
    {
        rules: {
            semi: "error",
        }
    },
    prettier,
];

The above successfully turns off the semi rule. 🎉 Even though semi wasn’t set by another config. This wasn’t possible before.

However, the CLI helper tool does not work:

❯ npx eslint-config-prettier index.js
No ESLint configuration found in /Users/lydell/stuff/eslint.

TODO:

However, it might be too early days to do this just yet: https://github.com/eslint/eslint/issues/13481

lydell commented 1 year ago

Changing this line:

https://github.com/prettier/eslint-config-prettier/blob/a57a3bb0e5aa39f59c2523bb3b77bf7e13b7be2a/bin/cli.js#L11

-const { ESLint } = require(require.resolve("eslint", {
+const { FlatESLint: ESLint } = require(require.resolve("eslint/use-at-your-own-risk", {

… seems to make the CLI work with the new config system. However, that is still an unsupported API, and I need to figure out how to support both the old and new config systems at the same time.

I think the conclusion for now is:

theoparis commented 1 year ago

Unless I'm doing something wrong it does not seem to work anymore 😕

Oops! Something went wrong! :(

ESLint: 8.44.0

TypeError: Cannot read properties of undefined (reading 'includes')
    at /home/theo/dev/fem-kanban/node_modules/.pnpm/eslint-plugin-prettier@5.0.0-alpha.2_eslint-config-prettier@8.8.0_eslint@8.44.0_prettier@3.0.0/node_modules/eslint-plugin-prettier/worker.js:116:27
lydell commented 1 year ago

The updated CLI tool was released in v9.0.0.

The docs and tests have been updated too.