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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(no-disabled-tests): fix false positives for pending() usage #155
Conversation
@@ -14,6 +14,7 @@ module.exports = { | |||
}, | |||
env: { | |||
node: true, | |||
es6: true, |
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.
I used a Set()
in my solution, and this was needed for ESLint to understand the Set
global.
const ruleTester = new RuleTester(); | ||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
sourceType: 'module', |
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.
This allows for writing examples that use ES modules (i.e. import
statements).
' expect(pending()).toEqual({})', | ||
'})', | ||
'', | ||
'function pending() {', |
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.
We want to ensure that a local function called pending()
will not trigger a no-disabled-tests violation.
@@ -19,6 +19,33 @@ function getName(node) { | |||
return null; | |||
} | |||
|
|||
function collectReferences(scope) { |
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.
This function takes the current scope (so wherever the pending()
function is called) and walks up the tree to collect all local references and unresolved references. This information is helpful for determining what local variables or functions have been defined in a file, as well as what variables that ESLint could not resolve (which likely means those are globals, like describe()
& test()
).
// meaning it is likely not an implicit global reference. | ||
!references.unresolved.has('pending') | ||
) { | ||
break; |
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.
Let me know if this if
statement is clear enough with the comment or if you see a clearer way to communicate this - I want this change to be as understandable and maintainable as possible. 鉂わ笍
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.
I think this is great! Separate Set
s make it quite straight forward to follow the flow 馃檪
Thank you so much for your continued help, @macklinu! I sent you an invite to this repo 馃檪 |
@macklinu I wonder if https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-jasmine-globals.md might need the same treatment that |
馃帀 This PR is included in version 21.22.1 馃帀 The release is available on: Your semantic-release bot 馃摝馃殌 |
Resolves #149
This PR adds some failing test cases and fixes for false positive warnings of
pending()
in the no-disabled-tests rule.I'll add some comments inline to help explain my solution - feedback welcome! 馃樅