Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/rules/prefer-lowercase-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,18 @@ describe('MyClass', () => {
});
});
```

### `ignoreTodos`

This option is used to control whether
[`todo`](https://jestjs.io/docs/api#testtodoname) Jest functions to be checked
by this rule. By the default, the option is set to false.

Example of **correct** code for the `{ "ignoreTodos": true }` option:

```js
/* eslint jest/prefer-lowercase-title: ["error", { "ignoreTodos": true }] */
test.todo('Uppercase description');

it.todo('Uppercase description');
```
92 changes: 92 additions & 0 deletions src/rules/__tests__/prefer-lowercase-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,95 @@ ruleTester.run('prefer-lowercase-title with ignoreTopLevelDescribe', rule, {
},
],
});

ruleTester.run('prefer-lowercase-title with ignoreTodos', rule, {
valid: [
{
code: 'test.todo(`Foo`, function () {})',
options: [{ ignoreTodos: true }],
},
{
code: 'it.todo(`Foo`, function () {})',
options: [{ ignoreTodos: true }],
},
{
code: 'it.todo("Foo", () => {})',
options: [{ ignoreTodos: true }],
},
{
code: 'it.only.todo("Foo", () => {})',
options: [{ ignoreTodos: true }],
},
{
code: 'it.todo.only("Foo", () => {})',
options: [{ ignoreTodos: true }],
},
],
invalid: [
{
code: "describe('Foo', function () {})",
output: "describe('foo', function () {})",
options: [{ ignoreTodos: true }],
errors: [
{
messageId: 'unexpectedCase',
data: { method: DescribeAlias.describe },
column: 10,
line: 1,
},
],
},
{
code: "it('Foo', function () {})",
output: "it('foo', function () {})",
options: [{ ignoreTodos: true }],
errors: [

This comment was marked as spam.

{
messageId: 'unexpectedCase',
data: { method: TestCaseName.it },
column: 4,
line: 1,
},
],
},
{
code: "test('Foo', function () {})",
output: "test('foo', function () {})",
options: [{ ignoreTodos: true }],
errors: [
{
messageId: 'unexpectedCase',
data: { method: TestCaseName.test },
column: 6,
line: 1,
},
],
},
{
code: "test.only('Foo', function () {})",
output: "test.only('foo', function () {})",
options: [{ ignoreTodos: true }],
errors: [
{
messageId: 'unexpectedCase',
data: { method: TestCaseName.test },
column: 11,
line: 1,
},
],
},
{
code: "test.skip('Foo', function () {})",
output: "test.skip('foo', function () {})",
options: [{ ignoreTodos: true }],
errors: [
{
messageId: 'unexpectedCase',
data: { method: TestCaseName.test },
column: 11,
line: 1,
},
],
},
],
});
30 changes: 28 additions & 2 deletions src/rules/prefer-lowercase-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type StringNode,
TestCaseName,
createRule,
getAccessorValue,
getStringValue,
isStringNode,
isTypeOfJestFnCall,

This comment was marked as spam.

Expand Down Expand Up @@ -47,6 +48,7 @@ export default createRule<
ignore: readonly IgnorableFunctionExpressions[];
allowedPrefixes: readonly string[];
ignoreTopLevelDescribe: boolean;
ignoreTodos: boolean;
}>,
],
'unexpectedCase'
Expand Down Expand Up @@ -88,17 +90,33 @@ export default createRule<
type: 'boolean',
default: false,
},
ignoreTodos: {
type: 'boolean',
default: false,
},
},
additionalProperties: false,
},
],
},
defaultOptions: [
{ ignore: [], allowedPrefixes: [], ignoreTopLevelDescribe: false },
{
ignore: [],
allowedPrefixes: [],
ignoreTopLevelDescribe: false,
ignoreTodos: false,
},

This comment was marked as spam.

],
create(
context,
[{ ignore = [], allowedPrefixes = [], ignoreTopLevelDescribe }],
[
{
ignore = [],
allowedPrefixes = [],
ignoreTopLevelDescribe,
ignoreTodos,
},
],
) {
const ignores = populateIgnores(ignore);
let numberOfDescribeBlocks = 0;
Expand All @@ -121,6 +139,14 @@ export default createRule<
return;
}

// Ignore *.todo test and/or test suites
if (
ignoreTodos &&
jestFnCall.members.some(s => getAccessorValue(s) === 'todo')
) {
return;
}

const [firstArg] = node.arguments;

const description = getStringValue(firstArg);
Expand Down
Loading