@spotify/eslint-plugin
Version:
Set of rules for Spotify's custom ESLint rules
45 lines • 1.75 kB
JavaScript
import { createDocsUrl } from '../../util/helpers';
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.`,
});
},
};
},
};
export default rule;
//# sourceMappingURL=no-discouraged-words.js.map