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

feat: support flat config #330

Merged
merged 9 commits into from
May 22, 2024
2 changes: 2 additions & 0 deletions lib/config/flat-recommended.js
Copy link
Contributor Author

@kazupon kazupon Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for flat config, ecmaFeatures option is not added. Because the parser options should be specified by the user. especially, jsx: true should be supported by plugins like eslint-plugin-react, as mentioned in the eslint documentation.
https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options

BTW, ecmaFeatures for flat config built-in on the plugin side will cause eslint to output an error as shown below, so we cannot set them built-in:

Error: Key "languageOptions": Unexpected key "ecmaFeatures" found.
    at ObjectSchema.validate (/path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/object-schema/src/object-schema.js:287:23)
    at /path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/object-schema/src/object-schema.js:239:18
    at Array.reduce (<anonymous>)
    at ObjectSchema.merge (/path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/object-schema/src/object-schema.js:237:24)
    at /path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/config-array/api.js:935:42
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (/path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/config-array/api.js:934:39)
    at FlatConfigArray.isFileIgnored (/path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/@humanwhocodes/config-array/api.js:962:15)
    at /path/to/oss/tailwind/eslint-plugin-tailwindcss/tests/integrations/flat-config/node_modules/eslint/lib/eslint/eslint-helpers.js:504:38
    at Array.forEach (<anonymous>)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren’t ecmaFeatures supported in languageOptions.parserOptions?

  {
+   languageOptions: {
+     parserOptions: {
+       ecmaFeatures: {
+         jsx: true,
+       },
+     },
+   },
    plugins: {
      get tailwindcss() {
        return require('../index');
      },
    },
  },

ref: https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
oh, I've apparently mis-read the config docs, and I found that it is possible with flat config.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const rules = require('./rules');

module.exports = [
{
name: 'tailwindcss:base',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about name, see the here

We can check flat config with eslint config inspector
image

plugins: {
get tailwindcss() {
return require('../index');
Expand All @@ -23,6 +24,7 @@ module.exports = [
},
},
{
name: 'tailwindcss:rules',
rules,
},
];