Skip to content

Fixed wrong indentation #1015

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
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
15 changes: 14 additions & 1 deletion lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
function getChainHeadToken (node) {
const type = node.type
while (node.parent.type === type) {
const prevToken = tokenStore.getTokenBefore(node)
if (isLeftParen(prevToken)) {
// The chaining is broken by parentheses.
break
}
node = node.parent
}
return tokenStore.getFirstToken(node)
Expand Down Expand Up @@ -537,7 +542,15 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
return parent.range[0] === token.range[0]
}
if (t === 'VExpressionContainer') {
return node.range[0] === token.range[0]
if (node.range[0] !== token.range[0]) {
return false
}
const prevToken = tokenStore.getTokenBefore(belongingNode)
if (isLeftParen(prevToken)) {
// It is not the first token because it is enclosed in parentheses.
return false
}
return true
}
if (t === 'CallExpression' || t === 'NewExpression') {
const openParen = tokenStore.getTokenAfter(parent.callee, isNotRightParen)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"start": "npm run test:base -- --watch --growl",
"test:base": "mocha \"tests/lib/**/*.js\" --reporter dot",
"test": "nyc npm run test:base -- \"tests/integrations/*.js\" --timeout 60000",
"debug": "mocha --inspect-brk \"tests/lib/**/*.js\" --reporter dot --timeout 60000",
"lint": "eslint . --rulesdir eslint-internal-rules",
"pretest": "npm run lint",
"preversion": "npm test && npm run update && git add .",
Expand Down
64 changes: 64 additions & 0 deletions tests/fixtures/html-indent/logical-expression-01.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--{}-->
<template>
<div>
<span
v-if="
a &&
b"
>
</span>
<span
v-if="
a
&& b"
>
</span>
<span
v-if="
a
&&
b"
>
</span>
<!-- Enclosed in parentheses -->
<span
v-if="(
a &&
b
)"
>
</span>
<span
v-if="(
a
&& b
)"
>
</span>
<span
v-if="(
a
&&
b
)"
>
</span>
<!-- The first line is the same line -->
<span
v-if="a &&
b"
>
</span>
<span
v-if="a
&& b"
>
</span>
<span
v-if="a
&&
b"
>
</span>
</div>
</template>
16 changes: 16 additions & 0 deletions tests/fixtures/script-indent/logical-expression-01.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--{}-->
<script>
// https://github.com/vuejs/eslint-plugin-vue/issues/1007
function fn () {
return (
(
a ||
b
) &&
(
c ||
d
)
);
}
</script>
12 changes: 12 additions & 0 deletions tests/fixtures/script-indent/logical-expression-02.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--{}-->
<script>
var bb =
(
a ||
b
) &&
(
c ||
d
)
</script>
9 changes: 9 additions & 0 deletions tests/fixtures/script-indent/logical-expression-03.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--{}-->
<script>
var bb =
a &&
b
||
c &&
d
</script>