Skip to content

Commit

Permalink
fix(lowercase-name): consider skip and only prefixes for ignores (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 4, 2021
1 parent 5c0d28f commit 8716c24
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
60 changes: 60 additions & 0 deletions src/rules/__tests__/lowercase-name.test.ts
Expand Up @@ -76,6 +76,18 @@ ruleTester.run('lowercase-name', rule, {
},
],
},
{
code: "xit('Foo', function () {})",
output: "xit('foo', function () {})",
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: TestCaseName.xit },
column: 5,
line: 1,
},
],
},
{
code: 'it("Foo", function () {})',
output: 'it("foo", function () {})',
Expand Down Expand Up @@ -112,6 +124,18 @@ ruleTester.run('lowercase-name', rule, {
},
],
},
{
code: "xtest('Foo', function () {})",
output: "xtest('foo', function () {})",
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: TestCaseName.xtest },
column: 7,
line: 1,
},
],
},
{
code: 'test("Foo", function () {})',
output: 'test("foo", function () {})',
Expand Down Expand Up @@ -184,6 +208,18 @@ ruleTester.run('lowercase-name', rule, {
},
],
},
{
code: 'fdescribe(`Some longer description`, function () {})',
output: 'fdescribe(`some longer description`, function () {})',
errors: [
{
messageId: 'unexpectedLowercase',
data: { method: DescribeAlias.fdescribe },
column: 11,
line: 1,
},
],
},
{
code: "it.each(['green', 'black'])('Should return %', () => {})",
output: "it.each(['green', 'black'])('should return %', () => {})",
Expand Down Expand Up @@ -225,6 +261,14 @@ ruleTester.run('lowercase-name with ignore=describe', rule, {
code: 'describe(`Foo`, function () {})',
options: [{ ignore: [DescribeAlias.describe] }],
},
{
code: 'fdescribe(`Foo`, function () {})',
options: [{ ignore: [DescribeAlias.describe] }],
},
{
code: 'describe.skip(`Foo`, function () {})',
options: [{ ignore: [DescribeAlias.describe] }],
},
],
invalid: [],
});
Expand All @@ -243,6 +287,14 @@ ruleTester.run('lowercase-name with ignore=test', rule, {
code: 'test(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.test] }],
},
{
code: 'xtest(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.test] }],
},
{
code: 'test.only(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.test] }],
},
],
invalid: [],
});
Expand All @@ -261,6 +313,14 @@ ruleTester.run('lowercase-name with ignore=it', rule, {
code: 'it(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.it] }],
},
{
code: 'fit(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.it] }],
},
{
code: 'it.skip(`Foo`, function () {})',
options: [{ ignore: [TestCaseName.it] }],
},
],
invalid: [],
});
Expand Down
19 changes: 18 additions & 1 deletion src/rules/lowercase-name.ts
Expand Up @@ -36,6 +36,22 @@ const findNodeNameAndArgument = (
return [getNodeName(node).split('.')[0], node.arguments[0]];
};

const populateIgnores = (ignore: readonly string[]): string[] => {
const ignores: string[] = [];

if (ignore.includes(DescribeAlias.describe)) {
ignores.push(...Object.keys(DescribeAlias));
}
if (ignore.includes(TestCaseName.test)) {
ignores.push(...Object.keys(TestCaseName));
}
if (ignore.includes(TestCaseName.it)) {
ignores.push(...Object.keys(TestCaseName));
}

return ignores;
};

export default createRule<
[
Partial<{
Expand Down Expand Up @@ -94,6 +110,7 @@ export default createRule<
context,
[{ ignore = [], allowedPrefixes = [], ignoreTopLevelDescribe }],
) {
const ignores = populateIgnores(ignore);
let numberOfDescribeBlocks = 0;

return {
Expand Down Expand Up @@ -125,7 +142,7 @@ export default createRule<
if (
!firstCharacter ||
firstCharacter === firstCharacter.toLowerCase() ||
ignore.includes(name as IgnorableFunctionExpressions)
ignores.includes(name as IgnorableFunctionExpressions)
) {
return;
}
Expand Down

0 comments on commit 8716c24

Please sign in to comment.