-
Notifications
You must be signed in to change notification settings - Fork 236
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 lowercase-description rule #56
Add lowercase-description rule #56
Conversation
bd752c2
to
f213dd3
Compare
'test("foo", function () {})', | ||
], | ||
|
||
invalid: [ |
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 it should warn for describe
and test
as well
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, I think that'd be nice!
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.
See inline comment.
CI is failing because the commit message is not semantic. Changing it to feat: add lowercase-description rule
and force pushing should fix it
@ismail-syed ping 🙂 |
0d1a166
to
1fe99d6
Compare
Sorry for the delay, thanks for the pin @SimenB. |
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'm not sure why the build is failing on Node 6 or Node 8 (looks like an issue with commitlint), but object destructuring is causing the Node 4 build failure (I commented on the problematic line).
I commented with some other suggestions and edge cases that I saw as well.
rules/lowercase_description.js
Outdated
}; | ||
|
||
const testDescription = node => { | ||
const { type } = node.arguments[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.
Object destructuring is not supported on Node 4, which is causing the Node 4 failure on Travis.
Related: #64 (comment)
rules/lowercase_description.js
Outdated
}; | ||
|
||
const isItDescription = node => { | ||
const foo = |
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.
Minor suggestion: return this conditional statement instead of assigning to foo
, since the variable doesn't explain what's going on in this function.
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.
Ops, forgot to remove this when I was poking around. Nice catch.
rules/lowercase_description.js
Outdated
|
||
const ruleMsg = 'it() description should begin with lowercase'; | ||
|
||
const isItOrTestorDescribeFunction = node => { |
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.
Minor function renaming suggestion: isItTestOrDescribeFunction
rules/lowercase_description.js
Outdated
meta: { | ||
docs: { | ||
url: | ||
'https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/lowercase_description.md', |
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.
lowercase_description
should be lowercase-description
to match the lowercase-description.md
filename.
I think if you have master merged in, this is autofixable with ESLint (introduced in #60).
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 did have the merged changes. The issue was that the file name was rules/lowercase_description.js
, instead of rules/lowercase-description.js
. Looks like the rule enforces the expected doc to be present based on the current file name.
rules/lowercase_description.js
Outdated
const descriptionBeginsWithLowerCase = node => { | ||
if (isItOrTestorDescribeFunction(node) && isItDescription(node)) { | ||
const description = testDescription(node); | ||
return description[0] === description[0].toLowerCase(); |
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.
Looking at the definition of testDescription()
, it can technically return undefined if the first argument's type is not Literal
or TemplateLiteral
, or if the Literal
provided is not a string.
For example, the following code:
it(42, () => {})
will result in TypeError: Cannot read property 'toLowerCase' of undefined
since the first argument of it()
is a Literal
, but it's not a string.
While passing a number as the first argument of it()
isn't really valid, I think this rule should protect against a possibility like 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.
Good catch, updated and added some tests to check this as well.
1fe99d6
to
ea38aa7
Compare
rules/lowercase-description.js
Outdated
@@ -0,0 +1,64 @@ | |||
'use strict'; | |||
|
|||
const ruleMsg = 'it() description should begin with lowercase'; |
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.
the it
part of the message should reflect test
or describe
as well
7d0f175
to
e87088c
Compare
e87088c
to
45396c1
Compare
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.
Thanks!
I tweaked the message a bit and changed the name.
Fixes #46