├── jest.config.js ├── .eslintrc.js ├── .travis.yml ├── src ├── index.ts ├── no-heisei-in-literal.ts ├── no-heisei-in-variable-name.ts └── __tests__ │ ├── no-heisei-in-variable-name.test.ts │ └── no-heisei-in-literal.test.ts ├── tsconfig.json ├── .gitignore ├── LICENSE ├── package.json └── README.md /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { 3 | "^.+\\.ts$": "ts-jest" 4 | }, 5 | testRegex: "(src/.*\\.test)\\.ts$", 6 | testPathIgnorePatterns: ["/node_modules/", "\\.d\\.ts$", "lib/.*"], 7 | moduleFileExtensions: ["js", "ts", "json"] 8 | }; 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true 4 | }, 5 | extends: [ 6 | "eslint:recommended", 7 | "plugin:@typescript-eslint/recommended", 8 | "prettier", 9 | "prettier/@typescript-eslint" 10 | ], 11 | rules: { 12 | "arrow-body-style": ["error", "as-needed"], 13 | "@typescript-eslint/no-unused-vars": "error", 14 | "@typescript-eslint/prefer-interface": "off" 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "11" 5 | - "10" 6 | - "8" 7 | before_install: 8 | - "nvm install-latest-npm" 9 | before_script: 10 | - 'yarn add "eslint@${ESLINT}"' 11 | script: 12 | - "npm run test" 13 | env: 14 | matrix: 15 | - ESLINT=5 16 | - ESLINT=4 17 | matrix: 18 | fast_finish: true 19 | include: 20 | - node_js: "lts/*" 21 | allow_failures: 22 | - node_js: "11" 23 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { noHeiseiInLiteral } from "./no-heisei-in-literal"; 2 | import { noHeiseiInVariableName } from "./no-heisei-in-variable-name"; 3 | 4 | const allRules = { 5 | "no-heisei-in-literal": noHeiseiInLiteral, 6 | "no-heisei-in-variable-name": noHeiseiInVariableName 7 | }; 8 | 9 | module.exports = { 10 | rules: allRules, 11 | configs: { 12 | recommended: { 13 | plugins: ["reiwa"], 14 | rules: { 15 | "reiwa/no-heisei-in-literal": "error", 16 | "reiwa/no-heisei-in-variable-name": "error" 17 | } 18 | } 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "esnext", 4 | "target": "es2018", 5 | "lib": ["es2015", "dom"], 6 | "strict": true, 7 | "noEmit": true, 8 | "esModuleInterop": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "noEmitOnError": true, 11 | "noFallthroughCasesInSwitch": true, 12 | "noImplicitAny": true, 13 | "noImplicitReturns": true, 14 | "noImplicitThis": true, 15 | "noUnusedLocals": true, 16 | "noUnusedParameters": true, 17 | "strictNullChecks": true 18 | }, 19 | "include": ["src/**/*.ts"] 20 | } 21 | -------------------------------------------------------------------------------- /src/no-heisei-in-literal.ts: -------------------------------------------------------------------------------- 1 | import { Rule } from "eslint"; 2 | 3 | export const noHeiseiInLiteral: Rule.RuleModule = { 4 | meta: { 5 | docs: { 6 | category: "Lint", 7 | recommended: true 8 | }, 9 | schema: [] 10 | }, 11 | 12 | create: context => ({ 13 | Literal: node => { 14 | if (node.type !== "Literal" || typeof node.value !== "string") return; 15 | if (node.value.match(/平成|heisei/i)) { 16 | context.report({ 17 | node, 18 | message: 19 | "Do not use 'heisei' or '平成' in string literal, use 'reiwa' or '令和'" 20 | }); 21 | } 22 | } 23 | }) 24 | }; 25 | -------------------------------------------------------------------------------- /src/no-heisei-in-variable-name.ts: -------------------------------------------------------------------------------- 1 | import { Rule } from "eslint"; 2 | 3 | export const noHeiseiInVariableName: Rule.RuleModule = { 4 | meta: { 5 | docs: { 6 | category: "Lint", 7 | recommended: true 8 | }, 9 | schema: [] 10 | }, 11 | 12 | create: context => ({ 13 | VariableDeclarator: node => { 14 | if (node.type !== "VariableDeclarator") return; 15 | if (node.id.type !== "Identifier") return; 16 | if (node.id.name.match(/平成|heisei/i)) { 17 | context.report({ 18 | node, 19 | message: 20 | "Do not use 'heisei' or '平成' in variable name, use 'reiwa' or '令和'" 21 | }); 22 | } 23 | } 24 | }) 25 | }; 26 | -------------------------------------------------------------------------------- /src/__tests__/no-heisei-in-variable-name.test.ts: -------------------------------------------------------------------------------- 1 | import { noHeiseiInVariableName } from "../no-heisei-in-variable-name"; 2 | import { RuleTester } from "eslint"; 3 | 4 | const ruleTester = new RuleTester({ 5 | parser: "@typescript-eslint/parser" 6 | }); 7 | 8 | const message = 9 | "Do not use 'heisei' or '平成' in variable name, use 'reiwa' or '令和'"; 10 | 11 | ruleTester.run("no-heisei", noHeiseiInVariableName, { 12 | valid: [], 13 | invalid: [ 14 | { 15 | code: "const theBeginningOfHeisei = 1989", 16 | errors: [{ message }] 17 | }, 18 | { 19 | code: "let heisei;", 20 | errors: [{ message }] 21 | }, 22 | { 23 | code: "var 平成;", 24 | errors: [{ message }] 25 | } 26 | ] 27 | }); 28 | -------------------------------------------------------------------------------- /src/__tests__/no-heisei-in-literal.test.ts: -------------------------------------------------------------------------------- 1 | import { noHeiseiInLiteral } from "../no-heisei-in-literal"; 2 | import { RuleTester } from "eslint"; 3 | 4 | const ruleTester = new RuleTester({ 5 | parser: "@typescript-eslint/parser" 6 | }); 7 | 8 | const message = 9 | "Do not use 'heisei' or '平成' in string literal, use 'reiwa' or '令和'"; 10 | 11 | ruleTester.run("no-heisei", noHeiseiInLiteral, { 12 | valid: [], 13 | invalid: [ 14 | { 15 | code: "'heisei'", 16 | errors: [{ message }] 17 | }, 18 | { 19 | code: "'平成'", 20 | errors: [{ message }] 21 | }, 22 | { 23 | code: 24 | "'The end of Heisei is expected to be during the GW of 2019 this year.'", 25 | errors: [{ message }] 26 | }, 27 | { 28 | code: "'平成の終わりは今年2019年のGW中になる見込みです。'", 29 | errors: [{ message }] 30 | } 31 | ] 32 | }); 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Optional npm cache directory 40 | .npm 41 | 42 | # Optional eslint cache 43 | .eslintcache 44 | 45 | # Optional REPL history 46 | .node_repl_history 47 | 48 | # Output of 'npm pack' 49 | *.tgz 50 | 51 | # Yarn Integrity file 52 | .yarn-integrity 53 | 54 | # dotenv environment variables file 55 | .env 56 | 57 | # next.js build output 58 | .next 59 | 60 | # pkg 61 | pkg 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Hidemi Yukita 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-plugin-reiwa", 3 | "version": "0.0.5", 4 | "description": "ESLint rules to replace heisei with reiwa", 5 | "repository": "ssh://git@github.com/otofu-square/eslint-plugin-reiwa.git", 6 | "keywords": [ 7 | "eslint", 8 | "reiwa", 9 | "heisei" 10 | ], 11 | "author": "otofu-square ", 12 | "license": "MIT", 13 | "@pika/pack": { 14 | "pipeline": [ 15 | [ 16 | "@pika/plugin-standard-pkg" 17 | ], 18 | [ 19 | "@pika/plugin-build-node" 20 | ] 21 | ] 22 | }, 23 | "husky": { 24 | "hooks": { 25 | "pre-commit": "lint-staged" 26 | } 27 | }, 28 | "lint-staged": { 29 | "*.{js,json,md}": [ 30 | "prettier --write", 31 | "git add" 32 | ], 33 | "*.ts": [ 34 | "prettier --write", 35 | "eslint --fix", 36 | "git add" 37 | ] 38 | }, 39 | "scripts": { 40 | "build": "pack build", 41 | "eslint": "eslint --cache ./**/*.ts", 42 | "publish": "pack publish", 43 | "test": "jest", 44 | "tsc": "tsc --noEmit" 45 | }, 46 | "devDependencies": { 47 | "@pika/pack": "0.3.6", 48 | "@pika/plugin-build-node": "0.3.14", 49 | "@pika/plugin-standard-pkg": "0.4.0", 50 | "@types/eslint": "4.16.6", 51 | "@types/jest": "24.0.11", 52 | "@typescript-eslint/eslint-plugin": "1.5.0", 53 | "eslint": "5.15.3", 54 | "eslint-config-prettier": "4.1.0", 55 | "husky": "1.3.1", 56 | "jest": "24.8.0", 57 | "lint-staged": "8.1.5", 58 | "prettier": "1.16.4", 59 | "ts-jest": "24.0.0", 60 | "typescript": "3.4.1" 61 | }, 62 | "peerDependencies": { 63 | "eslint": "^4.0.0 || ^5.0.0" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

eslint-plugin-reiwa

2 | 3 |

4 | GitHub license 5 | NPM Version 6 | NPM Downloads 7 | build: 8 |

9 | 10 | ## What's this? 11 | 12 | This is the eslint plugin to replace 平成 with 令和 which is new era in Japan. 13 | 14 | ## Examples 15 | 16 | ### `reiwa/no-heisei-in-literal` 17 | 18 | ```js 19 | // incorrect 20 | let str = "heisei"; 21 | str = "平成"; 22 | str = "Heisei will ended during the GW of 2019 this year."; 23 | str = "平成の終わりは今年2019年のGW中になる見込みです。"; 24 | ``` 25 | 26 | ### `reiwa/no-heisei-in-variable-name` 27 | 28 | ```js 29 | // incorrect 30 | const theBeginningOfHeisei = 1989; 31 | let heisei; 32 | var 平成; 33 | ``` 34 | 35 | ## Getting started 36 | 37 | ### Install 38 | 39 | ```sh 40 | $ yarn add -D eslint-plugin-reiwa 41 | # or 42 | $ npm i -D eslint-plugin-reiwa 43 | ``` 44 | 45 | ### Edit `.eslintrc.js` 46 | 47 | ```js 48 | module.exports = { 49 | plugins: [ 50 | ... 51 | "reiwa", 52 | ... 53 | ], 54 | rules: { 55 | "reiwa/no-heisei-in-literal": "error", 56 | "reiwa/no-heisei-in-variable-name": "error", 57 | ... 58 | } 59 | } 60 | ``` 61 | 62 | or 63 | 64 | ```js 65 | module.exports = { 66 | extends: ["plugin:reiwa/recommended"] 67 | }; 68 | ``` 69 | 70 | ## LICENSE 71 | 72 | MIT 73 | --------------------------------------------------------------------------------