UNPKG

@spotify/eslint-plugin

Version:
47 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../../util/helpers"); const discouragedWords = ['blacklist', 'whitelist']; const rule = { meta: { docs: { category: 'Best Practices', description: 'Prevent use of discouraged words.', url: (0, helpers_1.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.`, }); }, }; }, }; exports.default = rule; //# sourceMappingURL=no-discouraged-words.js.map