Skip to content

Commit 57f8deb

Browse files
committed
update
1 parent 7e71af1 commit 57f8deb

30 files changed

+704
-224
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 & 38 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,30 +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 {Property|MethodDefinition|PropertyDefinition} node The property node to collect prefix tokens.
483-
*/
484-
function getPrefixTokens(node, keyNode) {
485-
const prefixes = []
486-
487-
/** @type {Token|null} */
488-
let token = tokenStore.getFirstToken(node)
489-
while (token != null && token.range[1] <= keyNode.range[0]) {
490-
prefixes.push(token)
491-
token = tokenStore.getTokenAfter(token)
492-
}
493-
while (
494-
isOpeningParenToken(prefixes[prefixes.length - 1]) ||
495-
isOpeningBracketToken(prefixes[prefixes.length - 1])
496-
) {
497-
prefixes.pop()
498-
}
499-
500-
return prefixes
501-
}
502-
503484
/**
504485
* Find the head of chaining nodes.
505486
* @param {ASTNode} node The start node to find the head.
@@ -1848,7 +1829,6 @@ module.exports.defineVisitor = function create(
18481829
tokenStore,
18491830
setOffset,
18501831
copyOffset,
1851-
getPrefixTokens,
18521832
processSemicolons,
18531833
getFirstAndLastTokens
18541834
})
@@ -1892,9 +1872,10 @@ module.exports.defineVisitor = function create(
18921872

18931873
// Validate indentation of tokens.
18941874
for (const token of tokenStore.getTokens(node, ITERATION_OPTS)) {
1875+
const tokenStartLine = token.loc.start.line
18951876
if (
18961877
tokensOnSameLine.length === 0 ||
1897-
tokensOnSameLine[0].loc.start.line === token.loc.start.line
1878+
tokensOnSameLine[0].loc.start.line === tokenStartLine
18981879
) {
18991880
// This is on the same line (or the first token).
19001881
tokensOnSameLine.push(token)
@@ -1904,7 +1885,7 @@ module.exports.defineVisitor = function create(
19041885
comments.push(tokensOnSameLine[0])
19051886
isBesideMultilineToken =
19061887
/** @type {Token} */ (last(tokensOnSameLine)).loc.end.line ===
1907-
token.loc.start.line
1888+
tokenStartLine
19081889
tokensOnSameLine = [token]
19091890
} else {
19101891
// New line is detected, so validate the tokens.
@@ -1914,7 +1895,7 @@ module.exports.defineVisitor = function create(
19141895
}
19151896
isBesideMultilineToken =
19161897
/** @type {Token} */ (last(tokensOnSameLine)).loc.end.line ===
1917-
token.loc.start.line
1898+
tokenStartLine
19181899
tokensOnSameLine = [token]
19191900
comments = []
19201901
}

0 commit comments

Comments
 (0)