|
| 1 | +/** |
| 2 | + * @author Toru Nagashima <https://github.com/mysticatea> |
| 3 | + * See LICENSE file in root directory for full license. |
| 4 | + */ |
| 5 | +"use strict" |
| 6 | + |
| 7 | +const cp = require("child_process") |
| 8 | +const fs = require("fs") |
| 9 | +const path = require("path") |
| 10 | +const logger = console |
| 11 | + |
| 12 | +// main |
| 13 | +;(ruleId => { |
| 14 | + if (ruleId == null) { |
| 15 | + logger.error("Usage: npm run new <RuleID>") |
| 16 | + process.exitCode = 1 |
| 17 | + return |
| 18 | + } |
| 19 | + if (!/^[\w-]+$/u.test(ruleId)) { |
| 20 | + logger.error("Invalid RuleID '%s'.", ruleId) |
| 21 | + process.exitCode = 1 |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + const ruleFile = path.resolve(__dirname, `../lib/rules/${ruleId}.js`) |
| 26 | + const testFile = path.resolve(__dirname, `../tests/lib/rules/${ruleId}.js`) |
| 27 | + const docFile = path.resolve(__dirname, `../docs/rules/${ruleId}.md`) |
| 28 | + |
| 29 | + fs.writeFileSync( |
| 30 | + ruleFile, |
| 31 | + `/** |
| 32 | + * @author Toru Nagashima <https://github.com/mysticatea> |
| 33 | + * See LICENSE file in root directory for full license. |
| 34 | + */ |
| 35 | +"use strict" |
| 36 | +
|
| 37 | +module.exports = { |
| 38 | + meta: { |
| 39 | + docs: { |
| 40 | + description: "", |
| 41 | + category: "", |
| 42 | + recommended: false, |
| 43 | + url: "", |
| 44 | + }, |
| 45 | + fixable: null, |
| 46 | + messages: { |
| 47 | + }, |
| 48 | + schema: [], |
| 49 | + type: "problem", |
| 50 | + }, |
| 51 | + create(context) { |
| 52 | + return {} |
| 53 | + }, |
| 54 | +} |
| 55 | +` |
| 56 | + ) |
| 57 | + fs.writeFileSync( |
| 58 | + testFile, |
| 59 | + `/** |
| 60 | + * @author Toru Nagashima <https://github.com/mysticatea> |
| 61 | + * See LICENSE file in root directory for full license. |
| 62 | + */ |
| 63 | +"use strict" |
| 64 | +const { RuleTester } = require("eslint") |
| 65 | +const rule = require("../../../lib/rules/${ruleId}.js") |
| 66 | +
|
| 67 | +new RuleTester().run("${ruleId}", rule, { |
| 68 | + valid: [], |
| 69 | + invalid: [], |
| 70 | +}) |
| 71 | +` |
| 72 | + ) |
| 73 | + fs.writeFileSync( |
| 74 | + docFile, |
| 75 | + `# (es/${ruleId}) |
| 76 | +
|
| 77 | +(TODO: Why this rule is useful.) |
| 78 | +
|
| 79 | +## 📖 Rule Details |
| 80 | +
|
| 81 | +(TODO: How this rule will report code.) |
| 82 | +
|
| 83 | +👍 Examples of **correct** code for this rule: |
| 84 | +
|
| 85 | +\`\`\`js |
| 86 | +/*eslint node/${ruleId}: error */ |
| 87 | +\`\`\` |
| 88 | +
|
| 89 | +👎 Examples of **incorrect** code for this rule: |
| 90 | +
|
| 91 | +\`\`\`js |
| 92 | +/*eslint node/${ruleId}: error */ |
| 93 | +\`\`\` |
| 94 | +
|
| 95 | +## ⚙ Options |
| 96 | +
|
| 97 | +\`\`\`json |
| 98 | +{ |
| 99 | + "node/${ruleId}": ["error", ...] |
| 100 | +} |
| 101 | +\`\`\` |
| 102 | +` |
| 103 | + ) |
| 104 | + |
| 105 | + cp.execSync(`code "${ruleFile}"`) |
| 106 | + cp.execSync(`code "${testFile}"`) |
| 107 | + cp.execSync(`code "${docFile}"`) |
| 108 | +})(process.argv[2]) |
0 commit comments