|
| 1 | +/* |
| 2 | + * eslint-plugin-sonarjs |
| 3 | + * Copyright (C) 2018 SonarSource SA |
| 4 | + * mailto:info AT sonarsource DOT com |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 3 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + */ |
| 20 | +import * as fs from "fs"; |
| 21 | + |
| 22 | +const outputPath = process.argv[2]; |
| 23 | + |
| 24 | +const meta = []; |
| 25 | + |
| 26 | +const readmeContent = fs.readFileSync("README.md", "utf-8"); |
| 27 | + |
| 28 | +const lines = readmeContent.split(/\n/); |
| 29 | +let state: "before-bug" | "bug" | "between" | "code-smell" = "before-bug"; |
| 30 | +for (const line of lines) { |
| 31 | + if (state === "before-bug" && line.startsWith("*")) { |
| 32 | + state = "bug"; |
| 33 | + } |
| 34 | + |
| 35 | + if (state === "bug") { |
| 36 | + if (line.startsWith("*")) { |
| 37 | + addRule(line, "BUG"); |
| 38 | + } else { |
| 39 | + state = "between"; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + if (state === "between" && line.startsWith("*")) { |
| 44 | + state = "code-smell"; |
| 45 | + } |
| 46 | + |
| 47 | + if (state === "code-smell") { |
| 48 | + if (line.startsWith("*")) { |
| 49 | + addRule(line, "CODE_SMELL"); |
| 50 | + } else { |
| 51 | + break; |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +function addRule(line: string, type: string) { |
| 57 | + const name = line |
| 58 | + .substr(2) |
| 59 | + .split("([")[0] |
| 60 | + .trim(); |
| 61 | + const key = "sonarjs/" + line.split("`")[1].trim(); |
| 62 | + |
| 63 | + meta.push({ |
| 64 | + key, |
| 65 | + name, |
| 66 | + type, |
| 67 | + description: `See description of ESLint rule <code>sonarjs/${key}</code> at the <a href="https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/${key}.md">eslint-plugin-sonarjs website</a>.`, |
| 68 | + }); |
| 69 | +} |
| 70 | + |
| 71 | +fs.writeFileSync(outputPath, JSON.stringify(meta)); |
0 commit comments