Skip to content

Commit 781b27a

Browse files
committed
feat(rule): allow ignoring test.todo Jest functions for prefer-lowercase-title rule
Signed-off-by: hainenber <[email protected]>
1 parent 2557a20 commit 781b27a

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

docs/rules/prefer-lowercase-title.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ describe('MyClass', () => {
109109
});
110110
});
111111
```
112+
113+
### `ignoreTodos`
114+
115+
This option is used to control whether
116+
[`todo`](https://jestjs.io/docs/api#testtodoname) Jest functions to be checked
117+
by this rule. By the default, the option is set to false.
118+
119+
Example of **correct** code for the `{ "ignoreTodos": true }` option:
120+
121+
```js
122+
/* eslint jest/prefer-lowercase-title: ["error", { "ignoreTodos": true }] */
123+
test.todo('Uppercase description');
124+
125+
it.todo('Uppercase description');
126+
```

src/rules/__tests__/prefer-lowercase-title.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,57 @@ ruleTester.run('prefer-lowercase-title with ignoreTopLevelDescribe', rule, {
646646
},
647647
],
648648
});
649+
650+
ruleTester.run('prefer-lowercase-title with ignoreTodos', rule, {
651+
valid: [
652+
{
653+
code: 'test.todo(`Foo`, function () {})',
654+
options: [{ ignoreTodos: true }],
655+
},
656+
{
657+
code: 'it.todo(`Foo`, function () {})',
658+
options: [{ ignoreTodos: true }],
659+
},
660+
],
661+
invalid: [
662+
{
663+
code: "describe('Foo', function () {})",
664+
output: "describe('foo', function () {})",
665+
options: [{ ignoreTodos: true }],
666+
errors: [
667+
{
668+
messageId: 'unexpectedCase',
669+
data: { method: DescribeAlias.describe },
670+
column: 10,
671+
line: 1,
672+
},
673+
],
674+
},
675+
{
676+
code: "it('Foo', function () {})",
677+
output: "it('foo', function () {})",
678+
options: [{ ignoreTodos: true }],
679+
errors: [
680+
{
681+
messageId: 'unexpectedCase',
682+
data: { method: TestCaseName.it },
683+
column: 4,
684+
line: 1,
685+
},
686+
],
687+
},
688+
{
689+
code: "test('Foo', function () {})",
690+
output: "test('foo', function () {})",
691+
options: [{ ignore: [TestCaseName.it] }],
692+
errors: [
693+
{
694+
messageId: 'unexpectedCase',
695+
data: { method: TestCaseName.test },
696+
column: 6,
697+
line: 1,
698+
},
699+
],
700+
},
701+
],
702+
});

src/rules/prefer-lowercase-title.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type StringNode,
66
TestCaseName,
77
createRule,
8+
getAccessorValue,
89
getStringValue,
910
isStringNode,
1011
isTypeOfJestFnCall,
@@ -47,6 +48,7 @@ export default createRule<
4748
ignore: readonly IgnorableFunctionExpressions[];
4849
allowedPrefixes: readonly string[];
4950
ignoreTopLevelDescribe: boolean;
51+
ignoreTodos: boolean;
5052
}>,
5153
],
5254
'unexpectedCase'
@@ -88,17 +90,33 @@ export default createRule<
8890
type: 'boolean',
8991
default: false,
9092
},
93+
ignoreTodos: {
94+
type: 'boolean',
95+
default: false,
96+
},
9197
},
9298
additionalProperties: false,
9399
},
94100
],
95101
},
96102
defaultOptions: [
97-
{ ignore: [], allowedPrefixes: [], ignoreTopLevelDescribe: false },
103+
{
104+
ignore: [],
105+
allowedPrefixes: [],
106+
ignoreTopLevelDescribe: false,
107+
ignoreTodos: false,
108+
},
98109
],
99110
create(
100111
context,
101-
[{ ignore = [], allowedPrefixes = [], ignoreTopLevelDescribe }],
112+
[
113+
{
114+
ignore = [],
115+
allowedPrefixes = [],
116+
ignoreTopLevelDescribe,
117+
ignoreTodos,
118+
},
119+
],
102120
) {
103121
const ignores = populateIgnores(ignore);
104122
let numberOfDescribeBlocks = 0;
@@ -121,6 +139,15 @@ export default createRule<
121139
return;
122140
}
123141

142+
// Ignore *.todo test and/or test suites
143+
if (
144+
ignoreTodos &&
145+
(jestFnCall.name.startsWith('x') ||
146+
jestFnCall.members.some(s => getAccessorValue(s) === 'todo'))
147+
) {
148+
return;
149+
}
150+
124151
const [firstArg] = node.arguments;
125152

126153
const description = getStringValue(firstArg);

0 commit comments

Comments
 (0)