Skip to content
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

Merged
merged 1 commit into from Sep 21, 2018

Conversation

macklinu
Copy link
Collaborator

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! 馃樅

@@ -14,6 +14,7 @@ module.exports = {
},
env: {
node: true,
es6: true,
Copy link
Collaborator Author

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',
Copy link
Collaborator Author

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() {',
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

@macklinu macklinu Sep 21, 2018

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. 鉂わ笍

Copy link
Member

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 Sets make it quite straight forward to follow the flow 馃檪

@SimenB
Copy link
Member

SimenB commented Sep 21, 2018

Thank you so much for your continued help, @macklinu! I sent you an invite to this repo 馃檪

@SimenB SimenB merged commit fdce162 into jest-community:master Sep 21, 2018
@SimenB
Copy link
Member

SimenB commented Sep 21, 2018

@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 pending got in this PR. Thoguhts?

@SimenB
Copy link
Member

SimenB commented Sep 21, 2018

馃帀 This PR is included in version 21.22.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

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

Successfully merging this pull request may close these issues.

question : a function named pending () triggered the 'no-disabled-tests' error. my bad?
2 participants