]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Disallow mixed spaces and tabs for indentation | |
3 | * @author Jary Niebur | |
4 | */ | |
5 | "use strict"; | |
6 | ||
7 | //------------------------------------------------------------------------------ | |
8 | // Requirements | |
9 | //------------------------------------------------------------------------------ | |
10 | ||
11 | const rule = require("../../../lib/rules/no-mixed-spaces-and-tabs"), | |
12 | { RuleTester } = require("../../../lib/rule-tester"); | |
13 | ||
14 | //------------------------------------------------------------------------------ | |
15 | // Tests | |
16 | //------------------------------------------------------------------------------ | |
17 | ||
18 | const ruleTester = new RuleTester(); | |
19 | ||
20 | ruleTester.run("no-mixed-spaces-and-tabs", rule, { | |
21 | ||
22 | valid: [ | |
23 | "\tvar x = 5;", | |
24 | " var x = 5;", | |
25 | "\t/*\n\t * Hello\n\t */", | |
26 | "// foo\n\t/**\n\t * Hello\n\t */", | |
27 | "/*\n\n \t \n*/", | |
28 | "/*\t */ //", | |
29 | "/*\n \t*/ //", | |
30 | "/*\n\t *//*\n \t*/", | |
31 | "// \t", | |
32 | "/*\n*/\t ", | |
33 | "/* \t\n\t \n \t\n\t */ \t", | |
34 | { | |
35 | code: "\tvar x = 5,\n\t y = 2;", | |
36 | options: [true] | |
37 | }, | |
38 | { | |
39 | code: "/*\n\t */`\n\t `;", | |
40 | env: { es6: true } | |
41 | }, | |
42 | { | |
43 | code: "/*\n\t */var a = `\n\t `, b = `\n\t `/*\t \n\t \n*/;", | |
44 | env: { es6: true } | |
45 | }, | |
46 | { | |
47 | code: "/*\t `template inside comment` */", | |
48 | env: { es6: true } | |
49 | }, | |
50 | { | |
51 | code: "var foo = `\t /* comment inside template\t */`;", | |
52 | env: { es6: true } | |
53 | }, | |
54 | { | |
55 | code: "`\n\t `;", | |
56 | env: { es6: true } | |
57 | }, | |
58 | { | |
59 | code: "`\n\t \n`;", | |
60 | env: { es6: true } | |
61 | }, | |
62 | { | |
63 | code: "`\t `;", | |
64 | env: { es6: true } | |
65 | }, | |
66 | { | |
67 | code: "const foo = `${console}\n\t foo`;", | |
68 | env: { es6: true } | |
69 | }, | |
70 | { | |
71 | code: "`\t `;` \t`", | |
72 | env: { es6: true } | |
73 | }, | |
74 | { | |
75 | code: "`foo${ 5 }\t `;", | |
76 | env: { es6: true } | |
77 | }, | |
78 | "' \t\\\n\t multiline string';", | |
79 | "'\t \\\n \tmultiline string';", | |
80 | { | |
81 | code: "\tvar x = 5,\n\t y = 2;", | |
82 | options: ["smart-tabs"] | |
83 | } | |
84 | ], | |
85 | ||
86 | invalid: [ | |
87 | { | |
88 | code: "function add(x, y) {\n\t return x + y;\n}", | |
89 | errors: [ | |
90 | { | |
91 | messageId: "mixedSpacesAndTabs", | |
92 | type: "Program", | |
93 | line: 2 | |
94 | } | |
95 | ] | |
96 | }, | |
97 | { | |
98 | code: "\t ;\n/*\n\t * Hello\n\t */", | |
99 | errors: [ | |
100 | { | |
101 | messageId: "mixedSpacesAndTabs", | |
102 | type: "Program", | |
103 | line: 1 | |
104 | } | |
105 | ] | |
106 | }, | |
107 | { | |
108 | code: " \t/* comment */", | |
109 | errors: [ | |
110 | { | |
111 | messageId: "mixedSpacesAndTabs", | |
112 | type: "Program", | |
113 | line: 1 | |
114 | } | |
115 | ] | |
116 | }, | |
117 | { | |
118 | code: "\t // comment", | |
119 | errors: [ | |
120 | { | |
121 | messageId: "mixedSpacesAndTabs", | |
122 | type: "Program", | |
123 | line: 1 | |
124 | } | |
125 | ] | |
126 | }, | |
127 | { | |
128 | code: "\t var a /* comment */ = 1;", | |
129 | errors: [ | |
130 | { | |
131 | messageId: "mixedSpacesAndTabs", | |
132 | type: "Program", | |
133 | line: 1 | |
134 | } | |
135 | ] | |
136 | }, | |
137 | { | |
138 | code: " \tvar b = 1; // comment", | |
139 | errors: [ | |
140 | { | |
141 | messageId: "mixedSpacesAndTabs", | |
142 | type: "Program", | |
143 | line: 1 | |
144 | } | |
145 | ] | |
146 | }, | |
147 | { | |
148 | code: "/**/\n \t/*\n \t*/", | |
149 | errors: [ | |
150 | { | |
151 | messageId: "mixedSpacesAndTabs", | |
152 | type: "Program", | |
153 | line: 2 | |
154 | } | |
155 | ] | |
156 | }, | |
157 | { | |
158 | code: "\t var x = 5, y = 2, z = 5;\n\n\t \tvar j =\t x + y;\nz *= j;", | |
159 | errors: [ | |
160 | { | |
161 | messageId: "mixedSpacesAndTabs", | |
162 | type: "Program", | |
163 | line: 1 | |
164 | }, | |
165 | { | |
166 | messageId: "mixedSpacesAndTabs", | |
167 | type: "Program", | |
168 | line: 3 | |
169 | } | |
170 | ] | |
171 | }, | |
172 | { | |
173 | code: "\tvar x = 5,\n \t y = 2;", | |
174 | options: [true], | |
175 | errors: [ | |
176 | { | |
177 | messageId: "mixedSpacesAndTabs", | |
178 | type: "Program", | |
179 | line: 2 | |
180 | } | |
181 | ] | |
182 | }, | |
183 | { | |
184 | code: "\tvar x = 5,\n \t y = 2;", | |
185 | options: ["smart-tabs"], | |
186 | errors: [ | |
187 | { | |
188 | messageId: "mixedSpacesAndTabs", | |
189 | type: "Program", | |
190 | line: 2 | |
191 | } | |
192 | ] | |
193 | }, | |
194 | { | |
195 | code: "`foo${\n \t 5 }bar`;", | |
196 | options: ["smart-tabs"], | |
197 | env: { es6: true }, | |
198 | errors: [ | |
199 | { | |
200 | messageId: "mixedSpacesAndTabs", | |
201 | type: "Program", | |
202 | line: 2, | |
203 | column: 2 | |
204 | } | |
205 | ] | |
206 | }, | |
207 | { | |
208 | code: "`foo${\n\t 5 }bar`;", | |
209 | env: { es6: true }, | |
210 | errors: [ | |
211 | { | |
212 | messageId: "mixedSpacesAndTabs", | |
213 | type: "Program", | |
214 | line: 2, | |
215 | column: 2 | |
216 | } | |
217 | ] | |
218 | }, | |
219 | { | |
220 | code: " \t'';", | |
221 | errors: [ | |
222 | { | |
223 | messageId: "mixedSpacesAndTabs", | |
224 | type: "Program", | |
225 | line: 1 | |
226 | } | |
227 | ] | |
228 | }, | |
229 | { | |
230 | code: "''\n\t ", | |
231 | errors: [ | |
232 | { | |
233 | messageId: "mixedSpacesAndTabs", | |
234 | type: "Program", | |
235 | line: 2 | |
236 | } | |
237 | ] | |
238 | } | |
239 | ] | |
240 | }); |