|
| 1 | +const { InlineTokenChildren } = require("./common/inlineTokenChildren"); |
| 2 | +const { WordPattern } = require("./common/wordPattern"); |
| 3 | + |
| 4 | +const keywords = [ |
| 5 | + new WordPattern("iExtractor-manager"), |
| 6 | + new WordPattern("device-info"), |
| 7 | + new WordPattern("device-name"), |
| 8 | + new WordPattern("list_apps"), |
| 9 | + new WordPattern("decrypt_kcache"), |
| 10 | + new WordPattern("decrypt_fs"), |
| 11 | + new WordPattern("curl"), |
| 12 | + new WordPattern("wget"), |
| 13 | + new WordPattern("crontab"), |
| 14 | + new WordPattern("cron"), |
| 15 | + new WordPattern("netcat"), |
| 16 | + new WordPattern("ping"), |
| 17 | + new WordPattern("traceroute"), |
| 18 | + new WordPattern("sudo"), |
| 19 | + new WordPattern("(?<!(system |ISRG ))root(?! ca)", { suggestion: "root" }),// match "root", but not "root CA", "MacOS System Root" and "ISRG Root X1" |
| 20 | + new WordPattern("true"), |
| 21 | + new WordPattern("false"), |
| 22 | + new WordPattern("jps"), |
| 23 | + new WordPattern("name=value"), |
| 24 | + new WordPattern("key=value"), |
| 25 | + new WordPattern("time:value"), |
| 26 | + new WordPattern("atsd.log"), |
| 27 | + new WordPattern("start.log"), |
| 28 | + new WordPattern("logback.xml"), |
| 29 | + new WordPattern("graphite.conf"), |
| 30 | + new WordPattern("command_malformed.log"), |
| 31 | + new WordPattern("stdout"), |
| 32 | + new WordPattern("stderr"), |
| 33 | + new WordPattern("SIGTERM"), |
| 34 | + new WordPattern("NaN"), |
| 35 | + new WordPattern(".png", { noWordBoundary: true }), |
| 36 | + new WordPattern(".xml", { noWordBoundary: true }), |
| 37 | + new WordPattern(".jar", { noWordBoundary: true }), |
| 38 | + new WordPattern(".gz", { noWordBoundary: true }), |
| 39 | + new WordPattern(".tar.gz", { noWordBoundary: true }), |
| 40 | + new WordPattern(".zip", { noWordBoundary: true }), |
| 41 | + new WordPattern(".txt", { noWordBoundary: true }), |
| 42 | + new WordPattern(".csv", { noWordBoundary: true }), |
| 43 | + new WordPattern(".json", { noWordBoundary: true }), |
| 44 | + new WordPattern(".pdf", { noWordBoundary: true }), |
| 45 | + new WordPattern(".html", { noWordBoundary: true }) |
| 46 | + |
| 47 | +]; |
| 48 | + |
| 49 | +module.exports = { |
| 50 | + names: ["MD101", "backtick-keywords"], |
| 51 | + description: "Keywords must be fenced and must be in appropriate case.", |
| 52 | + tags: ["backtick", "code", "bash"], |
| 53 | + "function": (params, onError) => { |
| 54 | + var inHeading = false; |
| 55 | + var inLink = false; |
| 56 | + for (let token of params.tokens) { |
| 57 | + switch (token.type) { |
| 58 | + case "heading_open": |
| 59 | + inHeading = true; break; |
| 60 | + case "heading_close": |
| 61 | + inHeading = false; break; |
| 62 | + case "inline": |
| 63 | + let children = new InlineTokenChildren(token); |
| 64 | + for (let { token: child, column, lineNumber } of children) { |
| 65 | + let isText = child.type === "text"; |
| 66 | + switch (child.type) { |
| 67 | + case "link_open": |
| 68 | + inLink = true; break; |
| 69 | + case "link_close": |
| 70 | + inLink = false; break; |
| 71 | + } |
| 72 | + for (let k of keywords) { |
| 73 | + let anyCaseMatch = child.content.match(k.regex); |
| 74 | + if (anyCaseMatch != null) { |
| 75 | + let match = anyCaseMatch[0]; |
| 76 | + let correct = k.suggestion; |
| 77 | + if ((!inHeading && !inLink && isText) || // Bad not fenced |
| 78 | + (match !== correct)) { // Right fencing, wrong case |
| 79 | + onError({ |
| 80 | + lineNumber, |
| 81 | + detail: `Expected \`${correct}\`. Actual ${match}.`, |
| 82 | + range: [column + anyCaseMatch.index, match.length] |
| 83 | + }) |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +}; |
0 commit comments