Skip to content

Commit 8716c24

Browse files
authored
fix(lowercase-name): consider skip and only prefixes for ignores (#923)
1 parent 5c0d28f commit 8716c24

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/rules/__tests__/lowercase-name.test.ts

+60
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ ruleTester.run('lowercase-name', rule, {
7676
},
7777
],
7878
},
79+
{
80+
code: "xit('Foo', function () {})",
81+
output: "xit('foo', function () {})",
82+
errors: [
83+
{
84+
messageId: 'unexpectedLowercase',
85+
data: { method: TestCaseName.xit },
86+
column: 5,
87+
line: 1,
88+
},
89+
],
90+
},
7991
{
8092
code: 'it("Foo", function () {})',
8193
output: 'it("foo", function () {})',
@@ -112,6 +124,18 @@ ruleTester.run('lowercase-name', rule, {
112124
},
113125
],
114126
},
127+
{
128+
code: "xtest('Foo', function () {})",
129+
output: "xtest('foo', function () {})",
130+
errors: [
131+
{
132+
messageId: 'unexpectedLowercase',
133+
data: { method: TestCaseName.xtest },
134+
column: 7,
135+
line: 1,
136+
},
137+
],
138+
},
115139
{
116140
code: 'test("Foo", function () {})',
117141
output: 'test("foo", function () {})',
@@ -184,6 +208,18 @@ ruleTester.run('lowercase-name', rule, {
184208
},
185209
],
186210
},
211+
{
212+
code: 'fdescribe(`Some longer description`, function () {})',
213+
output: 'fdescribe(`some longer description`, function () {})',
214+
errors: [
215+
{
216+
messageId: 'unexpectedLowercase',
217+
data: { method: DescribeAlias.fdescribe },
218+
column: 11,
219+
line: 1,
220+
},
221+
],
222+
},
187223
{
188224
code: "it.each(['green', 'black'])('Should return %', () => {})",
189225
output: "it.each(['green', 'black'])('should return %', () => {})",
@@ -225,6 +261,14 @@ ruleTester.run('lowercase-name with ignore=describe', rule, {
225261
code: 'describe(`Foo`, function () {})',
226262
options: [{ ignore: [DescribeAlias.describe] }],
227263
},
264+
{
265+
code: 'fdescribe(`Foo`, function () {})',
266+
options: [{ ignore: [DescribeAlias.describe] }],
267+
},
268+
{
269+
code: 'describe.skip(`Foo`, function () {})',
270+
options: [{ ignore: [DescribeAlias.describe] }],
271+
},
228272
],
229273
invalid: [],
230274
});
@@ -243,6 +287,14 @@ ruleTester.run('lowercase-name with ignore=test', rule, {
243287
code: 'test(`Foo`, function () {})',
244288
options: [{ ignore: [TestCaseName.test] }],
245289
},
290+
{
291+
code: 'xtest(`Foo`, function () {})',
292+
options: [{ ignore: [TestCaseName.test] }],
293+
},
294+
{
295+
code: 'test.only(`Foo`, function () {})',
296+
options: [{ ignore: [TestCaseName.test] }],
297+
},
246298
],
247299
invalid: [],
248300
});
@@ -261,6 +313,14 @@ ruleTester.run('lowercase-name with ignore=it', rule, {
261313
code: 'it(`Foo`, function () {})',
262314
options: [{ ignore: [TestCaseName.it] }],
263315
},
316+
{
317+
code: 'fit(`Foo`, function () {})',
318+
options: [{ ignore: [TestCaseName.it] }],
319+
},
320+
{
321+
code: 'it.skip(`Foo`, function () {})',
322+
options: [{ ignore: [TestCaseName.it] }],
323+
},
264324
],
265325
invalid: [],
266326
});

src/rules/lowercase-name.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ const findNodeNameAndArgument = (
3636
return [getNodeName(node).split('.')[0], node.arguments[0]];
3737
};
3838

39+
const populateIgnores = (ignore: readonly string[]): string[] => {
40+
const ignores: string[] = [];
41+
42+
if (ignore.includes(DescribeAlias.describe)) {
43+
ignores.push(...Object.keys(DescribeAlias));
44+
}
45+
if (ignore.includes(TestCaseName.test)) {
46+
ignores.push(...Object.keys(TestCaseName));
47+
}
48+
if (ignore.includes(TestCaseName.it)) {
49+
ignores.push(...Object.keys(TestCaseName));
50+
}
51+
52+
return ignores;
53+
};
54+
3955
export default createRule<
4056
[
4157
Partial<{
@@ -94,6 +110,7 @@ export default createRule<
94110
context,
95111
[{ ignore = [], allowedPrefixes = [], ignoreTopLevelDescribe }],
96112
) {
113+
const ignores = populateIgnores(ignore);
97114
let numberOfDescribeBlocks = 0;
98115

99116
return {
@@ -125,7 +142,7 @@ export default createRule<
125142
if (
126143
!firstCharacter ||
127144
firstCharacter === firstCharacter.toLowerCase() ||
128-
ignore.includes(name as IgnorableFunctionExpressions)
145+
ignores.includes(name as IgnorableFunctionExpressions)
129146
) {
130147
return;
131148
}

0 commit comments

Comments
 (0)