Files
next.js/.config/ast-grep/rules/no-err-anyhow.yml
Matt MastracciandGitHub 1bc8f55993 Add Err(anyhow(... ast-grep rule (#90869)
# What

Add an ast-grep rule to use `bail!` rather than `Err(anyhow!(` in a
return position.

# Why

This is slightly more compact, and allows us to port more code over to
turbofmt/turbobail.

Note: _this PR was previously merged into another branch due to a GH
bug_
2026-03-04 09:08:55 -07:00

39 lines
991 B
YAML

# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
id: no-err-anyhow
message: Use `bail!()` instead of `Err(anyhow!())`.
note: The `bail!` macro from anyhow is more concise and idiomatic.
severity: error
language: Rust
rule:
all:
- any:
- pattern: Err(anyhow!($$$ARGS))
- pattern: Err(anyhow::anyhow!($$$ARGS))
- not:
inside:
kind: arguments
stopBy:
any:
- kind: block
- kind: closure_expression
- not:
inside:
kind: assignment_expression
stopBy:
any:
- kind: block
- kind: closure_expression
- not:
inside:
kind: let_declaration
stopBy:
any:
- kind: block
- kind: closure_expression
- not:
inside:
kind: field_expression
stopBy:
kind: call_expression