|
| 1 | +import { RuleTester } from "eslint"; |
| 2 | +import rule from "../../../lib/rules/no-irregular-whitespace"; |
| 3 | + |
| 4 | +const tester = new RuleTester({ |
| 5 | + parser: require.resolve("jsonc-eslint-parser"), |
| 6 | + parserOptions: { |
| 7 | + ecmaVersion: 2020, |
| 8 | + }, |
| 9 | +}); |
| 10 | + |
| 11 | +tester.run("no-irregular-whitespace", rule as any, { |
| 12 | + valid: [ |
| 13 | + `"\u0020"`, |
| 14 | + `"\u0009"`, |
| 15 | + `"\\u000B"`, |
| 16 | + `["\u0009"]`, |
| 17 | + `["\\u000B"]`, |
| 18 | + `{"\u0009": "\u0009"}`, |
| 19 | + `{"\\u000B": "\\u000B"}`, |
| 20 | + |
| 21 | + // String |
| 22 | + `"\u000B"`, |
| 23 | + `["\u000B"]`, |
| 24 | + `{"\u000B": "\u000B"}`, |
| 25 | + { |
| 26 | + code: `"\u000B"`, |
| 27 | + options: [{ skipStrings: true }], |
| 28 | + }, |
| 29 | + { |
| 30 | + code: `["\u000B"]`, |
| 31 | + options: [{ skipStrings: true }], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: `{"\u000B": "\u000B"}`, |
| 35 | + options: [{ skipStrings: true }], |
| 36 | + }, |
| 37 | + // Templates |
| 38 | + { |
| 39 | + code: `\`\u000B\``, |
| 40 | + options: [{ skipTemplates: true }], |
| 41 | + }, |
| 42 | + { |
| 43 | + code: `[\`\u000B\`]`, |
| 44 | + options: [{ skipTemplates: true }], |
| 45 | + }, |
| 46 | + { |
| 47 | + code: `{"\u000B": \`\u000B\`}`, |
| 48 | + options: [{ skipTemplates: true }], |
| 49 | + }, |
| 50 | + // RegExps |
| 51 | + { |
| 52 | + code: `/\u000B/`, |
| 53 | + options: [{ skipRegExps: true }], |
| 54 | + }, |
| 55 | + { |
| 56 | + code: `[/\u000B/]`, |
| 57 | + options: [{ skipRegExps: true }], |
| 58 | + }, |
| 59 | + { |
| 60 | + code: `{"\u000B": /\u000B/}`, |
| 61 | + options: [{ skipRegExps: true }], |
| 62 | + }, |
| 63 | + // Comments |
| 64 | + { |
| 65 | + code: `{} // \u000B`, |
| 66 | + options: [{ skipComments: true }], |
| 67 | + }, |
| 68 | + ], |
| 69 | + invalid: [ |
| 70 | + { |
| 71 | + code: `{"\u000B": [\`\u000B\`, /\u000B/]} \u000B // \u000B`, |
| 72 | + errors: [ |
| 73 | + { |
| 74 | + message: "Irregular whitespace not allowed.", |
| 75 | + line: 1, |
| 76 | + column: 9, |
| 77 | + }, |
| 78 | + { |
| 79 | + message: "Irregular whitespace not allowed.", |
| 80 | + line: 1, |
| 81 | + column: 14, |
| 82 | + }, |
| 83 | + { |
| 84 | + message: "Irregular whitespace not allowed.", |
| 85 | + line: 1, |
| 86 | + column: 19, |
| 87 | + }, |
| 88 | + { |
| 89 | + message: "Irregular whitespace not allowed.", |
| 90 | + line: 1, |
| 91 | + column: 24, |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: `{"\u000B": [\`\u000B\`, /\u000B/]} \u000B // \u000B`, |
| 97 | + options: [ |
| 98 | + { |
| 99 | + skipStrings: true, |
| 100 | + skipComments: true, |
| 101 | + skipRegExps: true, |
| 102 | + skipTemplates: true, |
| 103 | + }, |
| 104 | + ], |
| 105 | + errors: [ |
| 106 | + { |
| 107 | + message: "Irregular whitespace not allowed.", |
| 108 | + line: 1, |
| 109 | + column: 19, |
| 110 | + }, |
| 111 | + ], |
| 112 | + }, |
| 113 | + // String |
| 114 | + { |
| 115 | + code: `{"\u000B": "\u000B"}`, |
| 116 | + options: [{ skipStrings: false }], |
| 117 | + errors: [ |
| 118 | + { |
| 119 | + message: "Irregular whitespace not allowed.", |
| 120 | + line: 1, |
| 121 | + column: 3, |
| 122 | + }, |
| 123 | + { |
| 124 | + message: "Irregular whitespace not allowed.", |
| 125 | + line: 1, |
| 126 | + column: 8, |
| 127 | + }, |
| 128 | + ], |
| 129 | + }, |
| 130 | + { |
| 131 | + code: `["\u000B"]`, |
| 132 | + options: [{ skipStrings: false }], |
| 133 | + errors: [ |
| 134 | + { |
| 135 | + message: "Irregular whitespace not allowed.", |
| 136 | + line: 1, |
| 137 | + column: 3, |
| 138 | + }, |
| 139 | + ], |
| 140 | + }, |
| 141 | + { |
| 142 | + code: `"\u000B"`, |
| 143 | + options: [{ skipStrings: false }], |
| 144 | + errors: [ |
| 145 | + { |
| 146 | + message: "Irregular whitespace not allowed.", |
| 147 | + line: 1, |
| 148 | + column: 2, |
| 149 | + }, |
| 150 | + ], |
| 151 | + }, |
| 152 | + // Templates |
| 153 | + { |
| 154 | + code: `\`\u000B\``, |
| 155 | + options: [{ skipTemplates: false }], |
| 156 | + errors: [ |
| 157 | + { |
| 158 | + message: "Irregular whitespace not allowed.", |
| 159 | + line: 1, |
| 160 | + column: 2, |
| 161 | + }, |
| 162 | + ], |
| 163 | + }, |
| 164 | + { |
| 165 | + code: `[\`\u000B\`]`, |
| 166 | + options: [{ skipTemplates: false }], |
| 167 | + errors: [ |
| 168 | + { |
| 169 | + message: "Irregular whitespace not allowed.", |
| 170 | + line: 1, |
| 171 | + column: 3, |
| 172 | + }, |
| 173 | + ], |
| 174 | + }, |
| 175 | + { |
| 176 | + code: `{"\u000B": \`\u000B\`}`, |
| 177 | + options: [{ skipTemplates: false }], |
| 178 | + errors: [ |
| 179 | + { |
| 180 | + message: "Irregular whitespace not allowed.", |
| 181 | + line: 1, |
| 182 | + column: 8, |
| 183 | + }, |
| 184 | + ], |
| 185 | + }, |
| 186 | + // RegExps |
| 187 | + { |
| 188 | + code: `/\u000B/`, |
| 189 | + options: [{ skipRegExps: false }], |
| 190 | + errors: [ |
| 191 | + { |
| 192 | + message: "Irregular whitespace not allowed.", |
| 193 | + line: 1, |
| 194 | + column: 2, |
| 195 | + }, |
| 196 | + ], |
| 197 | + }, |
| 198 | + { |
| 199 | + code: `[/\u000B/]`, |
| 200 | + options: [{ skipRegExps: false }], |
| 201 | + errors: [ |
| 202 | + { |
| 203 | + message: "Irregular whitespace not allowed.", |
| 204 | + line: 1, |
| 205 | + column: 3, |
| 206 | + }, |
| 207 | + ], |
| 208 | + }, |
| 209 | + { |
| 210 | + code: `{"\u000B": /\u000B/}`, |
| 211 | + options: [{ skipRegExps: false }], |
| 212 | + errors: [ |
| 213 | + { |
| 214 | + message: "Irregular whitespace not allowed.", |
| 215 | + line: 1, |
| 216 | + column: 8, |
| 217 | + }, |
| 218 | + ], |
| 219 | + }, |
| 220 | + // Comments |
| 221 | + { |
| 222 | + code: `{} // \u000B`, |
| 223 | + options: [{ skipComments: false }], |
| 224 | + errors: [ |
| 225 | + { |
| 226 | + message: "Irregular whitespace not allowed.", |
| 227 | + line: 1, |
| 228 | + column: 7, |
| 229 | + }, |
| 230 | + ], |
| 231 | + }, |
| 232 | + ], |
| 233 | +}); |
0 commit comments