Skip to content

prefer-object-rule false positives #201

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

Closed
aladdin-add opened this issue Oct 11, 2021 · 3 comments · Fixed by #204
Closed

prefer-object-rule false positives #201

aladdin-add opened this issue Oct 11, 2021 · 3 comments · Fixed by #204

Comments

@aladdin-add
Copy link
Contributor

aladdin-add commented Oct 11, 2021

I've just tried [email protected] in eslint repo.

/Users/weiran/repo/github/eslint/karma.conf.js
  13:18  error  Rules should be declared using the object style  eslint-plugin/prefer-object-rule

/Users/weiran/repo/github/eslint/lib/cli-engine/formatters/checkstyle.js
  31:18  error  Rules should be declared using the object style  eslint-plugin/prefer-object-rule
.....

We can suggest users to use overrides to avoid these cases?

@bmish
Copy link
Member

bmish commented Oct 11, 2021

I think this is a pre-existing issue. That's why ESLint only enables the eslint-plugin/prefer-object-rule for rule files: https://github.com/eslint/eslint/blob/c4fffbcb089182d425ef1d5e45134fecc0e2da46/.eslintrc.js#L88

It's showing up now because we added this rule to the recommended config, so we'll just have to disable it in some places instead (or only enable the rules-recommended config for the rules folder).

@aladdin-add
Copy link
Contributor Author

aladdin-add commented Oct 11, 2021

I was thinking it can be a docs improvement - suggest using overrides to only apply the plugin to rule/test files.

or we will have to remove it from the recommended - it could be confusing for inexperienced users.

@bmish
Copy link
Member

bmish commented Oct 11, 2021

I opened a doc improvement for this in #204.

I would strongly prefer to keep eslint-plugin/prefer-object-rule as a recommended rule, especially since I'm planning to write an RFC to remove function-style rule support from ESLint in v9, so it's important that we discourage their use.

However, if necessary, as a bug fix, we could make our function-style rule detection more strict. Instead of just looking for:

  • module.exports = function (context) { ... }
  • export default function (context) { ... }

We could look for a default-exported function that has at least one object return:

  • module.exports = function (context) { return { ... } }
  • export default function (context) { return { ... } }

This would help reduce false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants