Skip to content

Commit

Permalink
feat: working document todo rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vuki656 committed Jul 12, 2022
1 parent a34a713 commit 8d8dfea
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/rules/document-todos.ts
@@ -0,0 +1,48 @@
import { TSESTree } from '@typescript-eslint/types'

import { createRule } from '../utils'

const NAME = 'import-declaration-newline'

// TODO: make schema
const value = createRule({
create(context) {
return {
Program() {
const sourceCode = context.getSourceCode()
const comments = sourceCode.getAllComments()

comments.forEach((comment) => {
if (comment.value.includes(context.settings.url as string)) {
return
}

context.report({
messageId: 'default',
loc: comment.loc,
})
})
},
}
},
defaultOptions: [],
meta: {
docs: {
description: 'Ensure all TODOs and FIXMEs have an issue link attached to them',
recommended: false,
requiresTypeChecking: false,
},
messages: {
default: 'All TODOs and FIXMEs have an issue link attached to them',
},
schema: [],
type: 'problem',
},
name: NAME,
})

export default {
name: NAME,
value,
}

Empty file added src/tests-jsx/fixtures/file.tsx
Empty file.
48 changes: 48 additions & 0 deletions src/tests-jsx/rules/document-todos.test.ts
@@ -0,0 +1,48 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */

import rule from '../../rules/document-todos'
import {
ruleTester,
TSX_FILE_PATH,
} from '../utils'

ruleTester.run(rule.name, rule.value, {
invalid: [
{
code: `
// TODO: comment above the function https://rimac-automobili.atlassian.net/jira/software/c/projects/QIA/boards/34/backlog?view=detail&selectedIssue=QIA-965&epics=visible&issueLimit=100
const Component = () => {
/**
* This is a comment block
* TODO: and this is his todo https://rimac-automobili.atlassian.net/jira/software/c/projects/QIA/boards/34/backlog?view=detail&selectedIssue=QIA-965&epics=visible&issueLimit=100
*/
const router = useRouter()
// FIXME: comment above the return
return (
<div
props={true}
// TODO: and this is his todo https://rimac-automobili.atlassian.net/jira/software/c/projects/QIA/boards/34/backlog?view=detail&selectedIssue=QIA-965&epics=visible&issueLimit=100
style={{ height: '50px' }}
>
{/* TODO: this is a different jsx comment */}
<p>Hello</p>
</div>
)
}
`,
filename: TSX_FILE_PATH,
settings: {
url: 'https://rimac-automobili.atlassian.net/jira/software/c/projects/'
},
errors: [
{
column: 1,
line: 2,
messageId: 'default',
},
],
}
],
valid: [],
})
19 changes: 19 additions & 0 deletions src/tests-jsx/tsconfig.json
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"jsx": "preserve",
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"types": [],
"lib": [
"es2015",
"es2017",
"esnext"
],
"experimentalDecorators": true
},
"include": [
"./fixtures/file.tsx"
]
}
1 change: 1 addition & 0 deletions src/tests-jsx/utils/constants.ts
@@ -0,0 +1 @@
export const TSX_FILE_PATH = './fixtures/file.tsx'
2 changes: 2 additions & 0 deletions src/tests-jsx/utils/index.ts
@@ -0,0 +1,2 @@
export * from './constants'
export * from './ruleTester'
15 changes: 15 additions & 0 deletions src/tests-jsx/utils/ruleTester.ts
@@ -0,0 +1,15 @@
import * as path from 'path'

import { ESLintUtils } from '@typescript-eslint/utils'

export const ruleTester = new ESLintUtils.RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2015,
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.json',
tsconfigRootDir: path.resolve(__dirname, '..'),
},
})
2 changes: 1 addition & 1 deletion src/tests/tsconfig.json
Expand Up @@ -14,6 +14,6 @@
"experimentalDecorators": true
},
"include": [
"fixtures"
"fixtures/file.ts"
]
}

0 comments on commit 8d8dfea

Please sign in to comment.