8000 ty/docs/rules.md at main · KleinhausM/ty · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 2.1 KB

rules.md

File metadata and controls

63 lines (43 loc) · 2.1 KB

Rules

Rules are individual checks that ty performs to detect common issues in your code, such as incompatible assignments, missing imports, or invalid type annotations. Each rule focuses on a specific pattern and can be turned on or off depending on your project’s needs.

!!! tip

See the [rules reference](./reference/rules.md) for an enumeration of all supported rules.

Rule levels

Each rule has a configurable level:

  • error: violations are reported as errors and ty exits with an exit code of 1 if there's any.
  • warn: violations are reported as warnings. Depending on your configuration, ty exits with an exit code of 0 if there are only warning violations (default) or 1 when using --error-on-warning.
  • ignore: the rule is turned off

You can configure the level for each rule on the command line using the --warn, --error, and --ignore flags. For example:

ty check \
  --warn unused-ignore-comment \        # Make `unused-ignore-comment` a warning
  --ignore redundant-cast \             # Disable `redundant-cast`
  --error possibly-missing-attribute \  # Error on `possibly-missing-attribute`
  --error possibly-missing-import       # Error on `possibly-missing-import`

The options can be repeated. Subsequent options override earlier options.

Rule levels can also be changed in the rules section of a configuration file.

For example, the following is equivalent to the command above:

[tool.ty.rules]
unused-ignore-comment = "warn"
redundant-cast = "ignore"
possibly-missing-attribute = "error"
possibly-missing-import = "error"

You can also configure the level for all rules at once.

On the command line you can use --error all, --warn all, or --ignore all. For example:

ty check --error all

You can also configure this setting in the rules section of a configuration file.

For example, the following is equivalent to the command above:

[tool.ty.rules]
all = "error"
0