eslint-plugin-censor
Version:
The plugin will prevent you from using swear pejoratives and abuse words
59 lines (46 loc) • 1.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.create = create;
exports.meta = void 0;
var _blackList = _interopRequireDefault(require("../words/blackList.json"));
var _whiteList = _interopRequireDefault(require("../words/whiteList.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function findInList(list, word) {
return list.find(w => Array.isArray(w) ? w.every(ww => word.includes(ww)) : word.includes(w));
}
function checkSwear(node, word, context) {
const sanitized = `${word}`.toLowerCase();
const isBad = findInList(_blackList.default, sanitized);
if (isBad) {
const justified = findInList(_whiteList.default, sanitized);
if (!justified) {
const match = Array.isArray(isBad) ? isBad.join('_') : isBad;
context.report({
node,
message: `${node.type} ${word} is considered as swear word [${match}]`
});
}
}
}
function create(context) {
return {
Identifier(node) {
checkSwear(node, node.name, context);
},
Literal(node) {
checkSwear(node, node.value, context);
}
};
}
const meta = {
type: 'suggestion',
docs: {
description: 'prevent from using pejoratives and abuse words',
category: 'Best Practices',
recommended: true
},
schema: [] // no options
};
exports.meta = meta;
;