]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-multiple-empty-lines.js
5291fbbf0a830bc1f81784ad76fc9a3e64f028f4
2 * @fileoverview Disallows multiple blank lines.
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const rule
= require("../../../lib/rules/no-multiple-empty-lines"),
12 { RuleTester
} = require("../../../lib/rule-tester");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
18 const ruleTester
= new RuleTester();
21 * Creates the expected error message object for the specified number of lines
22 * @param {lines} lines The number of lines expected.
23 * @returns {Object} the expected error message object
26 function getExpectedError(lines
) {
28 messageId
: "consecutiveBlank",
31 pluralizedLines
: lines
=== 1 ? "line" : "lines"
39 * Creates the expected error message object for the specified number of lines
40 * @param {lines} lines The number of lines expected.
41 * @returns {Object} the expected error message object
44 function getExpectedErrorEOF(lines
) {
46 messageId
: "blankEndOfFile",
56 * Creates the expected error message object for the specified number of lines
57 * @param {lines} lines The number of lines expected.
58 * @returns {Object} the expected error message object
61 function getExpectedErrorBOF(lines
) {
63 messageId
: "blankBeginningOfFile",
73 ruleTester
.run("no-multiple-empty-lines", rule
, {
77 code
: "// valid 1\nvar a = 5;\nvar b = 3;\n\n",
81 code
: "// valid 2\n\nvar a = 5;\n\nvar b = 3;",
85 code
: "// valid 3\nvar a = 5;\n\nvar b = 3;\n\n\n",
89 code
: "// valid 4\nvar a = 5,\n b = 3;",
93 code
: "// valid 5\nvar a = 5;\n\n\n\n\nvar b = 3;\n\n\n\n\n",
97 code
: "// valid 6\nvar a = 5;\n/* comment */\nvar b = 5;",
101 code
: "// valid 7\nvar a = 5;\n",
102 options
: [{ max
: 0 }]
105 code
: "// valid 8\nvar a = 5;\n",
106 options
: [{ max
: 0, maxEOF
: 0 }]
109 code
: "// valid 9\nvar a = 1;\n\n",
110 options
: [{ max
: 2, maxEOF
: 1 }]
113 code
: "// valid 10\nvar a = 5;\n",
114 options
: [{ max
: 0, maxBOF
: 0 }]
117 code
: "\n// valid 11\nvar a = 1;\n",
118 options
: [{ max
: 2, maxBOF
: 1 }]
121 code
: "// valid 12\r\n// windows line endings\r\nvar a = 5;\r\nvar b = 3;\r\n\r\n",
122 options
: [{ max
: 1 }]
127 code
: "// valid 12\nx = `\n\n\n\nhi\n\n\n\n`",
128 options
: [{ max
: 2 }],
129 parserOptions
: { ecmaVersion
: 6 }
132 code
: "// valid 13\n`\n\n`",
133 options
: [{ max
: 0 }],
134 parserOptions
: { ecmaVersion
: 6 }
137 code
: "// valid 14\nvar a = 5;`\n\n\n\n\n`",
138 options
: [{ max
: 0, maxEOF
: 0 }],
139 parserOptions
: { ecmaVersion
: 6 }
142 code
: "`\n\n\n\n\n`\n// valid 15\nvar a = 5;",
143 options
: [{ max
: 0, maxBOF
: 0 }],
144 parserOptions
: { ecmaVersion
: 6 }
147 code
: "\n\n\n\n// valid 16\nvar a = 5;\n",
148 options
: [{ max
: 0, maxBOF
: 4 }]
151 code
: "// valid 17\nvar a = 5;\n\n",
152 options
: [{ max
: 0, maxEOF
: 1 }]
156 options
: [{ max
: 1 }]
162 code
: "// invalid 1\nvar a = 5;\n\n\nvar b = 3;",
163 output
: "// invalid 1\nvar a = 5;\n\nvar b = 3;",
164 options
: [{ max
: 1 }],
165 errors
: [getExpectedError(1)]
168 code
: "// invalid 2\n\n\n\n\nvar a = 5;",
169 output
: "// invalid 2\n\n\nvar a = 5;",
170 options
: [{ max
: 2 }],
171 errors
: [getExpectedError(2)]
174 code
: "// invalid 3\nvar a = 5;\n\n\n\n",
175 output
: "// invalid 3\nvar a = 5;\n\n\n",
176 options
: [{ max
: 2 }],
177 errors
: [getExpectedErrorEOF(2)]
180 code
: "// invalid 4\nvar a = 5;\n \n \n \n",
181 output
: "// invalid 4\nvar a = 5;\n \n \n",
182 options
: [{ max
: 2 }],
183 errors
: [getExpectedErrorEOF(2)]
186 code
: "// invalid 5\nvar a=5;\n\n\n\nvar b = 3;",
187 output
: "// invalid 5\nvar a=5;\n\n\nvar b = 3;",
188 options
: [{ max
: 2 }],
189 errors
: [getExpectedError(2)]
192 code
: "// invalid 6\nvar a=5;\n\n\n\nvar b = 3;\n",
193 output
: "// invalid 6\nvar a=5;\n\n\nvar b = 3;\n",
194 options
: [{ max
: 2 }],
195 errors
: [getExpectedError(2)]
198 code
: "// invalid 7\nvar a = 5;\n\n\n\nb = 3;\nvar c = 5;\n\n\n\nvar d = 3;",
199 output
: "// invalid 7\nvar a = 5;\n\n\nb = 3;\nvar c = 5;\n\n\nvar d = 3;",
200 options
: [{ max
: 2 }],
204 code
: "// invalid 8\nvar a = 5;\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 3;",
205 output
: "// invalid 8\nvar a = 5;\n\n\nb = 3;",
206 options
: [{ max
: 2 }],
207 errors
: [getExpectedError(2)]
210 code
: "// invalid 9\nvar a=5;\n\n\n\n\n",
211 output
: "// invalid 9\nvar a=5;\n\n\n",
212 options
: [{ max
: 2 }],
213 errors
: [getExpectedErrorEOF(2)]
216 code
: "// invalid 10\nvar a = 5;\n\nvar b = 3;",
217 output
: "// invalid 10\nvar a = 5;\nvar b = 3;",
218 options
: [{ max
: 0 }],
219 errors
: [getExpectedError(0)]
222 code
: "// invalid 11\nvar a = 5;\n\n\n",
223 output
: "// invalid 11\nvar a = 5;\n\n",
224 options
: [{ max
: 5, maxEOF
: 1 }],
225 errors
: [getExpectedErrorEOF(1)]
228 code
: "// invalid 12\nvar a = 5;\n\n\n\n\n\n",
229 output
: "// invalid 12\nvar a = 5;\n\n\n\n\n",
230 options
: [{ max
: 0, maxEOF
: 4 }],
231 errors
: [getExpectedErrorEOF(4)]
234 code
: "// invalid 13\n\n\n\n\n\n\n\n\nvar a = 5;\n\n\n",
235 output
: "// invalid 13\n\n\n\n\n\n\n\n\nvar a = 5;\n\n",
236 options
: [{ max
: 10, maxEOF
: 1 }],
237 errors
: [getExpectedErrorEOF(1)]
240 code
: "// invalid 14\nvar a = 5;\n\n",
241 output
: "// invalid 14\nvar a = 5;\n",
242 options
: [{ max
: 2, maxEOF
: 0 }],
243 errors
: [getExpectedErrorEOF(0)]
246 code
: "\n\n// invalid 15\nvar a = 5;\n",
247 output
: "\n// invalid 15\nvar a = 5;\n",
248 options
: [{ max
: 5, maxBOF
: 1 }],
249 errors
: [getExpectedErrorBOF(1)]
252 code
: "\n\n\n\n\n// invalid 16\nvar a = 5;\n",
253 output
: "\n\n\n\n// invalid 16\nvar a = 5;\n",
254 options
: [{ max
: 0, maxBOF
: 4 }],
255 errors
: [getExpectedErrorBOF(4)]
258 code
: "\n\n// invalid 17\n\n\n\n\n\n\n\n\nvar a = 5;\n",
259 output
: "\n// invalid 17\n\n\n\n\n\n\n\n\nvar a = 5;\n",
260 options
: [{ max
: 10, maxBOF
: 1 }],
261 errors
: [getExpectedErrorBOF(1)]
264 code
: "\n// invalid 18\nvar a = 5;\n",
265 output
: "// invalid 18\nvar a = 5;\n",
266 options
: [{ max
: 2, maxBOF
: 0 }],
267 errors
: [getExpectedErrorBOF(0)]
270 code
: "\n\n\n// invalid 19\nvar a = 5;\n\n",
271 output
: "// invalid 19\nvar a = 5;\n",
272 options
: [{ max
: 2, maxBOF
: 0, maxEOF
: 0 }],
273 errors
: [getExpectedErrorBOF(0),
274 getExpectedErrorEOF(0)]
277 code
: "// invalid 20\r\n// windows line endings\r\nvar a = 5;\r\nvar b = 3;\r\n\r\n\r\n",
278 output
: "// invalid 20\r\n// windows line endings\r\nvar a = 5;\r\nvar b = 3;\r\n\r\n",
279 options
: [{ max
: 1 }],
280 errors
: [getExpectedErrorEOF(1)]
283 code
: "// invalid 21\n// unix line endings\nvar a = 5;\nvar b = 3;\n\n\n",
284 output
: "// invalid 21\n// unix line endings\nvar a = 5;\nvar b = 3;\n\n",
285 options
: [{ max
: 1 }],
286 errors
: [getExpectedErrorEOF(1)]
300 options
: [{ max
: 1 }],
301 parserOptions
: { ecmaVersion
: 6 },
302 errors
: [getExpectedError(1)]
305 code
: "`template ${foo\n\n\n} literal`;",
306 output
: "`template ${foo\n\n} literal`;",
307 options
: [{ max
: 1 }],
308 parserOptions
: { ecmaVersion
: 6 },
309 errors
: [getExpectedError(1)]
313 // https://github.com/eslint/eslint/issues/7893
314 code
: `a\n\n\n\n${"a".repeat(1e5)}`,
315 output
: `a\n\n\n${"a".repeat(1e5)}`,
316 errors
: [getExpectedError(2)]
320 // https://github.com/eslint/eslint/issues/8401
323 options
: [{ max
: 1, maxEOF
: 0 }],
324 errors
: [getExpectedErrorEOF(0)]
328 // https://github.com/eslint/eslint/pull/12594
329 code
: "var a;\n\n\n\n\nvar b;",
330 output
: "var a;\n\nvar b;",
331 options
: [{ max
: 1 }],
333 messageId
: "consecutiveBlank",
336 pluralizedLines
: "line"
345 // https://github.com/eslint/eslint/pull/12594
346 code
: "var a;\n\n\n\n\nvar b;",
347 output
: "var a;\n\n\nvar b;",
348 options
: [{ max
: 2 }],
350 messageId
: "consecutiveBlank",
353 pluralizedLines
: "lines"