astral-sh/ruff · error
{e}
Error message
{e} What it means
`ty rule <name>` looks up the requested lint rule in ty's default lint registry and wraps any registry lookup error in this anyhow error (message is the registry's own error text). It means the rule name given to `ty rule` does not match a known rule.
Solutions
- Check the exact rule name spelling against `ty rule --list` (or the docs)
- Use the fully qualified rule name as shown in diagnostics output
- If the rule was renamed in a newer version, update the name or pin the ty version
Example fix
# before ty rule ununsed-import // after ty rule unused-import
Defensive patterns
Strategy: try-catch
Validate before calling
import subprocess
known = subprocess.run(['ty','rule','--list'], capture_output=True, text=True).stdout
if '--rule-name--' not in known:
print('unknown rule') Try / catch
if let Err(e) = ty_rule(name, format) {
eprintln!("ty rule failed: {e}; run `ty rule --list` for valid rule names");
} Prevention
- Verify rule names with `ty rule --list` or the documentation before scripting lookups
- Copy rule names directly from ty's diagnostic output rather than retyping them
- Pin and read the changelog when upgrading ty, since rule names can be renamed
When it happens
Trigger: Running `ty rule <name>` with a misspelled, renamed, or nonexistent rule name; using a Ruff rule code that ty does not define.
Common situations: Typing `ty rule ununsed-import` (typo); copying Ruff rule names that don't exist in ty; referencing a rule removed or renamed in a newer ty version.
Related errors
- Can only write to stdout when formatting from stdin, but…
- Content not correctly formatted
- could not find any tasks matching the given criteria
- could not find `pyproject.toml` in any ancestor of
- could not find task named
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/f93d393e7c050201.
Report an issue: GitHub.
Appendix: source
Thrown at crates/ty/src/rule.rs:54
let status = match self.status {
LintStatus::Preview { since } => format!("Preview (since {since})"),
LintStatus::Stable { since } => format!("Stable (since {since})"),
LintStatus::Deprecated { since, reason } => {
format!("Deprecated (since {since}): {reason}")
}
LintStatus::Removed { since, reason } => format!("Removed (since {since}): {reason}"),
};
writeln!(f, "Default level: {} | {status}\n", self.default_level)?;
f.write_str(self.documentation.trim())
}
}
/// Explain a single rule.
pub(crate) fn rule(name: &str, format: HelpFormat) -> Result<()> {
let registry = default_lint_registry();
let lint = registry.get(name).map_err(|e| anyhow::anyhow!("{e}"))?;
let mut stdout = BufWriter::new(io::stdout().lock());
match format {
HelpFormat::Text => {
writeln!(stdout, "{}", Explanation::from_lint(&lint))?;
}
HelpFormat::Json => {
serde_json::to_writer_pretty(&mut stdout, &Explanation::from_lint(&lint))?;
}
}
Ok(())
}
/// Explain all rules.
pub(crate) fn rules(format: HelpFormat) -> Result<()> {
let registry = default_lint_registry();
let mut lints: Vec<LintId> = registry.lints().to_vec();
lints.sort_by_key(|l| l.name());View on GitHub (pinned to 26f38c119c)