diff --git a/docs/rules/valid-title.md b/docs/rules/valid-title.md index ba29e2391..e0bfe2a21 100644 --- a/docs/rules/valid-title.md +++ b/docs/rules/valid-title.md @@ -125,7 +125,8 @@ describe('foo', () => { **accidentalSpace** -A `describe` / `test` block should not contain accidentalSpace +A `describe` / `test` block should not contain accidentalSpace, but can be +turned off via the `ignoreSpaces` option: Examples of **incorrect** code for this rule @@ -161,6 +162,7 @@ describe('foo', () => { ```ts interface Options { + ignoreSpaces?: boolean; ignoreTypeOfDescribeName?: boolean; disallowedWords?: string[]; mustNotMatch?: Partial> | string; @@ -168,6 +170,12 @@ interface Options { } ``` +#### `ignoreSpaces` + +Default: `false` + +When enabled, the leading and trailing spaces won't be checked. + #### `ignoreTypeOfDescribeName` Default: `false` diff --git a/src/rules/__tests__/valid-title.test.ts b/src/rules/__tests__/valid-title.test.ts index 038f325c8..976413356 100644 --- a/src/rules/__tests__/valid-title.test.ts +++ b/src/rules/__tests__/valid-title.test.ts @@ -848,6 +848,10 @@ ruleTester.run('no-accidental-space', rule, { it('bar', () => {}) }) `, + { + code: 'it(`GIVEN... \n `, () => {});', + options: [{ ignoreSpaces: true }], + }, ], invalid: [ { diff --git a/src/rules/valid-title.ts b/src/rules/valid-title.ts index 65587be58..302a8a226 100644 --- a/src/rules/valid-title.ts +++ b/src/rules/valid-title.ts @@ -85,6 +85,7 @@ const MatcherAndMessageSchema: JSONSchema.JSONSchema7 = { type MatcherGroups = 'describe' | 'test' | 'it'; interface Options { + ignoreSpaces?: boolean; ignoreTypeOfDescribeName?: boolean; disallowedWords?: string[]; mustNotMatch?: @@ -132,6 +133,10 @@ export default createRule<[Options], MessageIds>({ { type: 'object', properties: { + ignoreSpaces: { + type: 'boolean', + default: false, + }, ignoreTypeOfDescribeName: { type: 'boolean', default: false, @@ -161,11 +166,18 @@ export default createRule<[Options], MessageIds>({ ], fixable: 'code', }, - defaultOptions: [{ ignoreTypeOfDescribeName: false, disallowedWords: [] }], + defaultOptions: [ + { + ignoreSpaces: false, + ignoreTypeOfDescribeName: false, + disallowedWords: [], + }, + ], create( context, [ { + ignoreSpaces, ignoreTypeOfDescribeName, disallowedWords = [], mustNotMatch, @@ -247,7 +259,7 @@ export default createRule<[Options], MessageIds>({ } } - if (title.trim().length !== title.length) { + if (ignoreSpaces === false && title.trim().length !== title.length) { context.report({ messageId: 'accidentalSpace', node: argument,