From 38ec5303fcc8f59d1c4350f71401675763fbda31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= <42278642+schoero@users.noreply.github.com> Date: Wed, 4 Mar 2026 17:42:25 +0100 Subject: [PATCH] refactor: lint concatenated strings --- src/parsers/es.test.ts | 2 +- src/parsers/es.ts | 8 ++++---- src/parsers/svelte.ts | 8 ++++---- src/parsers/vue.ts | 8 ++++---- src/utils/matchers.ts | 9 ++++++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/parsers/es.test.ts b/src/parsers/es.test.ts index 703bdda..f06d16d 100644 --- a/src/parsers/es.test.ts +++ b/src/parsers/es.test.ts @@ -235,7 +235,7 @@ describe("es", () => { }); // #234 - it("should ignore literals in binary expressions", () => { + it("should ignore literals in binary comparisons", () => { lint(noUnnecessaryWhitespace, { valid: [ { diff --git a/src/parsers/es.ts b/src/parsers/es.ts index e4d0bc9..dc87b64 100644 --- a/src/parsers/es.ts +++ b/src/parsers/es.ts @@ -3,8 +3,8 @@ import { findMatchingParentNodes, getLiteralNodesByMatchers, isIndexedAccessLiteral, - isInsideBinaryExpression, isInsideConditionalExpressionTest, + isInsideDisallowedBinaryExpression, isInsideLogicalExpressionLeft, isInsideMemberExpression, matchesPathPattern @@ -619,7 +619,7 @@ function getESMatcherFunctions(matchers: SelectorMatcher[]): MatcherFunctions): boo return isInsideConditionalExpressionTest(node.parent); } -export function isInsideBinaryExpression(node: WithParent): boolean { +export function isInsideDisallowedBinaryExpression(node: WithParent): boolean { if(!hasESNodeParentExtension(node)){ return false; } - if(node.parent.type === "BinaryExpression"){ return true; } - return isInsideBinaryExpression(node.parent); + if( + node.parent.type === "BinaryExpression" && + node.parent.operator !== "+" // allow string concatenation + ){ return true; } + return isInsideDisallowedBinaryExpression(node.parent); } export function isInsideLogicalExpressionLeft(node: WithParent): boolean {