Skip to content

Commit 7b187fa

Browse files
authored
Linter: Allow nested parens in erb-strict-locals-comment-syntax rule (#1141)
Fixes #1119
1 parent c9d044e commit 7b187fa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

javascript/packages/linter/src/rules/erb-strict-locals-comment-syntax.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { hasBalancedParentheses, splitByTopLevelComma } from "./string-utils.js"
77
import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js"
88
import type { ParseResult, ERBContentNode } from "@herb-tools/core"
99

10-
export const STRICT_LOCALS_PATTERN = /^locals:\s+\([^)]*\)\s*$/
10+
export const STRICT_LOCALS_PATTERN = /^locals:\s+\(.*\)\s*$/s
1111

1212
function isValidStrictLocalsFormat(content: string): boolean {
1313
return STRICT_LOCALS_PATTERN.test(content)

javascript/packages/linter/test/rules/erb-strict-locals-comment-syntax.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ describe("ERBStrictLocalsCommentSyntaxRule", () => {
3030
expectNoOffenses(`<%# locals: (callback: -> { nil }) %>`)
3131
})
3232

33+
test("allows i18n method calls with parentheses as default values", () => {
34+
expectNoOffenses(`<%# locals: (title: t("translation_key_for.title"), message:) %>`)
35+
expectNoOffenses(`<%# locals: (label: I18n.t("key"), value:) %>`)
36+
expectNoOffenses(`<%# locals: (a: foo(bar(baz())), b:) %>`)
37+
})
38+
3339
test("allows double-splat for optional keyword arguments", () => {
3440
expectNoOffenses(`<%# locals: (message: "Hello", **attributes) %>`)
3541
expectNoOffenses(`<%# locals: (**options) %>`)

0 commit comments

Comments
 (0)