eslint-community / eslint-plugin-promise

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

After migration to flat file (eslint 9.0/eslint-plugin-promise 6.2.4), I can no longer use my config file to ignore a eslint-plugin-promise rule. #481

Closed cagross closed 2 months ago

cagross commented 2 months ago

Description

[Description of the issue or feature request]

Steps to Reproduce

  1. Ensure config file is configured to ignore plugin rules catch-or-return and always-return.
  2. Open one single file in VSCode--one which contains violations of each of the above rules.

Expected behavior: I expect the VSCode output panel to contain zero entries related to these rules.

Actual behavior: The VSCode output panel contains entries related to these rules (see screenshot below).

image

Versions

[Please fill this in if you are submitting a bug report]

Additional Information

See below for the full contents of my eslint.config.js file. I can confirm this is the config being applied to the file in-question. Prior to updating eslint to v9.0, my .eslintrc file was also configured to ignore these two rules, and VSCode was successfully doing so. I tried changing the property value from 0 to 'off' (e.g. promise/catch-or-return': 'off') but that didn't change anything.

const prettier = require('eslint-plugin-prettier')
const promise = require('eslint-plugin-promise')
const globals = require('globals')
const js = require('@eslint/js')
const eslintConfigPrettier = require('eslint-config-prettier')
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended')
module.exports = [
  js.configs.recommended,

  {
    languageOptions: {
      parserOptions: {
        ecmaVersion: 'latest',
        sourceType: 'module',
        ecmaFeatures: {
          globalReturn: true,
          jsx: true
        }
      },

      globals: {
        Promise: true,
        $: true,
        ow0: true,
        ow4: true,
        ow5: true,
        __: true,
        common: true,
        no$: true,
        $ajax: true,
        ...globals.browser,
        ...globals.commonjs,
        ...globals['shared-node-browser'],
        ...globals.node,
        ...globals.es5,
        ...globals.es6,
        ...globals.es2015,
        ...globals.es2016,
        ...globals.es2017,
        ...globals.es2018,
        ...globals.es2019,
        ...globals.es2020,
        ...globals.es2021,
        ...globals.es2022,
        ...globals.es2023,
        ...globals.es2024
      }
    },

    plugins: {
      promise: promise,
      prettier: prettier
    },

    rules: {
      'prettier/prettier': [
        'error',
        {
          printWidth: 100,
          singleQuote: true,
          tabWidth: 2,
          semi: false,
          endOfLine: 'lf'
        }
      ],
      'promise/catch-or-return': 0,
      'promise/always-return': 0,
      'space-before-function-paren': 0,
      'arrow-parens': ['error', 'as-needed']
    }
  },
  {
    ignores: [
      'node_modules/',
      'assets/dependencies/**/*.js',
      'assets/build/**/*.js',
      'test/**/*.js',
      'dev/**/*.js'
    ]
  },
  eslintPluginPrettierRecommended,
  eslintConfigPrettier,
  promise.configs['flat/recommended']
]
aladdin-add commented 2 months ago

in the flat config, its order matters. it's recommended to put your own config to the last to avoid overwritten by the 3rd-party configs:

module.exports = [
  promise.configs['flat/recommended'],
  {rules : {'promise/catch-or-return': 0,}}
];
cagross commented 2 months ago

OK understood. The rule needs to be defined first, then disabled. In my case, I was trying to disable first, before the rule was defined. Does that sound right?

Anyway, making your change resolved the issue, so thanks. I'll keep this in-mind for the future.

aladdin-add commented 2 months ago

the rule was enabled in the preset, so in your case, it's like:

module.exports = [
{rules : {'promise/catch-or-return': 0,}},
{rules : {'promise/catch-or-return': 2,}}, // flat/recommended
];

eslint will deep-merge these config objects in turn, with the later ones overriding the earlier ones( something like Object.assign()). so the it's enabled in the calculated config.

cagross commented 2 months ago

Ah OK I see. Thanks very much for all that, and the prompt response.