From ecba100c558889eafe1d7b4cd590ea82f4703046 Mon Sep 17 00:00:00 2001 From: "domagoj.vukovic" Date: Fri, 28 Oct 2022 23:27:07 +0200 Subject: [PATCH] feat: match more todo comments --- src/rules/document-todos.ts | 16 +++- src/tests/tsx/rules/document-todos.test.ts | 89 +++++++++++++++------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/rules/document-todos.ts b/src/rules/document-todos.ts index b388b0a..8352c35 100644 --- a/src/rules/document-todos.ts +++ b/src/rules/document-todos.ts @@ -20,13 +20,25 @@ const value = createRule[], string>({ const isFixme = comment.value.includes('FIXME:') const hasLink = comment.value.includes(url.toLowerCase()) + const startsWithTodo = comment + .value + .trimStart() + .toLowerCase() + .startsWith('todo') + + const startsWithFixme = comment + .value + .trimStart() + .toLowerCase() + .startsWith('fixme') + // Valid todo/fixme comment - if ((isTodo || isFixme) && hasLink) { + if ((isTodo || isFixme || startsWithFixme || startsWithTodo) && hasLink) { continue } // Regular comment - if (!isTodo && !isFixme) { + if (!isTodo && !isFixme && !startsWithFixme && !startsWithTodo) { continue } diff --git a/src/tests/tsx/rules/document-todos.test.ts b/src/tests/tsx/rules/document-todos.test.ts index c0d7610..b4fe7d6 100644 --- a/src/tests/tsx/rules/document-todos.test.ts +++ b/src/tests/tsx/rules/document-todos.test.ts @@ -16,6 +16,48 @@ const options: OptionType[] = [{ jsxRuleTester.run[]>(rule.name, rule.value, { invalid: [ + { + code: dedent` + //todo something is wrong + const hello = 1 + `, + options, + filename: TSX_FILE_PATH, + errors: [ + { + line: 1, + messageId: 'default', + }, + ], + }, + { + code: dedent` + // todo something is wrong + const hello = 1 + `, + options, + filename: TSX_FILE_PATH, + errors: [ + { + line: 1, + messageId: 'default', + }, + ], + }, + { + code: dedent` + // todo: something is wrong + const hello = 1 + `, + options, + filename: TSX_FILE_PATH, + errors: [ + { + line: 1, + messageId: 'default', + }, + ], + }, { code: dedent` // FIXME: I'm not documented @@ -183,16 +225,7 @@ jsxRuleTester.run[]>(rule.name, rule.value, { * What is happening * Who am I? */ - return ( -
- {/* JSX dude */} -

Hello

-
- ) + return 1 } `, options, @@ -201,16 +234,7 @@ jsxRuleTester.run[]>(rule.name, rule.value, { { code: dedent` // TODO: something is wrong https://rimac-automobili.atlassian.net/jira/software/c/projects/QIA/5887 - const Component = () => { - return ( -
-

Hello

-
- ) - } + const Component = 1 `, options, filename: TSX_FILE_PATH, @@ -256,18 +280,27 @@ jsxRuleTester.run[]>(rule.name, rule.value, { * What is happening * TODO: something is wrong https://rimac-automobili.atlassian.net/jira/QIA/5887j */ - return ( -
-

Hello

-
- ) + const hello = 1 } `, options, filename: TSX_FILE_PATH, }, + { + code: dedent` + // todo: something is wrong https://rimac-automobili.atlassian.net/jira/QIA/5887j' + const hello = 1 + `, + options, + filename: TSX_FILE_PATH, + }, + { + code: dedent` + //todo something is wrong https://rimac-automobili.atlassian.net/jira/QIA/5887j' + const hello = 1 + `, + options, + filename: TSX_FILE_PATH, + }, ], })