Skip to content

Commit 66a559a

Browse files
committed
update
1 parent e3bd9a1 commit 66a559a

30 files changed

+704
-225
lines changed

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

Lines changed: 11 additions & 7 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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') {

lib/utils/indent-common.js

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const {
3232
} = require('./indent-utils')
3333
const { defineVisitor: tsDefineVisitor } = require('./indent-ts')
3434

35+
/**
36+
* @typedef {import('../../typings/eslint-plugin-vue/util-types/node').HasLocation} HasLocation
37+
* @typedef { { type: string } & HasLocation } MaybeNode
38+
*/
39+
3540
// ------------------------------------------------------------------------------
3641
// Helpers
3742
// ------------------------------------------------------------------------------
@@ -103,10 +108,10 @@ function parseOptions(type, options, defaultOptions) {
103108
ret.indentSize = 1
104109
}
105110

106-
if (Number.isSafeInteger(options.baseIndent)) {
111+
if (options.baseIndent != null && Number.isSafeInteger(options.baseIndent)) {
107112
ret.baseIndent = options.baseIndent
108113
}
109-
if (Number.isSafeInteger(options.attribute)) {
114+
if (options.attribute != null && Number.isSafeInteger(options.attribute)) {
110115
ret.attribute = options.attribute
111116
}
112117
if (Number.isSafeInteger(options.closeBracket)) {
@@ -126,7 +131,7 @@ function parseOptions(type, options, defaultOptions) {
126131
options.closeBracket
127132
)
128133
}
129-
if (Number.isSafeInteger(options.switchCase)) {
134+
if (options.switchCase != null && Number.isSafeInteger(options.switchCase)) {
130135
ret.switchCase = options.switchCase
131136
}
132137

@@ -142,9 +147,9 @@ function parseOptions(type, options, defaultOptions) {
142147

143148
/**
144149
* Check whether the node is at the beginning of line.
145-
* @param {ASTNode|null} node The node to check.
150+
* @param {MaybeNode|null} node The node to check.
146151
* @param {number} index The index of the node in the nodes.
147-
* @param {(ASTNode|null)[]} nodes The array of nodes.
152+
* @param {(MaybeNode|null)[]} nodes The array of nodes.
148153
* @returns {boolean} `true` if the node is at the beginning of line.
149154
*/
150155
function isBeginningOfLine(node, index, nodes) {
@@ -307,7 +312,7 @@ module.exports.defineVisitor = function create(
307312
/**
308313
* Get the first and last tokens of the given node.
309314
* If the node is parenthesized, this gets the outermost parentheses.
310-
* @param {ASTNode} node The node to get.
315+
* @param {MaybeNode} node The node to get.
311316
* @param {number} [borderOffset] The least offset of the first token. Defailt is 0. This value is used to prevent false positive in the following case: `(a) => {}` The parentheses are enclosing the whole parameter part rather than the first parameter, but this offset parameter is needed to distinguish.
312317
* @returns {{firstToken:Token,lastToken:Token}} The gotten tokens.
313318
*/
@@ -337,9 +342,9 @@ module.exports.defineVisitor = function create(
337342
* Process the given node list.
338343
* The first node is offsetted from the given left token.
339344
* Rest nodes are adjusted to the first node.
340-
* @param {(ASTNode|null)[]} nodeList The node to process.
341-
* @param {ASTNode|Token|null} left The left parenthesis token.
342-
* @param {ASTNode|Token|null} right The right parenthesis token.
345+
* @param {(MaybeNode|null)[]} nodeList The node to process.
346+
* @param {MaybeNode|Token|null} left The left parenthesis token.
347+
* @param {MaybeNode|Token|null} right The right parenthesis token.
343348
* @param {number} offset The offset to set.
344349
* @param {boolean} [alignVertically=true] The flag to align vertically. If `false`, this doesn't align vertically even if the first node is not at beginning of line.
345350
* @returns {void}
@@ -450,7 +455,7 @@ module.exports.defineVisitor = function create(
450455

451456
/**
452457
* Process semicolons of the given statement node.
453-
* @param {ASTNode} node The statement node to process.
458+
* @param {MaybeNode} node The statement node to process.
454459
* @returns {void}
455460
*/
456461
function processSemicolons(node) {
@@ -476,31 +481,6 @@ module.exports.defineVisitor = function create(
476481
}
477482
}
478483

479-
/**
480-
* Collect prefix tokens of the given property.
481-
* The prefix includes `async`, `get`, `set`, `static`, and `*`.
482-
* @param {ASTNode} node The property node to collect prefix tokens.
483-
* @param {ASTNode | Token} keyNode The key node.
484-
*/
485-
function getPrefixTokens(node, keyNode) {
486-
const prefixes = []
487-
488-
/** @type {Token|null} */
489-
let token = tokenStore.getFirstToken(node)
490-
while (token != null && token.range[1] <= keyNode.range[0]) {
491-
prefixes.push(token)
492-
token = tokenStore.getTokenAfter(token)
493-
}
494-
while (
495-
isOpeningParenToken(prefixes[prefixes.length - 1]) ||
496-
isOpeningBracketToken(prefixes[prefixes.length - 1])
497-
) {
498-
prefixes.pop()
499-
}
500-
501-
return prefixes
502-
}
503-
504484
/**
505485
* Find the head of chaining nodes.
506486
* @param {ASTNode} node The start node to find the head.
@@ -1849,7 +1829,6 @@ module.exports.defineVisitor = function create(
18491829
tokenStore,
18501830
setOffset,
18511831
copyOffset,
1852-
getPrefixTokens,
18531832
processSemicolons,
18541833
getFirstAndLastTokens
18551834
})
@@ -1893,9 +1872,10 @@ module.exports.defineVisitor = function create(
18931872

18941873
// Validate indentation of tokens.
18951874
for (const token of tokenStore.getTokens(node, ITERATION_OPTS)) {
1875+
const tokenStartLine = token.loc.start.line
18961876
if (
18971877
tokensOnSameLine.length === 0 ||
1898-
tokensOnSameLine[0].loc.start.line === token.loc.start.line
1878+
tokensOnSameLine[0].loc.start.line === tokenStartLine
18991879
) {
19001880
// This is on the same line (or the first token).
19011881
tokensOnSameLine.push(token)
@@ -1905,7 +1885,7 @@ module.exports.defineVisitor = function create(
19051885
comments.push(tokensOnSameLine[0])
19061886
isBesideMultilineToken =
19071887
/** @type {Token} */ (last(tokensOnSameLine)).loc.end.line ===
1908-
token.loc.start.line
1888+
tokenStartLine
19091889
tokensOnSameLine = [token]
19101890
} else {
19111891
// New line is detected, so validate the tokens.
@@ -1915,7 +1895,7 @@ module.exports.defineVisitor = function create(
19151895
}
19161896
isBesideMultilineToken =
19171897
/** @type {Token} */ (last(tokensOnSameLine)).loc.end.line ===
1918-
token.loc.start.line
1898+
tokenStartLine
19191899
tokensOnSameLine = [token]
19201900
comments = []
19211901
}

0 commit comments

Comments
 (0)