Skip to content

Commit f2b9ccc

Browse files
authored
Improved indent rules to support TypeScript syntax (#1520)
* Make the indent rules supports TypeScript * fix * Update docs * update * update ci * update ci * update testcase for node 8 * Fix decorator indent * update
1 parent a969878 commit f2b9ccc

File tree

96 files changed

+3382
-571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3382
-571
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- run:
4444
name: Install eslint@6
4545
command: |
46-
npm install -D eslint@6.2.0
46+
npm install --save-exact eslint@6.8.0 @typescript-eslint/[email protected] [email protected]
4747
- run:
4848
name: Install dependencies
4949
command: npm install

docs/rules/html-indent.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ since: v3.14.0
1717
This rule enforces a consistent indentation style in `<template>`. The default style is 2 spaces.
1818

1919
- This rule checks all tags, also all expressions in directives and mustaches.
20-
- In the expressions, this rule supports ECMAScript 2020 syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes.
20+
- In the expressions, this rule supports ECMAScript 2022 syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes.
2121

2222
<eslint-code-block fix :rules="{'vue/html-indent': ['error']}">
2323

docs/rules/script-indent.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ since: v4.2.0
1313

1414
## :book: Rule Details
1515

16-
This rule is similar to core [indent](https://eslint.org/docs/rules/indent) rule, but it has an option for inside of `<script>` tag.
16+
This rule enforces a consistent indentation style in `<script>`. The default style is 2 spaces.
1717

1818
<eslint-code-block fix :rules="{'vue/script-indent': ['error']}">
1919

@@ -117,7 +117,7 @@ This rule only checks `.vue` files and does not interfere with other `.js` files
117117

118118
- [indent](https://eslint.org/docs/rules/indent)
119119
- [vue/html-indent](./html-indent.md)
120-
- [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md). The `vue/script-indent` rule does not understand TypeScript AST. Please use `@typescript-eslint/indent` rule instead of this one inside of `<script lang="ts"`
120+
- [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md)
121121

122122
## :rocket: Version
123123

lib/rules/no-restricted-component-options.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ function parseOption(option) {
5050
}
5151

5252
/**
53-
* @typedef {object} Step
54-
* @property {Matcher} [test]
55-
* @property {boolean} [wildcard]
53+
* @typedef {object} StepForTest
54+
* @property {Matcher} test
55+
* @property {undefined} [wildcard]
56+
* @typedef {object} StepForWildcard
57+
* @property {undefined} [test]
58+
* @property {true} wildcard
59+
* @typedef {StepForTest | StepForWildcard} Step
5660
*/
5761

5862
/** @type {Step[]} */
@@ -76,28 +80,28 @@ function parseOption(option) {
7680
* @returns {Tester}
7781
*/
7882
function buildTester(index) {
79-
const { wildcard, test } = steps[index]
83+
const step = steps[index]
8084
const next = index + 1
8185
const needNext = steps.length > next
8286
return (node) => {
8387
/** @type {string} */
8488
let keyName
85-
if (wildcard) {
89+
if (step.wildcard) {
8690
keyName = '*'
8791
} else {
8892
if (node.type !== 'Property') {
8993
return null
9094
}
9195
const name = utils.getStaticPropertyName(node)
92-
if (!name || !test(name)) {
96+
if (!name || !step.test(name)) {
9397
return null
9498
}
9599
keyName = name
96100
}
97101

98102
return {
99103
next: needNext ? buildTester(next) : undefined,
100-
wildcard,
104+
wildcard: step.wildcard,
101105
keyName
102106
}
103107
}

lib/rules/order-in-components.js

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function isNotSideEffectsNode(node, visitorKeys) {
156156
let skipNode = null
157157
traverseNodes(node, {
158158
visitorKeys,
159+
/** @param {ASTNode} node */
159160
enterNode(node) {
160161
if (!result || skipNode) {
161162
return
@@ -193,6 +194,7 @@ function isNotSideEffectsNode(node, visitorKeys) {
193194
result = false
194195
}
195196
},
197+
/** @param {ASTNode} node */
196198
leaveNode(node) {
197199
if (skipNode === node) {
198200
skipNode = null

lib/rules/sort-keys.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ module.exports = {
206206
''
207207
chainLevel = 1
208208
} else {
209-
propName = upperVueState.propName
210-
chainLevel = upperVueState.chainLevel + 1
209+
propName = upperVueState.propName || ''
210+
chainLevel = (upperVueState.chainLevel || 0) + 1
211211
}
212212
vueState.propName = propName
213213
vueState.chainLevel = chainLevel

lib/utils/html-comments.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function defineParser(sourceCode, config) {
110110

111111
/**
112112
* Parse HTMLComment.
113-
* @param {ASTToken} node a comment token
114-
* @returns {HTMLComment | null} the result of HTMLComment tokens.
113+
* @param {Token} node a comment token
114+
* @returns {ParsedHTMLComment | null} the result of HTMLComment tokens.
115115
*/
116116
return function parseHTMLComment(node) {
117117
if (node.type !== 'HTMLComment') {

0 commit comments

Comments
 (0)