Skip to content

Commit cc4c9c6

Browse files
authored
fix: remove unusable filter from allowedArrayMethods in expressions (#5627)
filter requires a callback (arrow function) which is blocked by the linter's blanket "Functions are not supported" rule, making it effectively dead code. Remove it and update all related tests. ## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent cb92f50 commit cc4c9c6

File tree

3 files changed

+1
-31
lines changed

3 files changed

+1
-31
lines changed

apps/builder/app/builder/shared/expression-editor.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ describe("generateCompletionOptions", () => {
6464
expect(labels).toContain("1");
6565
expect(labels).toContain("2");
6666
expect(labels).toContain("length");
67-
expect(labels).toContain("filter()");
6867
expect(labels).toContain("slice()");
6968

7069
// Check specific values
@@ -76,22 +75,6 @@ describe("generateCompletionOptions", () => {
7675
});
7776
});
7877

79-
test("includes array methods when searching", () => {
80-
const target = [1, 2, 3];
81-
const options = generateCompletionOptions({
82-
target,
83-
pathName: "fil",
84-
pathLength: 1,
85-
});
86-
87-
const methodOptions = options.filter((o) => o.type === "method");
88-
expect(methodOptions).toContainEqual({
89-
label: "filter()",
90-
detail: "array method",
91-
type: "method",
92-
});
93-
});
94-
9578
test("filters length property by pathName", () => {
9679
const target = [1, 2, 3, 4, 5];
9780
const options = generateCompletionOptions({
@@ -233,7 +216,6 @@ describe("generateCompletionOptions", () => {
233216
// Empty array has length and all array methods
234217
const labels = options.map((o) => o.label);
235218
expect(labels).toContain("length");
236-
expect(labels).toContain("filter()");
237219
expect(labels).toContain("slice()");
238220

239221
const lengthOption = options.find((o) => o.label === "length");

packages/sdk/src/expression.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,6 @@ describe("transpile expression", () => {
456456
executable: true,
457457
})
458458
).toEqual("items?.map?.(item => item?.id)");
459-
expect(
460-
transpileExpression({
461-
expression: "data.list.filter(x => x > 0)",
462-
executable: true,
463-
})
464-
).toEqual("data?.list?.filter?.(x => x > 0)");
465459
});
466460

467461
test("transpile nested method calls with optional chaining", () => {

packages/sdk/src/expression.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ export const allowedStringMethods = new Set([
4343
"toLocaleUpperCase",
4444
]);
4545

46-
export const allowedArrayMethods = new Set([
47-
"at",
48-
"includes",
49-
"join",
50-
"slice",
51-
"filter",
52-
]);
46+
export const allowedArrayMethods = new Set(["at", "includes", "join", "slice"]);
5347

5448
export const lintExpression = ({
5549
expression,

0 commit comments

Comments
 (0)