eslint-community / eslint-plugin-promise

Enforce best practices for JavaScript promises
ISC License
938 stars 91 forks source link

Support ESLint 9 and Flat config #449

Closed brettz9 closed 2 months ago

brettz9 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 5 months ago

+1 to this support

doberkofler commented 5 months ago

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

voxpelli commented 5 months ago

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

crystalfp commented 4 months ago

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 commented 4 months ago

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

voxpelli commented 4 months ago

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

Yes, just not a definite timeline

TheElegantCoding commented 4 months ago

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

donalmurtagh commented 3 months ago

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
]
zloirock commented 3 months ago

https://github.com/eslint-community/eslint-plugin-promise/issues/472

github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 6.4.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

mightyiam commented 2 months ago

Thank you!