Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: "ignores" option of html-indent does not work #1016

Merged
merged 2 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions)
const sourceCode = context.getSourceCode()
const offsets = new Map()
const preformattedTokens = new Set()
const ignoreTokens = new Set()

/**
* Set offset to the given tokens.
Expand Down Expand Up @@ -341,9 +341,9 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
)
}
for (const token of tokenStore.getTokensBetween(node.startTag, endToken, option)) {
preformattedTokens.add(token)
ignoreTokens.add(token)
}
preformattedTokens.add(endToken)
ignoreTokens.add(endToken)
}

/**
Expand Down Expand Up @@ -587,6 +587,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
function ignore (node) {
for (const token of tokenStore.getTokens(node)) {
offsets.delete(token)
ignoreTokens.add(token)
}
}

Expand Down Expand Up @@ -848,8 +849,8 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
}
}

// It does not validate preformatted tokens.
if (preformattedTokens.has(firstToken)) {
// It does not validate ignore tokens.
if (ignoreTokens.has(firstToken)) {
return
}

Expand Down
19 changes: 19 additions & 0 deletions tests/fixtures/html-indent/opts-ignores-vattribute-01.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--{"options":[2,{"ignores": ["VAttribute"]}]}-->
<template>
<div>
<div
attr1="a">
</div>
<div
attr2>
</div>
<div
:attr3="a">
</div>
<div
:attr4="
a
">
</div>
</div>
</template>
19 changes: 19 additions & 0 deletions tests/lib/rules/html-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,25 @@ tester.run('html-indent', rule, loadPatterns(
{ message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 7 },
{ message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 }
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
\t <div attr1
\t\t attr2/>
</template>
`,
output: unIndent`
<template>
\t<div attr1
\t\t attr2/>
</template>
`,
options: ['tab', { 'ignores': ['VAttribute'] }],
errors: [
{ message: 'Expected "\\t" character, but found " " character.', line: 2 }
]
}
]
))