From a438d34fcd21b5bc88bd9b08a153efc08e64ffec Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Thu, 27 Aug 2026 19:11:03 -0400 Subject: [PATCH] chore: lint identity pipe callbacks (#45771) --- .../no-identity-pipe-snapshot.yml | 38 +++++++++++++++++++ .../no-identity-pipe-tsx-snapshot.yml | 38 +++++++++++++++++++ .../rule-tests/no-identity-pipe-test.yml | 18 +++++++++ .../rule-tests/no-identity-pipe-tsx-test.yml | 17 +++++++++ .../rules/no-identity-pipe-tsx.yml | 12 ++++++ .../rules/no-identity-pipe.yml | 12 ++++++ 6 files changed, 135 insertions(+) create mode 100644 script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-snapshot.yml create mode 100644 script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-tsx-snapshot.yml create mode 100644 script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-test.yml create mode 100644 script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-tsx-test.yml create mode 100644 script/ast-grep/effect-simplifications/rules/no-identity-pipe-tsx.yml create mode 100644 script/ast-grep/effect-simplifications/rules/no-identity-pipe.yml diff --git a/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-snapshot.yml b/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-snapshot.yml new file mode 100644 index 00000000000..d7862f43681 --- /dev/null +++ b/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-snapshot.yml @@ -0,0 +1,38 @@ +id: no-identity-pipe +snapshots: + schema.pipe((value) => value): + labels: + - source: schema.pipe((value) => value) + style: primary + start: 0 + end: 29 + schema.pipe((value) => { return value }): + labels: + - source: schema.pipe((value) => { return value }) + style: primary + start: 0 + end: 40 + "schema.pipe((value: Schema) => value)": + labels: + - source: "schema.pipe((value: Schema) => value)" + style: primary + start: 0 + end: 37 + "schema.pipe((value: Schema) => { return value })": + labels: + - source: "schema.pipe((value: Schema) => { return value })" + style: primary + start: 0 + end: 48 + schema.pipe(value => value): + labels: + - source: schema.pipe(value => value) + style: primary + start: 0 + end: 27 + schema.pipe(value => { return value }): + labels: + - source: schema.pipe(value => { return value }) + style: primary + start: 0 + end: 38 diff --git a/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-tsx-snapshot.yml b/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-tsx-snapshot.yml new file mode 100644 index 00000000000..9f4b278c1e0 --- /dev/null +++ b/script/ast-grep/effect-simplifications/rule-tests/__snapshots__/no-identity-pipe-tsx-snapshot.yml @@ -0,0 +1,38 @@ +id: no-identity-pipe-tsx +snapshots: + const view = value)} />: + labels: + - source: schema.pipe((value) => value) + style: primary + start: 28 + end: 57 + const view = { return value })} />: + labels: + - source: schema.pipe((value) => { return value }) + style: primary + start: 28 + end: 68 + "const view = value)} />": + labels: + - source: "schema.pipe((value: Schema) => value)" + style: primary + start: 28 + end: 65 + "const view = { return value })} />": + labels: + - source: "schema.pipe((value: Schema) => { return value })" + style: primary + start: 28 + end: 76 + const view = value)} />: + labels: + - source: schema.pipe(value => value) + style: primary + start: 28 + end: 55 + const view = { return value })} />: + labels: + - source: schema.pipe(value => { return value }) + style: primary + start: 28 + end: 66 diff --git a/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-test.yml b/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-test.yml new file mode 100644 index 00000000000..767166c09f7 --- /dev/null +++ b/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-test.yml @@ -0,0 +1,18 @@ +id: no-identity-pipe +valid: + - schema + - schema.pipe(transform) + - schema.pipe((value) => transform(value)) + - schema.pipe((value) => other) + - schema.pipe((value) => { log(value); return value }) + - schema.pipe((value = fallback) => value) + - schema.pipe(({ value }) => value) + - schema.pipe((value) => value, transform) + - other.call((value) => value) +invalid: + - schema.pipe((value) => value) + - schema.pipe(value => value) + - "schema.pipe((value: Schema) => value)" + - schema.pipe((value) => { return value }) + - schema.pipe(value => { return value }) + - "schema.pipe((value: Schema) => { return value })" diff --git a/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-tsx-test.yml b/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-tsx-test.yml new file mode 100644 index 00000000000..219d9add1e9 --- /dev/null +++ b/script/ast-grep/effect-simplifications/rule-tests/no-identity-pipe-tsx-test.yml @@ -0,0 +1,17 @@ +id: no-identity-pipe-tsx +valid: + - const view = + - const view = + - const view = transform(value))} /> + - const view = other)} /> + - const view = { log(value); return value })} /> + - const view = value)} /> + - const view = value)} /> + - const view = value, transform)} /> +invalid: + - const view = value)} /> + - const view = value)} /> + - "const view = value)} />" + - const view = { return value })} /> + - const view = { return value })} /> + - "const view = { return value })} />" diff --git a/script/ast-grep/effect-simplifications/rules/no-identity-pipe-tsx.yml b/script/ast-grep/effect-simplifications/rules/no-identity-pipe-tsx.yml new file mode 100644 index 00000000000..90e454d4cf9 --- /dev/null +++ b/script/ast-grep/effect-simplifications/rules/no-identity-pipe-tsx.yml @@ -0,0 +1,12 @@ +id: no-identity-pipe-tsx +language: Tsx +message: Remove identity callbacks from pipe calls. +severity: error +rule: + any: + - pattern: $RECEIVER.pipe(($VALUE) => $VALUE) + - pattern: $RECEIVER.pipe($VALUE => $VALUE) + - pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => $VALUE)" + - pattern: $RECEIVER.pipe(($VALUE) => { return $VALUE }) + - pattern: $RECEIVER.pipe($VALUE => { return $VALUE }) + - pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => { return $VALUE })" diff --git a/script/ast-grep/effect-simplifications/rules/no-identity-pipe.yml b/script/ast-grep/effect-simplifications/rules/no-identity-pipe.yml new file mode 100644 index 00000000000..163801a220b --- /dev/null +++ b/script/ast-grep/effect-simplifications/rules/no-identity-pipe.yml @@ -0,0 +1,12 @@ +id: no-identity-pipe +language: TypeScript +message: Remove identity callbacks from pipe calls. +severity: error +rule: + any: + - pattern: $RECEIVER.pipe(($VALUE) => $VALUE) + - pattern: $RECEIVER.pipe($VALUE => $VALUE) + - pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => $VALUE)" + - pattern: $RECEIVER.pipe(($VALUE) => { return $VALUE }) + - pattern: $RECEIVER.pipe($VALUE => { return $VALUE }) + - pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => { return $VALUE })"