Skip to content

Commit b742163

Browse files
authored
fix(no-navigation-without-resolve): properly detecting invalid binary expression operators (#1490)
1 parent e98c794 commit b742163

6 files changed

Lines changed: 33 additions & 3 deletions

File tree

.changeset/shy-things-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix(no-navigation-without-resolve): properly detecting invalid binary expression operators

packages/eslint-plugin-svelte/src/rules/no-navigation-without-resolve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ function binaryExpressionIsAbsoluteUrl(
384384
node: TSESTree.BinaryExpression
385385
): boolean {
386386
return (
387-
(node.left.type !== 'PrivateIdentifier' && expressionIsAbsoluteUrl(ctx, node.left)) ||
388-
expressionIsAbsoluteUrl(ctx, node.right)
387+
node.operator === '+' &&
388+
(expressionIsAbsoluteUrl(ctx, node.left) || expressionIsAbsoluteUrl(ctx, node.right))
389389
);
390390
}
391391

@@ -435,7 +435,7 @@ function binaryExpressionStartsWith(
435435
node: TSESTree.BinaryExpression,
436436
prefix: string
437437
): boolean {
438-
return node.left.type !== 'PrivateIdentifier' && expressionStartsWith(ctx, node.left, prefix);
438+
return node.operator === '+' && expressionStartsWith(ctx, node.left, prefix);
439439
}
440440

441441
function identifierStartsWith(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- message: Unexpected href link without resolve().
2+
line: 1
3+
column: 4
4+
suggestions: null
5+
- message: Unexpected href link without resolve().
6+
line: 2
7+
column: 4
8+
suggestions: null
9+
- message: Unexpected href link without resolve().
10+
line: 3
11+
column: 4
12+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<a href={'https://example.com' - '/foo'}>Click me!</a>
2+
<a href={'/foo' - 'https://example.com'}>Click me!</a>
3+
<a href={'https://' - 'example.com'}>Click me!</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- message: Unexpected href link without resolve().
2+
line: 1
3+
column: 4
4+
suggestions: null
5+
- message: Unexpected href link without resolve().
6+
line: 2
7+
column: 4
8+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<a href={'#section' - '/foo'}>Click me!</a>
2+
<a href={'#section' * '/foo'}>Click me!</a>

0 commit comments

Comments
 (0)