Skip to content

Commit 9adaecf

Browse files
authored
Merge branch 'master' into cleanup
2 parents f42464a + 58e2197 commit 9adaecf

File tree

9 files changed

+53
-29
lines changed

9 files changed

+53
-29
lines changed

.changeset/rich-bags-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": patch
3+
---
4+
5+
Fixed false positives for `TSImportType` in `vue/script-indent` rule

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# eslint-plugin-vue
22

3+
## 10.6.1
4+
5+
### Patch Changes
6+
7+
- Fixed false positives for comments outside `<template>` in [`vue/no-multiple-template-root`](https://eslint.vuejs.org/rules/no-multiple-template-root.html) rule ([#2964](https://github.com/vuejs/eslint-plugin-vue/pull/2964))
8+
39
## 10.6.0
410

511
### Minor Changes

docs/.vitepress/build-system/build.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ build(
2323
'node:fs',
2424
'semver',
2525
'fast-glob',
26+
'tinyglobby',
2627
'debug'
2728
]
2829
)

docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default async () => {
162162
tslib: path.join(dirname, '../../node_modules/tslib/tslib.es6.js'),
163163
globby: path.join(dirname, './build-system/shim/empty.mjs'),
164164
'fast-glob': path.join(dirname, './build-system/shim/empty.mjs'),
165+
tinyglobby: path.join(dirname, './build-system/shim/empty.mjs'),
165166
module: path.join(dirname, './build-system/shim/empty.mjs')
166167
}
167168
},

lib/rules/no-multiple-template-root.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@
66

77
const utils = require('../utils')
88

9-
/**
10-
* Get all comments that need to be reported
11-
* @param {(HTMLComment | HTMLBogusComment | Comment)[]} comments
12-
* @param {Range[]} elementRanges
13-
* @returns {(HTMLComment | HTMLBogusComment | Comment)[]}
14-
*/
15-
function getReportComments(comments, elementRanges) {
16-
return comments.filter(
17-
(comment) =>
18-
!elementRanges.some(
19-
(range) => range[0] <= comment.range[0] && comment.range[1] <= range[1]
20-
)
21-
)
22-
}
23-
249
module.exports = {
2510
meta: {
2611
type: 'problem',
@@ -65,10 +50,13 @@ module.exports = {
6550
return
6651
}
6752

68-
const comments = element.comments
69-
const elementRanges = element.children.map((child) => child.range)
70-
if (disallowComments && comments.length > 0) {
71-
for (const comment of getReportComments(comments, elementRanges)) {
53+
const reportComments = element.comments.filter(
54+
(comment) =>
55+
utils.inRange(element, comment) &&
56+
!element.children.some((child) => utils.inRange(child, comment))
57+
)
58+
if (disallowComments) {
59+
for (const comment of reportComments) {
7260
context.report({
7361
node: comment,
7462
loc: comment.loc,

lib/utils/indent-ts.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,14 +1199,25 @@ function defineVisitor({
11991199
isOpeningParenToken
12001200
)
12011201
setOffset(leftParenToken, 1, firstToken)
1202-
const argument =
1203-
node.argument ||
1204-
/** @type {any} typescript-eslint v5 */ (node).parameter
1202+
1203+
const args = []
1204+
if (node.source) {
1205+
args.push(node.source)
1206+
} else {
1207+
// For old typescript-eslint parser
1208+
args.push(
1209+
node.argument ||
1210+
/** @type {any} typescript-eslint v5 */ (node).parameter
1211+
)
1212+
}
1213+
if (node.options) {
1214+
args.push(node.options)
1215+
}
12051216
const rightParenToken = tokenStore.getTokenAfter(
1206-
argument,
1217+
args[args.length - 1],
12071218
isClosingParenToken
12081219
)
1209-
processNodeList([argument], leftParenToken, rightParenToken, 1)
1220+
processNodeList(args, leftParenToken, rightParenToken, 1)
12101221
if (node.qualifier) {
12111222
const dotToken = tokenStore.getTokenBefore(node.qualifier)
12121223
const propertyToken = tokenStore.getTokenAfter(dotToken)

lib/utils/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,10 +1965,11 @@ module.exports = {
19651965
},
19661966
/**
19671967
* Checks whether the target node is within the given range.
1968-
* @param { [number, number] } range
1968+
* @param { [number, number] | ASTNode | Token } rangeOrNode
19691969
* @param {ASTNode | Token} target
19701970
*/
1971-
inRange(range, target) {
1971+
inRange(rangeOrNode, target) {
1972+
const range = Array.isArray(rangeOrNode) ? rangeOrNode : rangeOrNode.range
19721973
return range[0] <= target.range[0] && target.range[1] <= range[1]
19731974
},
19741975
/**

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "eslint-plugin-vue",
3-
"version": "10.6.0",
3+
"version": "10.6.1",
44
"description": "Official ESLint plugin for Vue.js",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"scripts": {
88
"new": "node tools/new-rule.js",
9-
"start": "npm run test:base -- --watch --growl",
9+
"start": "npm run test:base -- --watch",
1010
"test:base": "vitest run --reporter=dot tests/lib",
1111
"test": "vitest run",
1212
"test:integrations": "vitest run tests/integrations",

tests/lib/rules/no-multiple-template-root.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ ruleTester.run('no-multiple-template-root', rule, {
122122
</template>
123123
`,
124124
options: [{ disallowComments: true }]
125+
},
126+
127+
// https://github.com/vuejs/eslint-plugin-vue/issues/2948
128+
{
129+
code: `
130+
<!-- comment -->
131+
<template>
132+
<div>abc</div>
133+
</template>
134+
`,
135+
options: [{ disallowComments: true }]
125136
}
126137
],
127138
invalid: [
@@ -371,7 +382,7 @@ ruleTester.run('no-multiple-template-root', rule, {
371382
{
372383
code: `
373384
<template>
374-
<!-- When you have a comment in the root of your template in vue 3,
385+
<!-- When you have a comment in the root of your template in vue 3,
375386
using $el will point to the first text comment instead of the actual DOM element. -->
376387
<div>
377388
12333

0 commit comments

Comments
 (0)