Skip to content

Commit

Permalink
Fixed wrong indentation (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Dec 27, 2019
1 parent 99fe70d commit c8cdd77
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/utils/indent-common.js
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
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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,9 @@
<!--{}-->
<script>
var bb =
a &&
b
||
c &&
d
</script>

0 comments on commit c8cdd77

Please sign in to comment.