import { Rule } from 'eslint' ; import { TSESTree } from '@typescript-eslint/types' ; import { createDocsUrl } from '../../util/helpers' ; /**
 * List of discouraged words in the form of RegEx (regular expressions).
 */ const discouragedWords = [ 'blacklist' , 'whitelist' ] ; const rule = { meta : { docs : { category : 'Best Practices' , description : 'Prevent use of discouraged words.' , url : createDocsUrl ( 'best-practices/no-discouraged-words.md' ) , } , schema : [ ] , fixable : 'code' , type : 'suggestion' , } , create ( context ) { return { Program ( ) { const comments = context . getSourceCode ( ) . getAllComments ( ) ; comments . forEach ( comment => { const commentText = comment . value ; const commentTextViolation = discouragedWords . find ( word => commentText . match ( new RegExp ( word , 'i' ) ) ) ; if ( ! commentTextViolation ) { return ; } context . report ( { node : comment , message : `Usage of the word "${ commentTextViolation }" is strongly discouraged. Please use a different word.` , } ) ; } ) ; } , Identifier ( node ) { const variableName = node . name ; const variableNameViolation = discouragedWords . find ( word => variableName . match ( new RegExp ( word , 'i' ) ) ) ; if ( ! variableNameViolation ) { return ; } context . report ( { node , message : `Usage of the word "${ variableNameViolation }" is strongly discouraged. Please use a different word.` , } ) ; } , } as Rule . RuleListener ; } , } ; export default rule ;