mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
chore(rust): add ast-grep config and a custom lint rule
Adds sgconfig.yml scoped to litellm-rust plus a rule that flags format!() passed directly into an error constructor (Error::Variant(...), PyValueError::new_err(...), etc), since rustfmt wraps that into an unreadable multi-line call. Local/manual use only for now; not wired into make lint or CI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
b94f5bdbed
commit
e3637fde9f
3 changed files with 36 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
id: no-format-in-error-variant
|
||||
valid:
|
||||
- |
|
||||
fn f(route: &str) -> Result<(), Error> {
|
||||
let msg = format!("bad route: {route}");
|
||||
Err(Error::InvalidProvider(msg))
|
||||
}
|
||||
- |
|
||||
fn f() -> String {
|
||||
format!("just a string")
|
||||
}
|
||||
invalid:
|
||||
- |
|
||||
fn f(route: &str) -> Result<(), Error> {
|
||||
Err(Error::InvalidProvider(format!("bad route: {route}")))
|
||||
}
|
||||
- |
|
||||
fn f(name: &str) -> PyResult<()> {
|
||||
Err(PyValueError::new_err(format!("missing argument: {name}")))
|
||||
}
|
||||
12
litellm-rust/ast-grep/rules/no-format-in-error-variant.yml
Normal file
12
litellm-rust/ast-grep/rules/no-format-in-error-variant.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
id: no-format-in-error-variant
|
||||
language: rust
|
||||
severity: warning
|
||||
message: >-
|
||||
Don't build an error variant straight from a format!() call; rustfmt wraps it into an
|
||||
unreadable multi-line call. Bind the message to a local first, e.g.
|
||||
`let msg = format!(...); $PATH::$VARIANT(msg)`.
|
||||
rule:
|
||||
pattern: $PATH::$VARIANT(format!($$$ARGS))
|
||||
constraints:
|
||||
PATH:
|
||||
regex: 'Error$'
|
||||
4
litellm-rust/sgconfig.yml
Normal file
4
litellm-rust/sgconfig.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ruleDirs:
|
||||
- ast-grep/rules
|
||||
testConfigs:
|
||||
- testDir: ast-grep/rule-tests
|
||||
Loading…
Add table
Reference in a new issue