-
Notifications
You must be signed in to change notification settings - Fork 228
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
Consistent-test-it rule #64
Conversation
README.md
Outdated
@@ -80,6 +80,7 @@ for more information about extending configuration files. | |||
|
|||
| Rule | Description | Recommended | Fixable | | |||
| ------------------------------------------------------------------ | --------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | | |||
| [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce consistent test or it keyword | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | |
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.
Not recommended
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.
badge removed
rules/consistent-test-it.js
Outdated
|
||
context.report({ | ||
message: | ||
"Prefer using '{{ testKeyword }}' on '{{ opositeTestKeyword }}'", |
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.
Switch "on" with "instead of" perhaps?
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 agree, "instead of" is better.
rules/consistent-test-it.js
Outdated
@@ -0,0 +1,124 @@ | |||
'use strict'; | |||
|
|||
const { getNodeName, isTestCase, isDescribe } = require('./util'); |
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.
cannot use destructuring due to node 4 support - see failing CI
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.
May be worth adding the es5/no-destructuring
rule to help prevent/communicate this.
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.
Opened #66 to address this.
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.
Yes, I see, Will be fixed
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.
A few minor things/typos, but looking like it covers all the desired cases. Nice work, thanks for submitting a PR!
rules/consistent-test-it.js
Outdated
], | ||
}, | ||
create(context) { | ||
const configObj = context.options[0]; |
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 you could declare this like:
const configObj = context.options[0] || {}
And then you're always dealing with a truthy object, so that on the following lines, you do not need to call configObj && configObj.propertyName
.
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 agree about that. Thanks
rules/consistent-test-it.js
Outdated
describeNestingLevel === 0 && | ||
nodeName.indexOf(testKeyword) === -1 | ||
) { | ||
const opositeTestKeyword = getOpositeTestKeyword(testKeyword); |
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.
oposite
is misspelled - should be opposite
.
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.
🙃
rules/consistent-test-it.js
Outdated
}, | ||
}; | ||
|
||
function getPreferedNodeName(nodeName, preferedTestKeyword) { |
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.
prefered
is mispelled - should be preferred
.
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.
@ranyitz thanks for addressing those comments. LGTM 😄
const testKeyword = configObj.fn || 'test'; | ||
const testKeywordWithinDescribe = | ||
configObj.withinDescribe || configObj.fn || 'it'; | ||
|
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.
valid: [ | ||
{ | ||
code: 'test("foo")', | ||
options: [{ fn: 'test', withinDescribe: 'it' }], |
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 removing options
here is enough to get to 100% coverage 🙂
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.
Yes, you are right :) will push fix soon
@SimenB Thanks for the comment. |
Following the discussion in #12
Summary
This rule gives you control over the usage of these keywords in your codebase.
You can control which style you prefer, within describe or outside.
{"fn": "it"}
enforceit
calls and fixtest
to beit
.{"fn": "test"}
enforetest
calls and fixit
to betest
.{"fn": "test", "withinDescribe":"it"}
enforcetest
on top level tests and enforceit
when nested inside ofdescribe
, fixit
totest
when using in top level, fixtest
toit
when using inside ofdescribe
.