eslint-plugin-ban-unko
Advanced tools
| 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" | ||
| } | ||
| } |
+26
-78
@@ -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; | ||
| } |
-32
| "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, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
3422
-15.51%4
33.33%87
-30.95%