]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/eol-last.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / rules / eol-last.js
1 /**
2 * @fileoverview Tests for eol-last rule.
3 * @author Nodeca Team <https://github.com/nodeca>
4 */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Requirements
9 //------------------------------------------------------------------------------
10
11 const rule = require("../../../lib/rules/eol-last"),
12 { RuleTester } = require("../../../lib/rule-tester");
13
14 //------------------------------------------------------------------------------
15 // Tests
16 //------------------------------------------------------------------------------
17
18 const ruleTester = new RuleTester();
19
20 ruleTester.run("eol-last", rule, {
21
22 valid: [
23 "",
24 "\n",
25 "var a = 123;\n",
26 "var a = 123;\n\n",
27 "var a = 123;\n \n",
28
29 "\r\n",
30 "var a = 123;\r\n",
31 "var a = 123;\r\n\r\n",
32 "var a = 123;\r\n \r\n",
33
34 { code: "var a = 123;", options: ["never"] },
35 { code: "var a = 123;\nvar b = 456;", options: ["never"] },
36 { code: "var a = 123;\r\nvar b = 456;", options: ["never"] },
37
38 // Deprecated: `"unix"` parameter
39 { code: "", options: ["unix"] },
40 { code: "\n", options: ["unix"] },
41 { code: "var a = 123;\n", options: ["unix"] },
42 { code: "var a = 123;\n\n", options: ["unix"] },
43 { code: "var a = 123;\n \n", options: ["unix"] },
44
45 // Deprecated: `"windows"` parameter
46 { code: "", options: ["windows"] },
47 { code: "\n", options: ["windows"] },
48 { code: "\r\n", options: ["windows"] },
49 { code: "var a = 123;\r\n", options: ["windows"] },
50 { code: "var a = 123;\r\n\r\n", options: ["windows"] },
51 { code: "var a = 123;\r\n \r\n", options: ["windows"] }
52 ],
53
54 invalid: [
55 {
56 code: "var a = 123;",
57 output: "var a = 123;\n",
58 errors: [{
59 messageId: "missing",
60 type: "Program",
61 line: 1,
62 column: 13,
63 endLine: void 0,
64 endColumn: void 0
65 }]
66 },
67 {
68 code: "var a = 123;\n ",
69 output: "var a = 123;\n \n",
70 errors: [{
71 messageId: "missing",
72 type: "Program",
73 line: 2,
74 column: 4,
75 endLine: void 0,
76 endColumn: void 0
77 }]
78 },
79 {
80 code: "var a = 123;\n",
81 output: "var a = 123;",
82 options: ["never"],
83 errors: [{
84 messageId: "unexpected",
85 type: "Program",
86 line: 1,
87 column: 13,
88 endLine: 2,
89 endColumn: 1
90 }]
91 },
92 {
93 code: "var a = 123;\r\n",
94 output: "var a = 123;",
95 options: ["never"],
96 errors: [{
97 messageId: "unexpected",
98 type: "Program",
99 line: 1,
100 column: 13,
101 endLine: 2,
102 endColumn: 1
103 }]
104 },
105 {
106 code: "var a = 123;\r\n\r\n",
107 output: "var a = 123;",
108 options: ["never"],
109 errors: [{
110 messageId: "unexpected",
111 type: "Program",
112 line: 2,
113 column: 1,
114 endLine: 3,
115 endColumn: 1
116 }]
117 },
118 {
119 code: "var a = 123;\nvar b = 456;\n",
120 output: "var a = 123;\nvar b = 456;",
121 options: ["never"],
122 errors: [{
123 messageId: "unexpected",
124 type: "Program",
125 line: 2,
126 column: 13,
127 endLine: 3,
128 endColumn: 1
129 }]
130 },
131 {
132 code: "var a = 123;\r\nvar b = 456;\r\n",
133 output: "var a = 123;\r\nvar b = 456;",
134 options: ["never"],
135 errors: [{
136 messageId: "unexpected",
137 type: "Program",
138 line: 2,
139 column: 13,
140 endLine: 3,
141 endColumn: 1
142 }]
143 },
144 {
145 code: "var a = 123;\n\n",
146 output: "var a = 123;",
147 options: ["never"],
148 errors: [{
149 messageId: "unexpected",
150 type: "Program",
151 line: 2,
152 column: 1,
153 endLine: 3,
154 endColumn: 1
155 }]
156 },
157
158 // Deprecated: `"unix"` parameter
159 {
160 code: "var a = 123;",
161 output: "var a = 123;\n",
162 options: ["unix"],
163 errors: [{
164 messageId: "missing",
165 type: "Program",
166 line: 1,
167 column: 13,
168 endLine: void 0,
169 endColumn: void 0
170 }]
171 },
172 {
173 code: "var a = 123;\n ",
174 output: "var a = 123;\n \n",
175 options: ["unix"],
176 errors: [{
177 messageId: "missing",
178 type: "Program",
179 line: 2,
180 column: 4,
181 endLine: void 0,
182 endColumn: void 0
183 }]
184 },
185
186 // Deprecated: `"windows"` parameter
187 {
188 code: "var a = 123;",
189 output: "var a = 123;\r\n",
190 options: ["windows"],
191 errors: [{
192 messageId: "missing",
193 type: "Program",
194 line: 1,
195 column: 13,
196 endLine: void 0,
197 endColumn: void 0
198 }]
199 },
200 {
201 code: "var a = 123;\r\n ",
202 output: "var a = 123;\r\n \r\n",
203 options: ["windows"],
204 errors: [{
205 messageId: "missing",
206 type: "Program",
207 line: 2,
208 column: 4,
209 endLine: void 0,
210 endColumn: void 0
211 }]
212 }
213 ]
214 });