eslint-plugin-promise icon indicating copy to clipboard operation
eslint-plugin-promise copied to clipboard

Support ESLint 9 and Flat config

Open brettz9 opened this issue 1 year ago • 13 comments

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!

brettz9 avatar Jan 17 '24 04:01 brettz9

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.

erichosick avatar Jan 21 '24 20:01 erichosick

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.

brettz9 avatar Jan 21 '24 21:01 brettz9

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()

erichosick avatar Jan 22 '24 23:01 erichosick

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.

brettz9 avatar Jan 22 '24 23:01 brettz9

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.

erichosick avatar Jan 23 '24 01:01 erichosick

+1 to this support

TheElegantCoding avatar Mar 23 '24 17:03 TheElegantCoding

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

doberkofler avatar Apr 06 '24 07:04 doberkofler

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

voxpelli avatar Apr 06 '24 18:04 voxpelli

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",

crystalfp avatar Apr 12 '24 12:04 crystalfp

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

electriquo avatar May 01 '24 07:05 electriquo

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

Yes, just not a definite timeline

voxpelli avatar May 01 '24 10:05 voxpelli

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

TheElegantCoding avatar May 04 '24 05:05 TheElegantCoding

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
]

donalmurtagh avatar May 13 '24 18:05 donalmurtagh

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

zloirock avatar May 28 '24 00:05 zloirock

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

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 01 '24 02:07 github-actions[bot]

Thank you!

mightyiam avatar Jul 01 '24 02:07 mightyiam