Skip to content

Commit 386cec4

Browse files
authored
Fixed: "ignores" option of html-indent does not work (#1016)
* Fixed: "ignores" option of "html-indent" does not work * Add testcase that mixed indent
1 parent c8cdd77 commit 386cec4

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

lib/utils/indent-common.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
278278
const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions)
279279
const sourceCode = context.getSourceCode()
280280
const offsets = new Map()
281-
const preformattedTokens = new Set()
281+
const ignoreTokens = new Set()
282282

283283
/**
284284
* Set offset to the given tokens.
@@ -341,9 +341,9 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
341341
)
342342
}
343343
for (const token of tokenStore.getTokensBetween(node.startTag, endToken, option)) {
344-
preformattedTokens.add(token)
344+
ignoreTokens.add(token)
345345
}
346-
preformattedTokens.add(endToken)
346+
ignoreTokens.add(endToken)
347347
}
348348

349349
/**
@@ -600,6 +600,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
600600
function ignore (node) {
601601
for (const token of tokenStore.getTokens(node)) {
602602
offsets.delete(token)
603+
ignoreTokens.add(token)
603604
}
604605
}
605606

@@ -861,8 +862,8 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
861862
}
862863
}
863864

864-
// It does not validate preformatted tokens.
865-
if (preformattedTokens.has(firstToken)) {
865+
// It does not validate ignore tokens.
866+
if (ignoreTokens.has(firstToken)) {
866867
return
867868
}
868869

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--{"options":[2,{"ignores": ["VAttribute"]}]}-->
2+
<template>
3+
<div>
4+
<div
5+
attr1="a">
6+
</div>
7+
<div
8+
attr2>
9+
</div>
10+
<div
11+
:attr3="a">
12+
</div>
13+
<div
14+
:attr4="
15+
a
16+
">
17+
</div>
18+
</div>
19+
</template>

tests/lib/rules/html-indent.js

+19
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,25 @@ tester.run('html-indent', rule, loadPatterns(
756756
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 },
757757
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 }
758758
]
759+
},
760+
{
761+
filename: 'test.vue',
762+
code: unIndent`
763+
<template>
764+
\t <div attr1
765+
\t\t attr2/>
766+
</template>
767+
`,
768+
output: unIndent`
769+
<template>
770+
\t<div attr1
771+
\t\t attr2/>
772+
</template>
773+
`,
774+
options: ['tab', { 'ignores': ['VAttribute'] }],
775+
errors: [
776+
{ message: 'Expected "\\t" character, but found " " character.', line: 2 }
777+
]
759778
}
760779
]
761780
))

0 commit comments

Comments
 (0)