Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate no-commented-out-tests
- Loading branch information
Showing
3 changed files
with
51 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { TSESTree } from '@typescript-eslint/experimental-utils'; | ||
import { createRule } from './tsUtils'; | ||
|
||
function hasTests(node: TSESTree.Comment) { | ||
return /^\s*(x|f)?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/m.test( | ||
node.value, | ||
); | ||
} | ||
|
||
export default createRule({ | ||
name: __filename, | ||
meta: { | ||
docs: { | ||
category: 'Best Practices', | ||
description: | ||
"This rule raises a warning about commented out tests. It's similar to no-disabled-tests rule.", | ||
recommended: false, | ||
}, | ||
messages: { | ||
commentedTests: 'Some tests seem to be commented', | ||
}, | ||
schema: [], | ||
type: 'suggestion', | ||
} as const, | ||
defaultOptions: [], | ||
create(context) { | ||
const sourceCode = context.getSourceCode(); | ||
|
||
function checkNode(node: TSESTree.Comment) { | ||
if (!hasTests(node)) { | ||
return; | ||
} | ||
|
||
context.report({ messageId: 'commentedTests', node }); | ||
} | ||
|
||
return { | ||
Program() { | ||
const comments = sourceCode.getAllComments(); | ||
|
||
comments.forEach(checkNode); | ||
}, | ||
}; | ||
}, | ||
}); |