chore: enforce effect simplifications (#43979)
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
id: no-effect-and-then-succeed-undefined-tsx
|
||||
language: Tsx
|
||||
message: Use Effect.as(undefined) to preserve the exact undefined success type.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- pattern: Effect.andThen($$$SELF, Effect.succeed(undefined))
|
||||
- not:
|
||||
pattern: Effect.andThen($_FIRST, $_SECOND, $$$REST)
|
||||
@@ -0,0 +1,9 @@
|
||||
id: no-effect-and-then-succeed-undefined
|
||||
language: TypeScript
|
||||
message: Use Effect.as(undefined) to preserve the exact undefined success type.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- pattern: Effect.andThen($$$SELF, Effect.succeed(undefined))
|
||||
- not:
|
||||
pattern: Effect.andThen($_FIRST, $_SECOND, $$$REST)
|
||||
@@ -0,0 +1,61 @@
|
||||
id: no-effect-catch-succeed-tsx
|
||||
language: Tsx
|
||||
message: Use Effect.orElseSucceed for constant failure recovery.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- any:
|
||||
- pattern: Effect.catch($$$SELF, () => Effect.succeed($VALUE))
|
||||
- pattern: Effect.catch($$$SELF, () => { return Effect.succeed($VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, ($IGNORED) => Effect.succeed($IGNORED_VALUE))
|
||||
- pattern: Effect.catch($$$SELF, ($IGNORED) => { return Effect.succeed($IGNORED_VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, $IGNORED => Effect.succeed($IGNORED_VALUE))
|
||||
- pattern: Effect.catch($$$SELF, $IGNORED => { return Effect.succeed($IGNORED_VALUE) })
|
||||
- pattern: "Effect.catch($$$SELF, ($IGNORED: $_TYPE) => Effect.succeed($IGNORED_VALUE))"
|
||||
- pattern: "Effect.catch($$$SELF, ($IGNORED: $_TYPE) => { return Effect.succeed($IGNORED_VALUE) })"
|
||||
- pattern: Effect.catch($$$SELF, function () { return Effect.succeed($FUNCTION_VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, function ($FUNCTION_IGNORED) { return Effect.succeed($FUNCTION_IGNORED_VALUE) })
|
||||
- pattern: "Effect.catch($$$SELF, function ($FUNCTION_IGNORED: $_TYPE) { return Effect.succeed($FUNCTION_IGNORED_VALUE) })"
|
||||
- not:
|
||||
pattern: Effect.catch($_FIRST, $_SECOND, $$$REST)
|
||||
constraints:
|
||||
IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
IGNORED_VALUE:
|
||||
all:
|
||||
- not:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
- not:
|
||||
has:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
stopBy: end
|
||||
FUNCTION_VALUE:
|
||||
all:
|
||||
- not:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
FUNCTION_IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
FUNCTION_IGNORED_VALUE:
|
||||
all:
|
||||
- not:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
@@ -0,0 +1,61 @@
|
||||
id: no-effect-catch-succeed
|
||||
language: TypeScript
|
||||
message: Use Effect.orElseSucceed for constant failure recovery.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- any:
|
||||
- pattern: Effect.catch($$$SELF, () => Effect.succeed($VALUE))
|
||||
- pattern: Effect.catch($$$SELF, () => { return Effect.succeed($VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, ($IGNORED) => Effect.succeed($IGNORED_VALUE))
|
||||
- pattern: Effect.catch($$$SELF, ($IGNORED) => { return Effect.succeed($IGNORED_VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, $IGNORED => Effect.succeed($IGNORED_VALUE))
|
||||
- pattern: Effect.catch($$$SELF, $IGNORED => { return Effect.succeed($IGNORED_VALUE) })
|
||||
- pattern: "Effect.catch($$$SELF, ($IGNORED: $_TYPE) => Effect.succeed($IGNORED_VALUE))"
|
||||
- pattern: "Effect.catch($$$SELF, ($IGNORED: $_TYPE) => { return Effect.succeed($IGNORED_VALUE) })"
|
||||
- pattern: Effect.catch($$$SELF, function () { return Effect.succeed($FUNCTION_VALUE) })
|
||||
- pattern: Effect.catch($$$SELF, function ($FUNCTION_IGNORED) { return Effect.succeed($FUNCTION_IGNORED_VALUE) })
|
||||
- pattern: "Effect.catch($$$SELF, function ($FUNCTION_IGNORED: $_TYPE) { return Effect.succeed($FUNCTION_IGNORED_VALUE) })"
|
||||
- not:
|
||||
pattern: Effect.catch($_FIRST, $_SECOND, $$$REST)
|
||||
constraints:
|
||||
IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
IGNORED_VALUE:
|
||||
all:
|
||||
- not:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
- not:
|
||||
has:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
stopBy: end
|
||||
FUNCTION_VALUE:
|
||||
all:
|
||||
- not:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
FUNCTION_IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
FUNCTION_IGNORED_VALUE:
|
||||
all:
|
||||
- not:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
@@ -0,0 +1,54 @@
|
||||
id: no-effect-flat-map-suspend-tsx
|
||||
language: Tsx
|
||||
message: Use effect-form Effect.andThen when the previous value is ignored.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- any:
|
||||
- pattern: Effect.flatMap($$$SELF, () => Effect.suspend($THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, () => { return Effect.suspend($THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, ($IGNORED) => Effect.suspend($IGNORED_THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, ($IGNORED) => { return Effect.suspend($IGNORED_THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, $IGNORED => Effect.suspend($IGNORED_THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, $IGNORED => { return Effect.suspend($IGNORED_THUNK) })
|
||||
- pattern: "Effect.flatMap($$$SELF, ($IGNORED: $_TYPE) => Effect.suspend($IGNORED_THUNK))"
|
||||
- pattern: "Effect.flatMap($$$SELF, ($IGNORED: $_TYPE) => { return Effect.suspend($IGNORED_THUNK) })"
|
||||
- pattern: Effect.flatMap($$$SELF, function () { return Effect.suspend($FUNCTION_THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, function ($FUNCTION_IGNORED) { return Effect.suspend($FUNCTION_IGNORED_THUNK) })
|
||||
- pattern: "Effect.flatMap($$$SELF, function ($FUNCTION_IGNORED: $_TYPE) { return Effect.suspend($FUNCTION_IGNORED_THUNK) })"
|
||||
- not:
|
||||
pattern: Effect.flatMap($_FIRST, $_SECOND, $$$REST)
|
||||
constraints:
|
||||
THUNK:
|
||||
kind: arrow_function
|
||||
IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
IGNORED_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
stopBy: end
|
||||
FUNCTION_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
FUNCTION_IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
FUNCTION_IGNORED_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
@@ -0,0 +1,54 @@
|
||||
id: no-effect-flat-map-suspend
|
||||
language: TypeScript
|
||||
message: Use effect-form Effect.andThen when the previous value is ignored.
|
||||
severity: error
|
||||
rule:
|
||||
all:
|
||||
- any:
|
||||
- pattern: Effect.flatMap($$$SELF, () => Effect.suspend($THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, () => { return Effect.suspend($THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, ($IGNORED) => Effect.suspend($IGNORED_THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, ($IGNORED) => { return Effect.suspend($IGNORED_THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, $IGNORED => Effect.suspend($IGNORED_THUNK))
|
||||
- pattern: Effect.flatMap($$$SELF, $IGNORED => { return Effect.suspend($IGNORED_THUNK) })
|
||||
- pattern: "Effect.flatMap($$$SELF, ($IGNORED: $_TYPE) => Effect.suspend($IGNORED_THUNK))"
|
||||
- pattern: "Effect.flatMap($$$SELF, ($IGNORED: $_TYPE) => { return Effect.suspend($IGNORED_THUNK) })"
|
||||
- pattern: Effect.flatMap($$$SELF, function () { return Effect.suspend($FUNCTION_THUNK) })
|
||||
- pattern: Effect.flatMap($$$SELF, function ($FUNCTION_IGNORED) { return Effect.suspend($FUNCTION_IGNORED_THUNK) })
|
||||
- pattern: "Effect.flatMap($$$SELF, function ($FUNCTION_IGNORED: $_TYPE) { return Effect.suspend($FUNCTION_IGNORED_THUNK) })"
|
||||
- not:
|
||||
pattern: Effect.flatMap($_FIRST, $_SECOND, $$$REST)
|
||||
constraints:
|
||||
THUNK:
|
||||
kind: arrow_function
|
||||
IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
IGNORED_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
regex: ^_[A-Za-z0-9_$]*$
|
||||
stopBy: end
|
||||
FUNCTION_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^arguments$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
FUNCTION_IGNORED:
|
||||
regex: ^_[A-Za-z0-9_$]*(?:\s*:\s*.+)?$
|
||||
FUNCTION_IGNORED_THUNK:
|
||||
all:
|
||||
- kind: arrow_function
|
||||
- not:
|
||||
has:
|
||||
any:
|
||||
- regex: ^(_[A-Za-z0-9_$]*|arguments)$
|
||||
- kind: this
|
||||
- kind: meta_property
|
||||
stopBy: end
|
||||
Reference in New Issue
Block a user