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 lowercase-description rule #56

Merged
merged 3 commits into from Feb 12, 2018

Conversation

ismail-syed
Copy link
Contributor

Fixes #46

'test("foo", function () {})',
],

invalid: [
Copy link
Member

@SimenB SimenB Jan 14, 2018

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

Copy link
Collaborator

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!

Copy link
Member

@SimenB SimenB left a 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

@SimenB
Copy link
Member

SimenB commented Feb 10, 2018

@ismail-syed ping 🙂

@ismail-syed ismail-syed force-pushed the test-description-lowercase branch 2 times, most recently from 0d1a166 to 1fe99d6 Compare February 10, 2018 23:10
@ismail-syed
Copy link
Contributor Author

Sorry for the delay, thanks for the pin @SimenB.
Comments have been addressed. Not sure why CI is complain, any suggestions?

Copy link
Collaborator

@macklinu macklinu left a 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.

};

const testDescription = node => {
const { type } = node.arguments[0];
Copy link
Collaborator

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)

};

const isItDescription = node => {
const foo =
Copy link
Collaborator

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.

Copy link
Contributor Author

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.


const ruleMsg = 'it() description should begin with lowercase';

const isItOrTestorDescribeFunction = node => {
Copy link
Collaborator

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

meta: {
docs: {
url:
'https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/lowercase_description.md',
Copy link
Collaborator

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).

Copy link
Contributor Author

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.

const descriptionBeginsWithLowerCase = node => {
if (isItOrTestorDescribeFunction(node) && isItDescription(node)) {
const description = testDescription(node);
return description[0] === description[0].toLowerCase();
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@@ -0,0 +1,64 @@
'use strict';

const ruleMsg = 'it() description should begin with lowercase';
Copy link
Member

@SimenB SimenB Feb 11, 2018

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

@ismail-syed ismail-syed force-pushed the test-description-lowercase branch 4 times, most recently from 7d0f175 to e87088c Compare February 11, 2018 23:10
Copy link
Member

@SimenB SimenB left a 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.

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.

None yet

3 participants