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
feat(rules): Add no-empty-title rule #238
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6ad217e
fix(no-identical-titles): report if identical TemplateLiterals
himynameisdave 4b12161
refactor: move some methods to utils
himynameisdave e005ee3
feat: add no-empty-title
himynameisdave 9dd2c61
docs: add documentation for no-empty-title
himynameisdave f67448e
docs(readme): add no-empty-title to the README
himynameisdave 3ef3ecd
chore: add jest/no-empty-title to recommended config
himynameisdave 62d2c58
test: 100% code coverage for no-empty-title rule
himynameisdave 626ff33
fix(no-identical-title): guard if there is no first argument
himynameisdave 94b723e
fix(no-identical-title): remove boolean casting
himynameisdave a1ddaf9
fix(readme): fixes a readme typo
himynameisdave 597cb39
Merge branch 'master' into issues/226
himynameisdave 0eac78b
Merge branch 'master' into issues/226
himynameisdave 9878304
chore: remove new rule from recommended config
SimenB 2289022
chore: add tests for template literal
SimenB 63f1d71
chore: remove rule from recommended config
SimenB 22fd997
fix: handle case where templateliterals breaks
himynameisdave e72a90d
chore: export helper
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Disallow empty titles | ||
|
||
Having an empty string as your test title is pretty useless. This rule reports | ||
an error if it finds an empty string as s test title. | ||
|
||
This rule is not auto-fixable. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
describe('', () => {}); | ||
describe('foo', () => { | ||
it('', () => {}); | ||
}); | ||
it('', () => {}); | ||
test('', () => {}); | ||
xdescribe('', () => {}); | ||
xit('', () => {}); | ||
xtest('', () => {}); | ||
``` | ||
|
||
These patterns would not be considered warnings: | ||
|
||
```js | ||
describe('foo', () => {}); | ||
describe('foo', () => { | ||
it('bar', () => {}); | ||
}); | ||
test('foo', () => {}); | ||
it('foo', () => {}); | ||
xdescribe('foo', () => {}); | ||
xit('foo', () => {}); | ||
xtest('foo', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
'use strict'; | ||
|
||
const { RuleTester } = require('eslint'); | ||
const rule = require('../no-empty-title'); | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
sourceType: 'module', | ||
}, | ||
}); | ||
|
||
ruleTester.run('no-empty-title', rule, { | ||
valid: [ | ||
'someFn("", function () {})', | ||
'describe(1, function () {})', | ||
'describe("foo", function () {})', | ||
'describe("foo", function () { it("bar", function () {}) })', | ||
'test("foo", function () {})', | ||
'test(`foo`, function () {})', | ||
'test(`${foo}`, function () {})', | ||
"it('foo', function () {})", | ||
"xdescribe('foo', function () {})", | ||
"xit('foo', function () {})", | ||
"xtest('foo', function () {})", | ||
], | ||
invalid: [ | ||
{ | ||
code: 'describe("", function () {})', | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.describe, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ["describe('foo', () => {", "it('', () => {})", '})'].join('\n'), | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 2, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'it("", function () {})', | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'test("", function () {})', | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'test(``, function () {})', | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "xdescribe('', () => {})", | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.describe, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "xit('', () => {})", | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "xtest('', () => {})", | ||
errors: [ | ||
{ | ||
message: rule.errorMessages.test, | ||
column: 1, | ||
line: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const { | ||
getDocsUrl, | ||
hasExpressions, | ||
isDescribe, | ||
isTestCase, | ||
isTemplateLiteral, | ||
isString, | ||
getStringValue, | ||
} = require('./util'); | ||
|
||
const errorMessages = { | ||
describe: 'describe should not have an empty title', | ||
test: 'test should not have an empty title', | ||
}; | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
url: getDocsUrl(__filename), | ||
}, | ||
}, | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
const is = { | ||
describe: isDescribe(node), | ||
testCase: isTestCase(node), | ||
}; | ||
if (!is.describe && !is.testCase) { | ||
return; | ||
} | ||
const [firstArgument] = node.arguments; | ||
if (!isString(firstArgument)) { | ||
return; | ||
} | ||
if (isTemplateLiteral(firstArgument) && hasExpressions(firstArgument)) { | ||
return; | ||
} | ||
if (getStringValue(firstArgument) === '') { | ||
const message = is.describe | ||
? errorMessages.describe | ||
: errorMessages.test; | ||
context.report({ | ||
message, | ||
node, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
errorMessages, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
whoops my bad!