eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.39k stars 4.4k forks source link

This method cannot be used with flat config. Add your entries directly into the config array. #18386

Closed egucciar closed 3 weeks ago

egucciar commented 3 weeks ago

Environment

Node version: 20.11.1 yarn version: 1.122.22 ESLint version: 9.1.1 Operating System: MacOS

What parser are you using?

@typescript-eslint/parser

What did you do?

Configuration ``` import globals from "globals"; import typescriptParser from "@typescript-eslint/parser"; import pluginReact from "eslint-plugin-react"; import pluginReactHooks from "eslint-plugin-react-hooks"; import pluginCypress from "eslint-plugin-cypress"; import pluginJsxA11y from "eslint-plugin-jsx-a11y"; import pluginChaiFriendly from "eslint-plugin-chai-friendly"; import pluginImport from "eslint-plugin-import"; import pluginTypescriptEslint from "@typescript-eslint/eslint-plugin"; import pluginCssModules from "eslint-plugin-css-modules"; import pluginAutofix from "eslint-plugin-disable-autofix"; import pluginJsdoc from "eslint-plugin-jsdoc"; import pluginUnicorn from "eslint-plugin-unicorn"; import pluginPreferArrow from "eslint-plugin-prefer-arrow"; import pluginNoOnlyTests from "eslint-plugin-no-only-tests"; import pluginNoRelativeImportPaths from "eslint-plugin-no-relative-import-paths"; import pluginSentenceCase from "eslint-plugin-sentence-case"; import pluginSimpleImportSort from "eslint-plugin-simple-import-sort"; import pluginUnusedImports from "eslint-plugin-unused-imports"; import pluginEarlyReturn from "@regru/eslint-plugin-prefer-early-return"; export default [ { languageOptions: { ecmaVersion: 2022, sourceType: "module", globals: { ...globals.browser, ...globals.node, }, parser: typescriptParser, parserOptions: { project: "./tsconfig.json", sourceType: "module", }, }, ...pluginReact.configs.recommended, ...pluginReactHooks.configs.recommended, ...pluginCypress.configs.recommended, ...pluginJsxA11y.configs.recommended, ...pluginChaiFriendly.configs.recommended, ...pluginImport.configs.recommended, ...pluginImport.configs.typescript, ...pluginTypescriptEslint.configs.recommended, ...pluginCssModules.configs.recommended, ignorePatterns: ["**/__mocks__/**/*.js"], plugins: { "@typescript-eslint": pluginTypescriptEslint, "chai-friendly": pluginChaiFriendly, "css-modules": pluginCssModules, cypress: pluginCypress, "disable-autofix": pluginAutofix, "eslint-plugin-import": pluginImport, "eslint-plugin-jsdoc": pluginJsdoc, "eslint-plugin-unicorn": pluginUnicorn, "eslint-plugin-react": pluginReact, "eslint-plugin-prefer-arrow": pluginPreferArrow, "no-only-tests": pluginNoOnlyTests, "no-relative-import-paths": pluginNoRelativeImportPaths, "sentence-case": pluginSentenceCase, "simple-import-sort": pluginSimpleImportSort, "unused-imports": pluginUnusedImports, "@regru/prefer-early-return": pluginEarlyReturn, }, settings: { react: { version: "detect", }, "import/resolver": { typescript: {}, // this loads /tsconfig.json to eslint }, }, rules: { "css-modules/no-unused-class": [2, {camelCaseOnly: true}], "css-modules/no-undef-class": [2, {camelCaseOnly: true}], "@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/array-type": [ "error", { default: "array-simple", }, ], "@typescript-eslint/await-thenable": "error", "@typescript-eslint/ban-types": [ "warn", { types: { Object: { message: "Avoid using the `Object` type. Did you mean `object`?", }, Function: { message: "Avoid using the `Function` type. Prefer a specific function type, like `() => void`.", }, Boolean: { message: "Avoid using the `Boolean` type. Did you mean `boolean`?", }, Number: { message: "Avoid using the `Number` type. Did you mean `number`?", }, String: { message: "Avoid using the `String` type. Did you mean `string`?", }, Symbol: { message: "Avoid using the `Symbol` type. Did you mean `symbol`?", }, }, }, ], "@typescript-eslint/consistent-type-assertions": "error", "@typescript-eslint/consistent-type-definitions": "error", "@typescript-eslint/dot-notation": "error", "@typescript-eslint/explicit-member-accessibility": [ "error", { accessibility: "explicit", overrides: { constructors: "off", }, }, ], "@typescript-eslint/indent": "off", "@typescript-eslint/member-delimiter-style": [ "off", { multiline: { delimiter: "none", requireLast: true, }, singleline: { delimiter: "semi", requireLast: false, }, }, ], // "@typescript-eslint/member-ordering": "error", "@typescript-eslint/naming-convention": [ "warn", { selector: ["enum", "enumMember"], format: ["StrictPascalCase"], }, ], "@typescript-eslint/prefer-enum-initializers": "error", "@typescript-eslint/prefer-literal-enum-member": "error", "@typescript-eslint/no-mixed-enums": "error", "@typescript-eslint/no-empty-function": "warn", "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-namespace": "error", "@typescript-eslint/no-parameter-properties": "off", "@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-this-alias": "error", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-var-requires": "warn", "@typescript-eslint/prefer-for-of": "off", "@typescript-eslint/prefer-function-type": "error", "@typescript-eslint/prefer-namespace-keyword": "error", "@typescript-eslint/quotes": "off", "@typescript-eslint/semi": ["off", null], "@typescript-eslint/triple-slash-reference": [ "error", { path: "always", types: "prefer-import", lib: "always", }, ], "@typescript-eslint/type-annotation-spacing": "off", "@typescript-eslint/unified-signatures": "error", // "arrow-body-style": "error", "arrow-parens": ["off", "always"], "brace-style": ["off", "off"], "comma-dangle": "off", complexity: "off", curly: "error", "cypress/unsafe-to-chain-command": "warn", // TODO clean up these errors since these should be treated like errors "dot-notation": "error", "eol-last": "off", eqeqeq: ["error", "always", {null: "ignore"}], "guard-for-in": "error", "id-denylist": [ "error", "any", "Number", "number", // "String", "string", "Boolean", "boolean", "Undefined", "undefined", ], "id-match": "error", // We are using this plugin to handle side effect imports, which eslint-plugin-import does not handle "simple-import-sort/imports": [ "error", // This allows us to have no spaces between groups { groups: [ ["^\\u0000(?!\\.s?css)$"], ["^react$", "^node:", "^(?!@ob)[@\\w]"], ["^@ob.*$"], ["^\\..+(?!\\.)"], ], }, ], "simple-import-sort/exports": "off", /** * This rules takes up a lot of time and memory, by far the slowest rule when checked with * TIMING=1. When disabled, a different `import/` rule will become the slowest, since * whichever is the first to build the export tree takes the hit. However, this one seems to * be nearly 6 times as bad as the others. */ "import/namespace": "off", "import/no-default-export": "warn", "import/no-named-as-default": "error", "import/newline-after-import": ["error", {count: 1}], "import/no-duplicates": ["error", {"prefer-inline": true}], "import/no-extraneous-dependencies": "off", "import/no-unresolved": "error", // "import/no-cycle": ["warn", {maxDepth: 1}], // // the import/no-internal-modules lint rule is very slow for relatively minimal gain // "import/no-internal-modules": [ // "warn", // { // "allow": [ // "antd/*", // "@ob/ui/*", // ] // } // ], indent: "off", "jsdoc/check-alignment": "off", "jsdoc/check-indentation": "off", "jsdoc/newline-after-description": "off", "linebreak-style": "off", "max-classes-per-file": ["warn", 1], "max-len": "off", "new-parens": "off", "newline-per-chained-call": "off", "no-bitwise": "error", "no-caller": "error", "no-cond-assign": "error", "no-console": "error", "no-debugger": "error", "no-duplicate-case": "error", "no-duplicate-imports": "error", "no-empty": "error", "no-empty-function": "off", "no-eval": "error", "no-extra-bind": "error", "no-extra-semi": "off", "no-fallthrough": "off", "no-invalid-this": "error", "no-irregular-whitespace": "off", "no-multiple-empty-lines": "off", "no-new-func": "error", "no-new-wrappers": "error", "no-relative-import-paths/no-relative-import-paths": [ "error", {allowSameFolder: true, prefix: "@ob"}, ], "no-restricted-imports": ["error", "aws-sdk", "mocha"], "no-restricted-syntax": [ "error", { selector: "MethodDefinition[static = true] ThisExpression", message: "Static this can be confusing and imprecise when used with extended classes", }, { selector: 'PropertyDefinition Identifier[name="whyDidYouRender"], MemberExpression Identifier[name="whyDidYouRender"]', message: "Ok to use whyDidYouRender to debug, but don't commit this line to the codebase", }, ], "no-return-await": "error", "no-sequences": ["error", {allowInParentheses: false}], "no-shadow": "off", "no-sparse-arrays": "error", "no-template-curly-in-string": "error", "no-throw-literal": "error", "no-trailing-spaces": "off", "no-undef-init": "error", "no-underscore-dangle": "off", "no-unsafe-finally": "error", "no-unused-labels": "error", "no-useless-rename": "error", "no-use-before-define": "off", "object-shorthand": "error", "one-var": ["error", "never"], "padded-blocks": [ "off", { blocks: "never", }, { allowSingleLineBlocks: true, }, ], "prefer-object-spread": "error", "quote-props": "off", quotes: "off", radix: "error", "react/no-unescaped-entities": "warn", "react/no-find-dom-node": "warn", "react/jsx-boolean-value": ["error", "always"], "react/jsx-curly-spacing": "off", "react/jsx-equals-spacing": "off", "react/jsx-key": "error", "react/jsx-no-bind": [ "error", { allowArrowFunctions: true, allowFunctions: true, }, ], "react/jsx-tag-spacing": [ "off", { afterOpening: "allow", closingSlash: "allow", }, ], "react/jsx-wrap-multilines": "off", "react/prop-types": "off", "react/self-closing-comp": "error", semi: "off", "sentence-case/sentence-case": 1, "space-before-function-paren": "off", "space-in-parens": ["off", "never"], "unicorn/prefer-ternary": "off", "unused-imports/no-unused-imports": "off", "disable-autofix/unused-imports/no-unused-imports": "error", "unused-imports/no-unused-vars": [ "warn", {vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_"}, ], "use-isnan": "error", "valid-typeof": "off", "cypress/no-pause": "error", // TODO: For now, all recommended jsx-a11y rules that are erroring will be set to warn "jsx-a11y/no-noninteractive-element-interactions": "warn", "jsx-a11y/no-static-element-interactions": "warn", "jsx-a11y/click-events-have-key-events": "warn", "jsx-a11y/label-has-associated-control": "warn", "jsx-a11y/mouse-events-have-key-events": "warn", "jsx-a11y/interactive-supports-focus": "warn", "jsx-a11y/no-noninteractive-tabindex": "warn", "jsx-a11y/heading-has-content": "warn", "jsx-a11y/no-redundant-roles": "warn", "jsx-a11y/iframe-has-title": "warn", "jsx-a11y/anchor-is-valid": "warn", "jsx-a11y/no-autofocus": "warn", "jsx-a11y/aria-role": "warn", "jsx-a11y/alt-text": "warn", "no-only-tests/no-only-tests": "error", "@regru/prefer-early-return/prefer-early-return": "warn", }, overrides: [ { files: ["**/__tests__/*", "**/*.test.ts"], extends: ["plugin:jest/recommended"], plugins: ["jest"], }, { files: ["**/*.spec.ts*", "**.cy.ts*", "cypress/**", "integration/**"], rules: { "sentence-case/sentence-case": "off", }, }, { // Turn off no-restricted-imports and no-relative-imports in webpack files files: ["**/webpack.*.ts"], rules: { "no-restricted-imports": "off", "no-relative-import-paths/no-relative-import-paths": "off", }, }, { parserOptions: { project: "./tsconfig.cypress.json", }, files: ["cypress/**/*.ts", "**/*.cy.tsx", "./cypress.config.ts"], }, { parserOptions: { project: "./tsconfig.json", }, files: ["**/*[!.cy].tsx", "./[!cypress]*/**/*.ts"], }, { // FIXME: We have issues with circular dependencies surrounding Actions, // so the import ordering of these files matters. files: ["webapp/__tests__/**/*", "webapp/src/client/mainapp/models/**/*"], rules: { "simple-import-sort/imports": "off", "import/namespace": "off", "import/newline-after-import": "off", "import/no-duplicates": "off", }, }, { files: ["*jest.config.js", ".prettierrc.js"], rules: { "@typescript-eslint/no-var-requires": "off", }, }, ], ignores: [ "node_modules/**", "**/node_modules/**", "build/**", "screenshot/**", "sensors/**", "**/dist/**", "**/prototype/**/*.ts", "**/prototype/**/*.tsx", "**/typings/**", "**/*.d.ts", "**/.eslintrc.js", "**/jest-coverage/**", "observe-js.code-workspace", "webapp/src/client/mainapp/gql/**", "webapp/src/client/mainapp/lib/history-no-decode.js", ], }, ]; ```

What did you expect to happen?

I am trying to upgrade to use flat config, however im stuck when running yarn lint due to this error message. I could not figure out by googling it or reading the docs what the cause of the error was.

I expected to receive guidance from the yarn lint command regarding what remediation action to take

What actually happened?

this stack trace:

Oops! Something went wrong! :(

ESLint: 9.1.1

Error: This method cannot be used with flat config. Add your entries directly into the config array. at assertEslintrcConfig (/Users/erica.gucciardo/observe/code/js/node_modules/eslint/lib/linter/linter.js:1256:15) at Linter.getRules (/Users/erica.gucciardo/observe/code/js/node_modules/eslint/lib/linter/linter.js:2185:9) at Object. (/Users/erica.gucciardo/observe/code/js/node_modules/eslint-plugin-disable-autofix/index.js:39:29) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at cjsLoader (node:internal/modules/esm/translators:356:17) at ModuleWrap. (node:internal/modules/esm/translators:305:7) at ModuleJob.run (node:internal/modules/esm/module_job:218:25)

Link to Minimal Reproducible Example

https://codesandbox.io/p/devbox/9h46mr

Participation

Additional comments

In the code sandbox link, go to "terminal" and run pnpm lint to see the message:

image
mdjermanovic commented 3 weeks ago

ESLint: 9.1.1

Error: This method cannot be used with flat config. Add your entries directly into the config array. at assertEslintrcConfig (/Users/erica.gucciardo/observe/code/js/node_modules/eslint/lib/linter/linter.js:1256:15) at Linter.getRules (/Users/erica.gucciardo/observe/code/js/node_modules/eslint/lib/linter/linter.js:2185:9) at Object. (/Users/erica.gucciardo/observe/code/js/node_modules/eslint-plugin-disable-autofix/index.js:39:29)

It seems that eslint-plugin-disable-autofix doesn't support ESLint v9 yet. Can you please submit an issue to the plugin's repository:

https://github.com/chiefmikey/eslint-plugin-disable-autofix