---
name: adding-ty-diagnostics
description: Use when a user says "add a ty rule", "add a ty diagnostic", "write this new ty diagnostic", "change a ty error message", "review ty diagnostics", or asks to add, update, or review ty checks, diagnostic messages, subdiagnostics, or concise output behavior.
title: adding-ty-diagnostics
canonical_url: https://skilld.dev/gh/astral-sh/ruff/adding-ty-diagnostics
last_updated: 2026-11-12T05:46:05.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install astral-sh/ruff/adding-ty-diagnostics`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/adding-ty-diagnostics`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/astral-sh/ruff/adding-ty-diagnostics) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/adding-ty-diagnostics`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/adding-ty-diagnostics --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/adding-ty-diagnostics --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Adding Ty Diagnostics

Use this skill when adding a ty rule or adding, changing, or reviewing a ty diagnostic.

**Keep error messages concise.** Think about how the diagnostic will look on a narrow terminal screen.

Put extra detail in subdiagnostics or secondary annotations when that helps, but make sure the primary diagnostic is understandable on its own.

Always check that the diagnostic still makes sense when the user passes `--output-format=concise`.

If the error code is entirely new or if you have changed the documentation for the error code,
you will need to run `cargo dev generate-all` after making your changes, to update the generated schema for ty
and the generated `.md` documentation files.

Diagnostics should usually be tested using mdtests. If you are changing behaviour for an existing diagnostic,
you should usually add your tests to a pre-existing `.md` file; otherwise, it may be appropriate to add a new
`.md` file for your tests. A new ty diagnostic should normally have at least one snapshot test showing how ty renders
it. For changes to existing diagnostics, snapshot tests are only usually necessary for diagnostics that use secondary
annotations or subdiagnostics. If you want to add a snapshot, inline `# snapshot` comments are preferred over the legacy
`<!-- snapshot-annotations -->` directive.

Rule renames usually need no new tests. Update existing test expectations to use the new name.
Skip tests that only demonstrate that the old name still works in configuration or ignore comments.
The [rule-selection tests](../../../crates/ty/tests/cli/rule_selection.rs) and
[suppression mdtests](../../../crates/ty_python_semantic/resources/mdtest/import/errors.md#suppressing-import-not-found-with-the-previous-rule-name)
already cover those cases.

When adding a ty rule that is disabled by default, normally enable it at `warn` in `.github/ty-ecosystem.toml` so the
ecosystem-analyzer workflows report its effects.

When declaring a new stable rule with `declare_lint!`, set `status` to `LintStatus::stable(<next version of ty>)`.
This also applies to a new rule split out of an existing rule.
You should determine what the next version of ty will be by inspecting https://pypi.org/pypi/ty/json, finding what
the latest release of ty is, and incrementing the patch version by one. For example, if the latest release of ty is `0.5.3`, the status should be `LintStatus::stable("0.5.4")`.

When renaming a rule, keep the version from its existing declaration.

Document changes such as renames and splits in a `## Rule history` section at the end of each
affected rule's documentation. Use a terse bullet for each change, starting with the ty version
that introduced it. For a rename, give the old and new names. For a split, name the original rule
and the rules split out of it. Follow the format of existing rule histories, such as the one for
[`invalid-implicit-return-in-function-with-stub-body`](../../../crates/ty_python_semantic/resources/lint_docs/invalid-implicit-return-in-function-with-stub-body.md#rule-history).
