Skip to content

Commit c8cdd77

Browse files
authored
Fixed wrong indentation (#1015)
1 parent 99fe70d commit c8cdd77

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

lib/utils/indent-common.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
509509
function getChainHeadToken (node) {
510510
const type = node.type
511511
while (node.parent.type === type) {
512+
const prevToken = tokenStore.getTokenBefore(node)
513+
if (isLeftParen(prevToken)) {
514+
// The chaining is broken by parentheses.
515+
break
516+
}
512517
node = node.parent
513518
}
514519
return tokenStore.getFirstToken(node)
@@ -537,7 +542,15 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
537542
return parent.range[0] === token.range[0]
538543
}
539544
if (t === 'VExpressionContainer') {
540-
return node.range[0] === token.range[0]
545+
if (node.range[0] !== token.range[0]) {
546+
return false
547+
}
548+
const prevToken = tokenStore.getTokenBefore(belongingNode)
549+
if (isLeftParen(prevToken)) {
550+
// It is not the first token because it is enclosed in parentheses.
551+
return false
552+
}
553+
return true
541554
}
542555
if (t === 'CallExpression' || t === 'NewExpression') {
543556
const openParen = tokenStore.getTokenAfter(parent.callee, isNotRightParen)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "npm run test:base -- --watch --growl",
88
"test:base": "mocha \"tests/lib/**/*.js\" --reporter dot",
99
"test": "nyc npm run test:base -- \"tests/integrations/*.js\" --timeout 60000",
10+
"debug": "mocha --inspect-brk \"tests/lib/**/*.js\" --reporter dot --timeout 60000",
1011
"lint": "eslint . --rulesdir eslint-internal-rules",
1112
"pretest": "npm run lint",
1213
"preversion": "npm test && npm run update && git add .",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!--{}-->
2+
<template>
3+
<div>
4+
<span
5+
v-if="
6+
a &&
7+
b"
8+
>
9+
</span>
10+
<span
11+
v-if="
12+
a
13+
&& b"
14+
>
15+
</span>
16+
<span
17+
v-if="
18+
a
19+
&&
20+
b"
21+
>
22+
</span>
23+
<!-- Enclosed in parentheses -->
24+
<span
25+
v-if="(
26+
a &&
27+
b
28+
)"
29+
>
30+
</span>
31+
<span
32+
v-if="(
33+
a
34+
&& b
35+
)"
36+
>
37+
</span>
38+
<span
39+
v-if="(
40+
a
41+
&&
42+
b
43+
)"
44+
>
45+
</span>
46+
<!-- The first line is the same line -->
47+
<span
48+
v-if="a &&
49+
b"
50+
>
51+
</span>
52+
<span
53+
v-if="a
54+
&& b"
55+
>
56+
</span>
57+
<span
58+
v-if="a
59+
&&
60+
b"
61+
>
62+
</span>
63+
</div>
64+
</template>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--{}-->
2+
<script>
3+
// https://github.com/vuejs/eslint-plugin-vue/issues/1007
4+
function fn () {
5+
return (
6+
(
7+
a ||
8+
b
9+
) &&
10+
(
11+
c ||
12+
d
13+
)
14+
);
15+
}
16+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--{}-->
2+
<script>
3+
var bb =
4+
(
5+
a ||
6+
b
7+
) &&
8+
(
9+
c ||
10+
d
11+
)
12+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--{}-->
2+
<script>
3+
var bb =
4+
a &&
5+
b
6+
||
7+
c &&
8+
d
9+
</script>

0 commit comments

Comments
 (0)