Skip to content

Commit 1c410d8

Browse files
authored
Ignore indent rules on files other than .vue (#544)
1 parent 74f7dc6 commit 1c410d8

File tree

7 files changed

+215
-154
lines changed

7 files changed

+215
-154
lines changed

lib/utils/indent-common.js

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ function isTrivialToken (token) {
269269
* @returns {object} AST event handlers.
270270
*/
271271
module.exports.defineVisitor = function create (context, tokenStore, defaultOptions) {
272+
if (!context.getFilename().endsWith('.vue')) return {}
273+
272274
const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions)
273275
const sourceCode = context.getSourceCode()
274276
const offsets = new Map()

tests/fixtures/script-indent/if-statement-04.js

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--{}-->
2+
<script>
3+
if (a)
4+
b;
5+
c
6+
</script>
7+

tests/fixtures/script-indent/if-statement-05.js

-6
This file was deleted.

tests/fixtures/script-indent/opts-baseindent1.js

-16
This file was deleted.

tests/lib/rules/html-indent.js

+145-97
Original file line numberDiff line numberDiff line change
@@ -108,114 +108,151 @@ tester.run('html-indent', rule, loadPatterns(
108108
// Valid
109109
[
110110
// TemplateLiteral
111-
unIndent`
112-
<template>
113-
<div
114-
v-bind:b="
115-
\`
116-
test
117-
test
111+
{
112+
filename: 'test.vue',
113+
code: unIndent`
114+
<template>
115+
<div
116+
v-bind:b="
117+
\`
118+
test
118119
test
119-
\`
120-
"
121-
></div>
122-
</template>
123-
`,
120+
test
121+
\`
122+
"
123+
></div>
124+
</template>
125+
`
126+
},
124127

125128
// VAttribute
126-
unIndent`
127-
<template>
128-
<div a="
129-
a" b="b"></div>
130-
</template>
131-
`,
129+
{
130+
filename: 'test.vue',
131+
code: unIndent`
132+
<template>
133+
<div a="
134+
a" b="b"></div>
135+
</template>
136+
`
137+
},
132138

133139
// Comments
134-
unIndent`
135-
<template>
136-
<!-- comment -->
137-
{{
138-
// comment
139-
// comment
140-
message
141-
}}
142-
</template>
143-
`,
144-
unIndent`
145-
<template>
146-
{{
147-
/*
148-
* comment
149-
*/
150-
message
151-
}}
152-
</template>
153-
`,
154-
unIndent`
155-
<template>
156-
{{
157-
message
140+
{
141+
filename: 'test.vue',
142+
code: unIndent`
143+
<template>
144+
<!-- comment -->
145+
{{
146+
// comment
147+
// comment
148+
message
149+
}}
150+
</template>
151+
`
152+
},
153+
{
154+
filename: 'test.vue',
155+
code: unIndent`
156+
<template>
157+
{{
158+
/*
159+
* comment
160+
*/
161+
message
162+
}}
163+
</template>
164+
`
165+
},
166+
{
167+
filename: 'test.vue',
168+
code: unIndent`
169+
<template>
170+
{{
171+
message
172+
// comment
173+
// comment
174+
}}
175+
<!-- comment -->
176+
</template>
177+
`
178+
},
179+
{
180+
filename: 'test.vue',
181+
code: unIndent`
182+
<template>
183+
{{
184+
message
185+
/*
186+
* comment
187+
*/
188+
}}
189+
</template>
190+
`
191+
},
192+
{
193+
filename: 'test.vue',
194+
code: unIndent`
195+
<template>
196+
{{
197+
message
158198
// comment
159199
// comment
160-
}}
161-
<!-- comment -->
162-
</template>
163-
`,
164-
unIndent`
165-
<template>
166-
{{
167-
message
200+
}}
201+
<!-- comment -->
202+
</template>
203+
`
204+
},
205+
{
206+
filename: 'test.vue',
207+
code: unIndent`
208+
<template>
209+
{{
210+
message
168211
/*
169-
* comment
170-
*/
171-
}}
172-
</template>
173-
`,
174-
unIndent`
175-
<template>
176-
{{
177-
message
178-
// comment
179-
// comment
180-
}}
181-
<!-- comment -->
182-
</template>
183-
`,
184-
unIndent`
185-
<template>
186-
{{
187-
message
188-
/*
189-
* comment
190-
*/
191-
}}
192-
</template>
193-
`,
194-
unIndent`
195-
<template>
196-
<div>
197-
<!-- this comment is ignored because the next token doesn't exist. -->
198-
`,
199-
unIndent`
200-
<template>
201-
<div>
202-
<div></div>
203-
<!-- this comment is ignored because the next token doesn't exist. -->
204-
`,
205-
unIndent`
206-
<template>
207-
<div>
208-
<!-- this comment is ignored because the next token doesn't exist. -->
209-
`,
210-
unIndent`
211-
<template>
212-
<div>
213-
<div></div>
214-
<!-- this comment is ignored because the next token doesn't exist. -->
215-
`,
212+
* comment
213+
*/
214+
}}
215+
</template>
216+
`
217+
},
218+
{
219+
filename: 'test.vue',
220+
code: unIndent`
221+
<template>
222+
<div>
223+
<!-- this comment is ignored because the next token doesn't exist. -->
224+
`
225+
},
226+
{
227+
filename: 'test.vue',
228+
code: unIndent`
229+
<template>
230+
<div>
231+
<div></div>
232+
<!-- this comment is ignored because the next token doesn't exist. -->
233+
`
234+
},
235+
{
236+
filename: 'test.vue',
237+
code: unIndent`
238+
<template>
239+
<div>
240+
<!-- this comment is ignored because the next token doesn't exist. -->
241+
`
242+
},
243+
{
244+
filename: 'test.vue',
245+
code: unIndent`
246+
<template>
247+
<div>
248+
<div></div>
249+
<!-- this comment is ignored because the next token doesn't exist. -->
250+
`
251+
},
216252

217253
// Ignores
218254
{
255+
filename: 'test.vue',
219256
code: unIndent`
220257
<template>
221258
<div
@@ -234,6 +271,7 @@ tester.run('html-indent', rule, loadPatterns(
234271

235272
// Pre
236273
{
274+
filename: 'test.vue',
237275
code: unIndent`
238276
<template>
239277
<pre>
@@ -250,6 +288,7 @@ tester.run('html-indent', rule, loadPatterns(
250288
[
251289
// TemplateLiteral
252290
{
291+
filename: 'test.vue',
253292
code: unIndent`
254293
<template>
255294
<div
@@ -284,6 +323,7 @@ tester.run('html-indent', rule, loadPatterns(
284323

285324
// A mix of spaces and tabs.
286325
{
326+
filename: 'test.vue',
287327
code: unIndent`
288328
<template>
289329
<div>
@@ -303,6 +343,7 @@ tester.run('html-indent', rule, loadPatterns(
303343
]
304344
},
305345
{
346+
filename: 'test.vue',
306347
code: unIndent`
307348
<template>
308349
\t<div>
@@ -325,6 +366,7 @@ tester.run('html-indent', rule, loadPatterns(
325366

326367
// Comments
327368
{
369+
filename: 'test.vue',
328370
code: unIndent`
329371
<template>
330372
<!-- comment -->
@@ -355,6 +397,7 @@ tester.run('html-indent', rule, loadPatterns(
355397
]
356398
},
357399
{
400+
filename: 'test.vue',
358401
code: unIndent`
359402
<template>
360403
{{
@@ -381,6 +424,7 @@ tester.run('html-indent', rule, loadPatterns(
381424
]
382425
},
383426
{
427+
filename: 'test.vue',
384428
code: unIndent`
385429
<template>
386430
{{
@@ -410,6 +454,7 @@ tester.run('html-indent', rule, loadPatterns(
410454
]
411455
},
412456
{
457+
filename: 'test.vue',
413458
code: unIndent`
414459
<template>
415460
{{
@@ -440,6 +485,7 @@ tester.run('html-indent', rule, loadPatterns(
440485

441486
// Ignores
442487
{
488+
filename: 'test.vue',
443489
code: unIndent`
444490
<template>
445491
<div
@@ -464,6 +510,7 @@ tester.run('html-indent', rule, loadPatterns(
464510
]
465511
},
466512
{
513+
filename: 'test.vue',
467514
code: unIndent`
468515
<template>
469516
{{
@@ -497,6 +544,7 @@ tester.run('html-indent', rule, loadPatterns(
497544

498545
// Pre
499546
{
547+
filename: 'test.vue',
500548
code: unIndent`
501549
<template>
502550
<pre

0 commit comments

Comments
 (0)