Skip to content

[unbound-method] should accept a whitelist #1776

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
morithon opened this issue Mar 20, 2020 · 1 comment
Closed

[unbound-method] should accept a whitelist #1776

morithon opened this issue Mar 20, 2020 · 1 comment
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look

Comments

@morithon
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/unbound-method": ["warn", { ignoreStatic: true, whitelist: ["expect"] }]
  }
}
spyOn(el, "setAttribute");
expect(el.setAttribute).not.toHaveBeenCalled();

Expected Result
For eslint not to throw an error

Actual Result
Eslint throws an error

Versions

package version
@typescript-eslint/eslint-plugin 2.15.0
@typescript-eslint/parser 2.15.0
TypeScript 3.7.5
ESLint 6.8.0
node 10.16.0
npm 6.9.0

It would be nice to have an ability to define exceptions to the rule using a whitelist option.

@morithon morithon added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 20, 2020
@bradzacher
Copy link
Member

It would probably be better to disable the rule in test files.
https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns

If there are cases in your codebase where you are okay with passing unbound methods, then you can also use disable comments.

Whitelists are generally bad because they lack context. This is doubly true for type-aware rules, as they need even more context.
For example, if I whitelist the function foo, intending to target the function in file a.ts, but then define a function foo in file b.ts, the rule has no way to tell that its not supposed to whitelist the second function. This causes false negatives, and introduces bug vectors into your codebase.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

2 participants