Skip to content

Commit 5445433

Browse files
committed
Merge branch 'main' into block-lang
2 parents 1b9074b + 2e61c7a commit 5445433

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# eslint-plugin-svelte
22

3+
## 2.19.2
4+
5+
### Patch Changes
6+
7+
- [#387](https://github.com/ota-meshi/eslint-plugin-svelte/pull/387) [`6422ee8`](https://github.com/ota-meshi/eslint-plugin-svelte/commit/6422ee89fcb5c8cefceda7dfa5b78e411c27f557) Thanks [@ota-meshi](https://github.com/ota-meshi)! - fix: false positive for element in `svelte/no-unused-svelte-ignore`
8+
39
## 2.19.1
410

511
### Patch Changes

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-svelte",
3-
"version": "2.19.1",
3+
"version": "2.19.2",
44
"description": "ESLint plugin for Svelte using AST",
55
"repository": "git+https://github.com/ota-meshi/eslint-plugin-svelte.git",
66
"homepage": "https://ota-meshi.github.io/eslint-plugin-svelte",

src/shared/svelte-compile-warns/index.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,30 @@ function processIgnore(
511511

512512
/** Get warning node */
513513
function getWarningNode(warning: Warning) {
514-
const index = getWarningIndex(warning)
515-
if (index == null) {
516-
return null
514+
const indexes = getWarningIndexes(warning)
515+
if (indexes.start != null) {
516+
const node = getWarningTargetNodeFromIndex(indexes.start)
517+
if (node) {
518+
return node
519+
}
520+
if (indexes.end != null) {
521+
const center = Math.floor(
522+
indexes.start + (indexes.end - indexes.start) / 2,
523+
)
524+
return getWarningTargetNodeFromIndex(center)
525+
}
526+
}
527+
if (indexes.end != null) {
528+
return getWarningTargetNodeFromIndex(indexes.end)
517529
}
530+
531+
return null
532+
}
533+
534+
/**
535+
* Get warning target node from the given index
536+
*/
537+
function getWarningTargetNodeFromIndex(index: number) {
518538
let targetNode = sourceCode.getNodeByRangeIndex(index)
519539
while (targetNode) {
520540
if (
@@ -535,18 +555,14 @@ function processIgnore(
535555
}
536556
targetNode = targetNode.parent || null
537557
}
538-
539558
return null
540559
}
541560

542561
/** Get warning index */
543-
function getWarningIndex(warning: Warning) {
562+
function getWarningIndexes(warning: Warning) {
544563
const start = warning.start && sourceCode.getIndexFromLoc(warning.start)
545564
const end = warning.end && sourceCode.getIndexFromLoc(warning.end)
546-
if (start != null && end != null) {
547-
return Math.floor(start + (end - start) / 2)
548-
}
549-
return start ?? end
565+
return { start, end }
550566
}
551567
}
552568

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
2+
<span tabindex="0">
3+
<span class="element" />
4+
</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
2+
<span tabindex="0">
3+
<span class="element" />
4+
</span>

0 commit comments

Comments
 (0)