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

Support ESLint 9 and Flat config #449

Open
Tracked by #18093 ...
brettz9 opened this issue Jan 17, 2024 · 13 comments
Open
Tracked by #18093 ...

Support ESLint 9 and Flat config #449

brettz9 opened this issue Jan 17, 2024 · 13 comments

Comments

@brettz9
Copy link
Contributor

brettz9 commented Jan 17, 2024

Description

Please add support for ESLint 9, including Flat config support.

See:

  1. https://eslint.org/docs/latest/use/configure/configuration-files-new
  2. https://eslint.org/blog/2022/08/new-config-system-part-1/
  3. https://eslint.org/blog/2022/08/new-config-system-part-2/
  4. https://eslint.org/docs/latest/use/configure/migration-guide

Thanks!

@erichosick
Copy link

Want to try and work on this a bit. Trying to follow the pattern in eslint-plugin-n

import promise from 'eslint-plugin-promise';

/// TODO: Get the package name and version from package.json
const mod = {
  meta: {
    name: 'eslint-plugin-promise', /// pkg.name,
    version: '6.1.1', /// pkg.version,
  },
  rules: promise.rules, /// the rule definitions
}

const recommendedConfig = {
  flat: {
    languageOptions: {}, /// no language options for promise that I know of
    rules: promise.configs.recommended.rules, /// the rules we are applying
  }
}

/// really not sure how the eslint-plugin-promise wants to expose their
/// but here is a sort of guess.
mod.configs = {
  "flat/recommended": [
    {
      plugins: {
        promise: mod
      },
      files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
      ...recommendedConfig.flat
    },
  ],
}

export default mod;

usage in flat file is something like:

// files: eslint.config.mjs

import promise from './eslint-plugin-promise-flat.mjs';
const flatConfig = promise.configs["flat/recommended"];

const eslintConfigObjects = [
  ...flatConfig,
];

export default eslintConfigObjects;

but when actually linting say no-promise-in-callback, getAncestors is undefined.

The line of code is here.

So, not quite sure why this is happening.

@brettz9
Copy link
Contributor Author

brettz9 commented Jan 21, 2024

Some of the APIs have been dropped in ESLint 9. context.getAncestors should be changed to SourceCode#getAncestors(node). See https://eslint.org/docs/latest/extend/custom-rules for the already deprecated items which are being dropped in ESLint 9.

@erichosick
Copy link

Heads up that the above link sends us to the older docs (at this time). Maybe this link instead? https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()

@brettz9
Copy link
Contributor Author

brettz9 commented Jan 22, 2024

Sure, I just meant the older docs for the fact that it had already been deprecated and a replacement was indicated there too. But yours is presumably even more current.

@erichosick
Copy link

Just one more note that the above example code does work for eslint v8. So, may be helpful for anyone wanting to use flat config in V8.

@TheElegantCoding
Copy link

+1 to this support

@doberkofler
Copy link

eslint v9 has just been released and support for v9 would be greatly appreciated

@voxpelli
Copy link
Member

voxpelli commented Apr 6, 2024

I'll try to find time to implement this if no-one beats me to it 👍

@crystalfp
Copy link

FYI. The rules that I had to disable to have eslint succeed are:

        "promise/no-return-wrap": "warn",
        "promise/no-promise-in-callback": "warn",
        "promise/no-nesting": "warn",
        "promise/no-callback-in-promise": "warn",

@electriquo
Copy link

Hi guys, are there any plans to support flat config?

@voxpelli
Copy link
Member

voxpelli commented May 1, 2024

Hi guys, are there any plans to support flat config?

Yes, just not a definite timeline

@TheElegantCoding
Copy link

the package also need type declaration for the export in flat config
image

@donalmurtagh
Copy link

donalmurtagh commented May 13, 2024

It's possible to make the current version of the promise plugin work in an ESLint v9 flag configuration file using @eslint/compat by following these instructions.

In my case I made these changes to eslint.config.js

import { FlatCompat } from '@eslint/eslintrc'
import { fixupConfigRules } from '@eslint/compat'

const compat = new FlatCompat()

export default [
  /*
  To make the promise plugin work with ESLint v9 we have to use
  1. fixupConfigRules to fix obsolete rules API usages
  2. FlatCompat to convert the plugin's config format to the v9 flat format
  */
  ...fixupConfigRules(
    compat.config({
      extends: ['plugin:promise/recommended'],
      ignorePatterns: ['tests/e2e']
    })
  ),
  // other config objects
]

Jaid added a commit to Jaid/eslint-config-jaid that referenced this issue May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants