-
Notifications
You must be signed in to change notification settings - Fork 242
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
feat(unbound-method): create rule #765
Merged
+2,067
−8
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0bfb31a
feat(unbound-method): add original `unbound-method` rule
G-Rath aa1a3d6
feat(unbound-method): modify rule for `jest`
G-Rath 2f79c3e
refactor(unbound-method): extend base rule
G-Rath 5715f91
docs(readme): add section about type-based rules
G-Rath d956d0d
chore: add `@typescript-eslint/eslint-plugin` as an optional peer dep
G-Rath 9df61ab
fix(unbound-method): re-throw errors that are not `MODULE_NOT_FOUND`
G-Rath 3e6eab8
chore(unbound-method): use early return instead of empty string
G-Rath b5f312b
test(unbound-method): adjust test
G-Rath 9610a08
build: ignore test fixtures
G-Rath b6e175e
test: add end of file newline to fixture
G-Rath ce08e5e
docs(unbound-method): mention `@typescript-eslint/eslint-plugin` dep
G-Rath 5d1612a
refactor(unbound-method): improve method & variable name
G-Rath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
coverage/ | ||
lib/ | ||
!.eslintrc.js | ||
src/rules/__tests__/fixtures/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Enforces unbound methods are called with their expected scope (`unbound-method`) | ||
G-Rath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Rule Details | ||
|
||
This rule extends the base [`@typescript-eslint/unbound-method`][original-rule] | ||
rule, meaning you must depend on `@typescript-eslint/eslint-plugin` for it to | ||
work. It adds support for understanding when it's ok to pass an unbound method | ||
to `expect` calls. | ||
|
||
See the [`@typescript-eslint` documentation][original-rule] for more details on | ||
the `unbound-method` rule. | ||
|
||
Note that while this rule requires type information to work, it will fail | ||
silently when not available allowing you to safely enable it on projects that | ||
are not using TypeScript. | ||
|
||
## How to use | ||
|
||
```json5 | ||
{ | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['test/**'], | ||
extends: ['jest'], | ||
rules: { | ||
// you should turn the original rule off *only* for test files | ||
'@typescript-eslint/unbound-method': 'off', | ||
'jest/unbound-method': 'error', | ||
}, | ||
}, | ||
], | ||
rules: { | ||
'@typescript-eslint/unbound-method': 'error', | ||
}, | ||
} | ||
``` | ||
|
||
This rule should be applied to your test files in place of the original rule, | ||
which should be applied to the rest of your codebase. | ||
|
||
## Options | ||
|
||
See [`@typescript-eslint/unbound-method`][original-rule] options. | ||
|
||
<sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup> | ||
|
||
[original-rule]: | ||
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// used by no-throw-literal test case to validate custom error | ||
export class Error {} | ||
|
||
// used by unbound-method test case to test imports | ||
export const console = { log() {} }; | ||
|
||
// used by prefer-reduce-type-parameter to test native vs userland check | ||
export class Reducable { | ||
reduce() {} | ||
} | ||
|
||
// used by no-implied-eval test function imports | ||
export class Function {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type T = number; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something about needing to install the upstream plugin as well? Possibly in the table if we'll have othe rrules in the future that do not use type info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean if we have other rules that don't extend base rules.
You're completely right - I don't expect us to make any more rules that extend base rules, only more rules that use type information; so I might leave the table as is for now and just add a sentence saying that
unbound-method
is an extension rule (as well as updating its own docs).