Skip to content

(Feat): Add linter: ty #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 54 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,59 @@ Enable the following tools via:
trunk check enable {linter}
```

| Technology | Linters |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
| Bazel, Starlark | [buildifier] |
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
| C# | [dotnet-format] |
| CircleCI Config | [circleci] |
| Cloudformation | [cfnlint], [checkov] |
| CMake | [cmake-format] |
| CSS, SCSS | [stylelint], [prettier] |
| Cue | [cue-fmt] |
| Dart | [dart] |
| Docker | [hadolint], [checkov] |
| Dotenv | [dotenv-linter] |
| GitHub | [actionlint] |
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
| GraphQL | [graphql-schema-linter], [prettier] |
| HAML | [haml-lint] |
| HTML Templates | [djlint] |
| Java | [google-java-format], [pmd], [semgrep] |
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
| Kotlin | [detekt], [ktlint] |
| Kubernetes | [kube-linter] |
| Lua | [stylua] |
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
| Nix | [nixpkgs-fmt] |
| package.json | [sort-package-json] |
| Perl | [perlcritic], [perltidy] |
| PHP | [php-cs-fixer], [phpstan] |
| PNG | [oxipng] |
| PowerShell | [psscriptanalyzer] |
| Prisma | [prisma] |
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
| Rego | [regal], [opa] |
| Renovate | [renovate] |
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
| Rust | [clippy], [rustfmt] |
| Scala | [scalafmt] |
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
| SVG | [svgo] |
| Swift | [stringslint], [swiftlint], [swiftformat] |
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
| Terragrunt | [terragrunt] |
| Textproto | [txtpbfmt] |
| TOML | [taplo] |
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
| YAML | [prettier], [semgrep], [yamllint] |
| Technology | Linters |
| --------------- | -------------------------------------------------------------------------------------------------------------------------- |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
| Bazel, Starlark | [buildifier] |
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
| C# | [dotnet-format] |
| CircleCI Config | [circleci] |
| Cloudformation | [cfnlint], [checkov] |
| CMake | [cmake-format] |
| CSS, SCSS | [stylelint], [prettier] |
| Cue | [cue-fmt] |
| Dart | [dart] |
| Docker | [hadolint], [checkov] |
| Dotenv | [dotenv-linter] |
| GitHub | [actionlint] |
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
| GraphQL | [graphql-schema-linter], [prettier] |
| HAML | [haml-lint] |
| HTML Templates | [djlint] |
| Java | [google-java-format], [pmd], [semgrep] |
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
| Kotlin | [detekt], [ktlint] |
| Kubernetes | [kube-linter] |
| Lua | [stylua] |
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
| Nix | [nixpkgs-fmt] |
| package.json | [sort-package-json] |
| Perl | [perlcritic], [perltidy] |
| PHP | [php-cs-fixer], [phpstan] |
| PNG | [oxipng] |
| PowerShell | [psscriptanalyzer] |
| Prisma | [prisma] |
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery], [ty] |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It appears that sourcery is also a linter, so it should be alphabetized with the other linters. Can you please move ty to the correct alphabetical position?

| Rego | [regal], [opa] |
| Renovate | [renovate] |
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
| Rust | [clippy], [rustfmt] |
| Scala | [scalafmt] |
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
| SVG | [svgo] |
| Swift | [stringslint], [swiftlint], [swiftformat] |
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
| Terragrunt | [terragrunt] |
| Textproto | [txtpbfmt] |
| TOML | [taplo] |
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
| YAML | [prettier], [semgrep], [yamllint] |

[actionlint]: https://trunk.io/linters/infra/actionlint
[ansible-lint]: https://github.com/ansible/ansible-lint#readme
Expand Down Expand Up @@ -195,6 +195,7 @@ trunk check enable {linter}
[trufflehog]: https://trunk.io/linters/security/trufflehog
[trunk-toolbox]: https://github.com/trunk-io/toolbox#readme
[txtpbfmt]: https://github.com/protocolbuffers/txtpbfmt#readme
[ty]: https://github.com/astral-sh/ty#readme
[vale]: https://vale.sh/docs/
[yamllint]: https://trunk.io/linters/yaml/yamllint
[yapf]: https://github.com/google/yapf#readme
Expand Down
45 changes: 45 additions & 0 deletions linters/ty/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 0.1
downloads:
- name: ty
version: 0.0.1-alpha.1
downloads:
- os:
linux: unknown-linux-gnu
macos: apple-darwin
cpu:
x86_64: x86_64
arm_64: aarch64
url: https://github.com/astral-sh/ty/releases/download/${version}/ty-${cpu}-${os}.tar.gz
strip_components: 1
- os:
windows: windows
cpu:
x86_64: x86_64
url: https://github.com/astral-sh/ty/releases/download/${version}/ty-x86_64-pc-windows-msvc.zip
strip_components: 1
tools:
definitions:
- name: ty
download: ty
known_good_version: 0.0.1-alpha.1
shims: [ty]
health_checks:
- command: ty --version
parse_regex: ${semver}
lint:
definitions:
- name: ty
description: A Python type checker
files: [python, python-interface]
tools: [ty]
known_good_version: 0.0.1-alpha.1
suggest_if: never

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The suggest_if: never field indicates that Trunk should never suggest enabling this linter. Is this intentional? If so, please add a comment explaining why.

commands:
- name: check
output: regex
parse_regex:
((?P<severity>.+)\[(?P<code>.+)\]
(?P<path>.+):(?P<line>\d+):(?P<column>\d+):\s*(?P<message>.*))
run: ty check --output-format=concise ${target}
success_codes: [0, 1]
batch: true
56 changes: 56 additions & 0 deletions linters/ty/test_data/basic.in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Callable, Iterator, Union, Optional, Enum


def wrong_type(x: int) -> str:
return x # error: Incompatible return value type (got "int", expected "str")

class A:
def method1(self) -> None:
self.x = 1

def method2(self) -> None:
self.x = ""

a = A()
reveal_type(a.x)

a.x = ""
a.x = 3.0



class A:
x: int = 0 # Regular class variable
y: ClassVar[int] = 0 # Pure class variable

def __init__(self):
self.z = 0 # Pure instance variable

print(A.x)
print(A.y)
print(A.z)



class Color(Enum):
RED = 1
BLUE = 2

def is_red(color: Color) -> bool:
if color == Color.RED:
return True
elif color == Color.BLUE:
return False


def func(val: int | None):
if val is not None:

def inner_1() -> None:
reveal_type(val)
print(val + 1)

inner_2 = lambda: reveal_type(val) + 1

inner_1()
inner_2()
51 changes: 51 additions & 0 deletions linters/ty/test_data/interface.in.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Based on test file input from astral-sh/ruff
import json

from typing import Any, Sequence

class MissingCommand(TypeError): ...
class AnoherClass: ...

def a(): ...

@overload
def a(arg: int): ...

@overload
def a(arg: int, name: str): ...


def grouped1(): ...
def grouped2(): ...
def grouped3( ): ...


class BackendProxy:
backend_module: str
backend_object: str | None
backend: Any

def grouped1(): ...
def grouped2(): ...
def grouped3( ): ...
@decorated

def with_blank_line(): ...


def ungrouped(): ...
a = "test"

def function_def():
pass
b = "test"


def outer():
def inner():
pass
def inner2():
pass

class Foo: ...
class Bar: ...
Loading
Loading