Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More β†’
Socket
Book a DemoSign in
Socket

eslint-plugin-ban-unko

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-ban-unko - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+46
lib/rules/no-unko.js
const isOffensive = (text) =>
typeof text === "string" &&
/πŸ’©|うんこ|ウンコ|ウンコ|unko|poop|feces/.test(text.toLowerCase());
const reportWith = (message) => (context, node) =>
context.report(node, message);
const Rule = {
meta: {
docs: {
description: "Disallow use of offensive language",
category: "Best Practices",
recommended: true,
},
schema: [],
messages: {
noUnko: "",
},
},
create(context) {
const message = "The use of strings similar to πŸ’© is prohibited.";
const report = reportWith(message);
return {
Literal(node) {
isOffensive(node.value) && report(context, node);
},
Identifier(node) {
isOffensive(node.name) && report(context, node);
},
TemplateElement(node) {
isOffensive(node.value.raw) && report(context, node);
},
Program(node) {
node.comments
.filter((c) => c.type !== "Shebang")
.forEach((c) => {
isOffensive(c.value) && report(context, c);
});
},
};
},
};
module.exports.rules = {
"no-unko": Rule,
};
+4
-3
{
"name": "eslint-plugin-ban-unko",
"version": "0.0.2",
"version": "0.0.3",
"description": "πŸš«πŸ’©",
"main": "lib/index.js",
"scripts": {
"test": "eslint tests/*.test.js"
"test": "jest"
},

@@ -20,4 +20,5 @@ "keywords": [

"@babel/eslint-parser": "^7.21.3",
"eslint": "^8.36.0"
"eslint": "^8.36.0",
"jest": "^29.5.0"
}
}

@@ -1,82 +0,30 @@

"use strict";
const { RuleTester } = require("eslint");
const plugin = require("../lib");
const rule = require("../lib/rules/no-unko").rules["no-unko"];
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2021
}
const ruleTester = new RuleTester();
ruleTester.run("no-unko", rule, {
valid: ['"hello"', '"HELLO"', "console.log(123)", { code: "var hoge = 1" }],
invalid: [
invalid('"πŸ’©"'),
invalid('"うんこ"'),
invalid('"ウンコ"'),
invalid('"ウンコ"'),
invalid('"unko"'),
invalid('"poop"'),
invalid('"feces"'),
invalid('var foo = "unko"'),
invalid('var unko = "foo"'),
invalid("function unko() {}"),
],
});
ruleTester.run("no-unko", plugin.rules["no-unko"], {
valid: [
'const helloWorld = "Hello World";',
'const noUnko = "noUnko";'
],
invalid: [
{
code: 'const unko = "πŸ’©";',
errors: [
{
message: "The word 'πŸ’©' is banned",
type: "Literal"
}
]
},
{
code: 'const message = "I stepped on unko";',
errors: [
{
message: "The word 'unko' is banned",
type: "Literal"
}
]
},
{
code: "const message = `I saw a pile of うんこ yesterday`;",
errors: [
{
message: "The word 'うんこ' is banned",
type: "TemplateElement"
}
]
},
{
code: "const message = `I smelled ウンコ on the street`;",
errors: [
{
message: "The word 'ウンコ' is banned",
type: "TemplateElement"
}
]
},
{
code: "const message = `My dog rolled in ウンコ at the park`;",
errors: [
{
message: "The word 'ウンコ' is banned",
type: "TemplateElement"
}
]
},
{
code: "const message = `The poop emoji is my favorite emoji`;",
errors: [
{
message: "The word 'poop' is banned",
type: "TemplateElement"
}
]
},
{
code: 'const message = `I prefer to use the word "feces" instead of "unko"`;',
errors: [
{
message: "The word 'feces' is banned",
type: "TemplateElement"
}
]
}
]
});
function invalid(code, output) {
const invalidTest = {
code,
errors: [{ message: "The use of strings similar to πŸ’© is prohibited." }],
};
if (output) {
invalidTest.output = output;
}
return invalidTest;
}
"use strict";
module.exports = {
rules: {
"no-unko": {
meta: {
type: "problem",
docs: {
description: "ban πŸ’©, うんこ, ウンコ, ウンコ, unko, poop, feces",
category: "Possible Errors",
recommended: true,
},
schema: [],
},
create: function (context) {
return {
Identifier(node) {
const { name } = node;
const options = context.options[0] || {};
const message = options.message || `${name} は禁歒ワードです。`;
if (/[うウ][んン][こコ][πŸ’©]/u.test(name)) {
context.report({
node,
message,
});
}
},
};
},
},
},
};