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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new rule no-only-tests #145

Merged
merged 1 commit into from Jun 24, 2021
Merged

Conversation

bmish
Copy link
Member

@bmish bmish commented Jun 24, 2021

Fixes #118.

I named it no-only-tests for consistency with the no-identical-tests rule name. I would be equally happy to name it no-test-only or something else. Let me know if you want me to change the name.

We should enable this as a recommended rule in v4 (#120).

Most other test frameworks have a similar rule to this:

@aladdin-add
Copy link
Contributor

We should enable this as a recommended rule in v4 (#120).

👍 agreed!


## Rule Details

This rule flags a violation when a test case is using `only`. Note that this rule is not autofixable since automatically deleting the property would prevent developers from being able to use it during development.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add a suggestion to fix it?

Copy link
Member Author

@bmish bmish Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a suggestion to remove the only: true property.

In a follow-up PR, I will update the README to make it more clear which rules provide suggestions.

`,
output: null,
errors: [{ messageId: 'foundOnly', type: 'Property', line: 5, endLine: 5, column: 28, endColumn: 38 }],
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some more tests like:

const {RuleTester} = require("eslint");
const tester = new RuleTester();
tester.run('foo', bar, {...});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added imports to tests/docs.

@bmish bmish force-pushed the no-only-tests branch 2 times, most recently from 2342d55 to d8e1f1b Compare June 24, 2021 15:16
Copy link
Contributor

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@aladdin-add aladdin-add merged commit f0ac31c into eslint-community:master Jun 24, 2021
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is a comma token.
*/
function isCommaToken (token) {
Copy link
Contributor

@fisker fisker Jul 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmish

Sorry, I'm late for this.

I added eslint-utils in #111, we should use these functions from it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, didn't realize they came from there, fixed #156

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.

New rule: no-test-only
3 participants