Skip to content

Commit a438d34

Browse files
authored
chore: lint identity pipe callbacks (anomalyco#45771)
1 parent fa7a1ca commit a438d34

6 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
id: no-identity-pipe
2+
snapshots:
3+
schema.pipe((value) => value):
4+
labels:
5+
- source: schema.pipe((value) => value)
6+
style: primary
7+
start: 0
8+
end: 29
9+
schema.pipe((value) => { return value }):
10+
labels:
11+
- source: schema.pipe((value) => { return value })
12+
style: primary
13+
start: 0
14+
end: 40
15+
"schema.pipe((value: Schema) => value)":
16+
labels:
17+
- source: "schema.pipe((value: Schema) => value)"
18+
style: primary
19+
start: 0
20+
end: 37
21+
"schema.pipe((value: Schema) => { return value })":
22+
labels:
23+
- source: "schema.pipe((value: Schema) => { return value })"
24+
style: primary
25+
start: 0
26+
end: 48
27+
schema.pipe(value => value):
28+
labels:
29+
- source: schema.pipe(value => value)
30+
style: primary
31+
start: 0
32+
end: 27
33+
schema.pipe(value => { return value }):
34+
labels:
35+
- source: schema.pipe(value => { return value })
36+
style: primary
37+
start: 0
38+
end: 38
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
id: no-identity-pipe-tsx
2+
snapshots:
3+
const view = <Widget value={schema.pipe((value) => value)} />:
4+
labels:
5+
- source: schema.pipe((value) => value)
6+
style: primary
7+
start: 28
8+
end: 57
9+
const view = <Widget value={schema.pipe((value) => { return value })} />:
10+
labels:
11+
- source: schema.pipe((value) => { return value })
12+
style: primary
13+
start: 28
14+
end: 68
15+
"const view = <Widget value={schema.pipe((value: Schema) => value)} />":
16+
labels:
17+
- source: "schema.pipe((value: Schema) => value)"
18+
style: primary
19+
start: 28
20+
end: 65
21+
"const view = <Widget value={schema.pipe((value: Schema) => { return value })} />":
22+
labels:
23+
- source: "schema.pipe((value: Schema) => { return value })"
24+
style: primary
25+
start: 28
26+
end: 76
27+
const view = <Widget value={schema.pipe(value => value)} />:
28+
labels:
29+
- source: schema.pipe(value => value)
30+
style: primary
31+
start: 28
32+
end: 55
33+
const view = <Widget value={schema.pipe(value => { return value })} />:
34+
labels:
35+
- source: schema.pipe(value => { return value })
36+
style: primary
37+
start: 28
38+
end: 66
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: no-identity-pipe
2+
valid:
3+
- schema
4+
- schema.pipe(transform)
5+
- schema.pipe((value) => transform(value))
6+
- schema.pipe((value) => other)
7+
- schema.pipe((value) => { log(value); return value })
8+
- schema.pipe((value = fallback) => value)
9+
- schema.pipe(({ value }) => value)
10+
- schema.pipe((value) => value, transform)
11+
- other.call((value) => value)
12+
invalid:
13+
- schema.pipe((value) => value)
14+
- schema.pipe(value => value)
15+
- "schema.pipe((value: Schema) => value)"
16+
- schema.pipe((value) => { return value })
17+
- schema.pipe(value => { return value })
18+
- "schema.pipe((value: Schema) => { return value })"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
id: no-identity-pipe-tsx
2+
valid:
3+
- const view = <Widget value={schema} />
4+
- const view = <Widget value={schema.pipe(transform)} />
5+
- const view = <Widget value={schema.pipe((value) => transform(value))} />
6+
- const view = <Widget value={schema.pipe((value) => other)} />
7+
- const view = <Widget value={schema.pipe((value) => { log(value); return value })} />
8+
- const view = <Widget value={schema.pipe((value = fallback) => value)} />
9+
- const view = <Widget value={schema.pipe(({ value }) => value)} />
10+
- const view = <Widget value={schema.pipe((value) => value, transform)} />
11+
invalid:
12+
- const view = <Widget value={schema.pipe((value) => value)} />
13+
- const view = <Widget value={schema.pipe(value => value)} />
14+
- "const view = <Widget value={schema.pipe((value: Schema) => value)} />"
15+
- const view = <Widget value={schema.pipe((value) => { return value })} />
16+
- const view = <Widget value={schema.pipe(value => { return value })} />
17+
- "const view = <Widget value={schema.pipe((value: Schema) => { return value })} />"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
id: no-identity-pipe-tsx
2+
language: Tsx
3+
message: Remove identity callbacks from pipe calls.
4+
severity: error
5+
rule:
6+
any:
7+
- pattern: $RECEIVER.pipe(($VALUE) => $VALUE)
8+
- pattern: $RECEIVER.pipe($VALUE => $VALUE)
9+
- pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => $VALUE)"
10+
- pattern: $RECEIVER.pipe(($VALUE) => { return $VALUE })
11+
- pattern: $RECEIVER.pipe($VALUE => { return $VALUE })
12+
- pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => { return $VALUE })"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
id: no-identity-pipe
2+
language: TypeScript
3+
message: Remove identity callbacks from pipe calls.
4+
severity: error
5+
rule:
6+
any:
7+
- pattern: $RECEIVER.pipe(($VALUE) => $VALUE)
8+
- pattern: $RECEIVER.pipe($VALUE => $VALUE)
9+
- pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => $VALUE)"
10+
- pattern: $RECEIVER.pipe(($VALUE) => { return $VALUE })
11+
- pattern: $RECEIVER.pipe($VALUE => { return $VALUE })
12+
- pattern: "$RECEIVER.pipe(($VALUE: $TYPE) => { return $VALUE })"

0 commit comments

Comments
 (0)