Skip to content

(fixes #494) Ignore indent rules on files other than .vue #544

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

Merged
merged 1 commit into from
Aug 3, 2018
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
2 changes: 2 additions & 0 deletions lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ function isTrivialToken (token) {
* @returns {object} AST event handlers.
*/
module.exports.defineVisitor = function create (context, tokenStore, defaultOptions) {
if (!context.getFilename().endsWith('.vue')) return {}

const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions)
const sourceCode = context.getSourceCode()
const offsets = new Map()
Expand Down
4 changes: 0 additions & 4 deletions tests/fixtures/script-indent/if-statement-04.js

This file was deleted.

7 changes: 7 additions & 0 deletions tests/fixtures/script-indent/if-statement-04.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--{}-->
<script>
if (a)
b;
c
</script>

6 changes: 0 additions & 6 deletions tests/fixtures/script-indent/if-statement-05.js

This file was deleted.

16 changes: 0 additions & 16 deletions tests/fixtures/script-indent/opts-baseindent1.js

This file was deleted.

242 changes: 145 additions & 97 deletions tests/lib/rules/html-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,114 +108,151 @@ tester.run('html-indent', rule, loadPatterns(
// Valid
[
// TemplateLiteral
unIndent`
<template>
<div
v-bind:b="
\`
test
test
{
filename: 'test.vue',
code: unIndent`
<template>
<div
v-bind:b="
\`
test
test
\`
"
></div>
</template>
`,
test
\`
"
></div>
</template>
`
},

// VAttribute
unIndent`
<template>
<div a="
a" b="b"></div>
</template>
`,
{
filename: 'test.vue',
code: unIndent`
<template>
<div a="
a" b="b"></div>
</template>
`
},

// Comments
unIndent`
<template>
<!-- comment -->
{{
// comment
// comment
message
}}
</template>
`,
unIndent`
<template>
{{
/*
* comment
*/
message
}}
</template>
`,
unIndent`
<template>
{{
message
{
filename: 'test.vue',
code: unIndent`
<template>
<!-- comment -->
{{
// comment
// comment
message
}}
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
/*
* comment
*/
message
}}
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
message
// comment
// comment
}}
<!-- comment -->
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
message
/*
* comment
*/
}}
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
message
// comment
// comment
}}
<!-- comment -->
</template>
`,
unIndent`
<template>
{{
message
}}
<!-- comment -->
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
message
/*
* comment
*/
}}
</template>
`,
unIndent`
<template>
{{
message
// comment
// comment
}}
<!-- comment -->
</template>
`,
unIndent`
<template>
{{
message
/*
* comment
*/
}}
</template>
`,
unIndent`
<template>
<div>
<!-- this comment is ignored because the next token doesn't exist. -->
`,
unIndent`
<template>
<div>
<div></div>
<!-- this comment is ignored because the next token doesn't exist. -->
`,
unIndent`
<template>
<div>
<!-- this comment is ignored because the next token doesn't exist. -->
`,
unIndent`
<template>
<div>
<div></div>
<!-- this comment is ignored because the next token doesn't exist. -->
`,
* comment
*/
}}
</template>
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<div>
<!-- this comment is ignored because the next token doesn't exist. -->
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<div>
<div></div>
<!-- this comment is ignored because the next token doesn't exist. -->
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<div>
<!-- this comment is ignored because the next token doesn't exist. -->
`
},
{
filename: 'test.vue',
code: unIndent`
<template>
<div>
<div></div>
<!-- this comment is ignored because the next token doesn't exist. -->
`
},

// Ignores
{
filename: 'test.vue',
code: unIndent`
<template>
<div
Expand All @@ -234,6 +271,7 @@ tester.run('html-indent', rule, loadPatterns(

// Pre
{
filename: 'test.vue',
code: unIndent`
<template>
<pre>
Expand All @@ -250,6 +288,7 @@ tester.run('html-indent', rule, loadPatterns(
[
// TemplateLiteral
{
filename: 'test.vue',
code: unIndent`
<template>
<div
Expand Down Expand Up @@ -284,6 +323,7 @@ tester.run('html-indent', rule, loadPatterns(

// A mix of spaces and tabs.
{
filename: 'test.vue',
code: unIndent`
<template>
<div>
Expand All @@ -303,6 +343,7 @@ tester.run('html-indent', rule, loadPatterns(
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
\t<div>
Expand All @@ -325,6 +366,7 @@ tester.run('html-indent', rule, loadPatterns(

// Comments
{
filename: 'test.vue',
code: unIndent`
<template>
<!-- comment -->
Expand Down Expand Up @@ -355,6 +397,7 @@ tester.run('html-indent', rule, loadPatterns(
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
Expand All @@ -381,6 +424,7 @@ tester.run('html-indent', rule, loadPatterns(
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
Expand Down Expand Up @@ -410,6 +454,7 @@ tester.run('html-indent', rule, loadPatterns(
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
Expand Down Expand Up @@ -440,6 +485,7 @@ tester.run('html-indent', rule, loadPatterns(

// Ignores
{
filename: 'test.vue',
code: unIndent`
<template>
<div
Expand All @@ -464,6 +510,7 @@ tester.run('html-indent', rule, loadPatterns(
]
},
{
filename: 'test.vue',
code: unIndent`
<template>
{{
Expand Down Expand Up @@ -497,6 +544,7 @@ tester.run('html-indent', rule, loadPatterns(

// Pre
{
filename: 'test.vue',
code: unIndent`
<template>
<pre
Expand Down
Loading