Skip to content

Commit

Permalink
feat: match more todo comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vuki656 committed Oct 28, 2022
1 parent 50a1b52 commit ecba100
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
16 changes: 14 additions & 2 deletions src/rules/document-todos.ts
Expand Up @@ -20,13 +20,25 @@ const value = createRule<Record<string, string>[], 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
}

Expand Down
89 changes: 61 additions & 28 deletions src/tests/tsx/rules/document-todos.test.ts
Expand Up @@ -16,6 +16,48 @@ const options: OptionType[] = [{

jsxRuleTester.run<string, Record<string, string>[]>(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
Expand Down Expand Up @@ -183,16 +225,7 @@ jsxRuleTester.run<string, Record<string, string>[]>(rule.name, rule.value, {
* What is happening
* Who am I?
*/
return (
<div
props={true}
// Prop dude
style={{ height: '50px' }}
>
{/* JSX dude */}
<p>Hello</p>
</div>
)
return 1
}
`,
options,
Expand All @@ -201,16 +234,7 @@ jsxRuleTester.run<string, Record<string, string>[]>(rule.name, rule.value, {
{
code: dedent`
// TODO: something is wrong https://rimac-automobili.atlassian.net/jira/software/c/projects/QIA/5887
const Component = () => {
return (
<div
props={true}
style={{ height: '50px' }}
>
<p>Hello</p>
</div>
)
}
const Component = 1
`,
options,
filename: TSX_FILE_PATH,
Expand Down Expand Up @@ -256,18 +280,27 @@ jsxRuleTester.run<string, Record<string, string>[]>(rule.name, rule.value, {
* What is happening
* TODO: something is wrong https://rimac-automobili.atlassian.net/jira/QIA/5887j
*/
return (
<div
props={true}
style={{ height: '50px' }}
>
<p>Hello</p>
</div>
)
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,
},
],
})

0 comments on commit ecba100

Please sign in to comment.