Skip to content

Commit 8ad7d13

Browse files
authored
(Feat): Add linter: ty (#1028)
Fixes #1024. https://github.com/astral-sh/ty#readme
1 parent 3e45a62 commit 8ad7d13

7 files changed

Lines changed: 447 additions & 53 deletions

File tree

README.md

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,59 @@ Enable the following tools via:
3838
trunk check enable {linter}
3939
```
4040

41-
| Technology | Linters |
42-
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
43-
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
44-
| Ansible | [ansible-lint] |
45-
| Apex | [pmd] |
46-
| Bash | [shellcheck], [shfmt] |
47-
| Bazel, Starlark | [buildifier] |
48-
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
49-
| C# | [dotnet-format] |
50-
| CircleCI Config | [circleci] |
51-
| Cloudformation | [cfnlint], [checkov] |
52-
| CMake | [cmake-format] |
53-
| CSS, SCSS | [stylelint], [prettier] |
54-
| Cue | [cue-fmt] |
55-
| Dart | [dart] |
56-
| Docker | [hadolint], [checkov] |
57-
| Dotenv | [dotenv-linter] |
58-
| GitHub | [actionlint] |
59-
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
60-
| GraphQL | [graphql-schema-linter], [prettier] |
61-
| HAML | [haml-lint] |
62-
| HTML Templates | [djlint] |
63-
| Java | [google-java-format], [pmd], [semgrep] |
64-
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
65-
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
66-
| Kotlin | [detekt], [ktlint] |
67-
| Kubernetes | [kube-linter] |
68-
| Lua | [stylua] |
69-
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
70-
| Nix | [nixpkgs-fmt] |
71-
| package.json | [sort-package-json] |
72-
| Perl | [perlcritic], [perltidy] |
73-
| PHP | [php-cs-fixer], [phpstan] |
74-
| PNG | [oxipng] |
75-
| PowerShell | [psscriptanalyzer] |
76-
| Prisma | [prisma] |
77-
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
78-
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
79-
| Rego | [regal], [opa] |
80-
| Renovate | [renovate] |
81-
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
82-
| Rust | [clippy], [rustfmt] |
83-
| Scala | [scalafmt] |
84-
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
85-
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
86-
| SVG | [svgo] |
87-
| Swift | [stringslint], [swiftlint], [swiftformat] |
88-
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
89-
| Terragrunt | [terragrunt] |
90-
| Textproto | [txtpbfmt] |
91-
| TOML | [taplo] |
92-
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
93-
| YAML | [prettier], [semgrep], [yamllint] |
41+
| Technology | Linters |
42+
| --------------- | -------------------------------------------------------------------------------------------------------------------------- |
43+
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
44+
| Ansible | [ansible-lint] |
45+
| Apex | [pmd] |
46+
| Bash | [shellcheck], [shfmt] |
47+
| Bazel, Starlark | [buildifier] |
48+
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
49+
| C# | [dotnet-format] |
50+
| CircleCI Config | [circleci] |
51+
| Cloudformation | [cfnlint], [checkov] |
52+
| CMake | [cmake-format] |
53+
| CSS, SCSS | [stylelint], [prettier] |
54+
| Cue | [cue-fmt] |
55+
| Dart | [dart] |
56+
| Docker | [hadolint], [checkov] |
57+
| Dotenv | [dotenv-linter] |
58+
| GitHub | [actionlint] |
59+
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
60+
| GraphQL | [graphql-schema-linter], [prettier] |
61+
| HAML | [haml-lint] |
62+
| HTML Templates | [djlint] |
63+
| Java | [google-java-format], [pmd], [semgrep] |
64+
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
65+
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
66+
| Kotlin | [detekt], [ktlint] |
67+
| Kubernetes | [kube-linter] |
68+
| Lua | [stylua] |
69+
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
70+
| Nix | [nixpkgs-fmt] |
71+
| package.json | [sort-package-json] |
72+
| Perl | [perlcritic], [perltidy] |
73+
| PHP | [php-cs-fixer], [phpstan] |
74+
| PNG | [oxipng] |
75+
| PowerShell | [psscriptanalyzer] |
76+
| Prisma | [prisma] |
77+
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
78+
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery], [ty] |
79+
| Rego | [regal], [opa] |
80+
| Renovate | [renovate] |
81+
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
82+
| Rust | [clippy], [rustfmt] |
83+
| Scala | [scalafmt] |
84+
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
85+
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
86+
| SVG | [svgo] |
87+
| Swift | [stringslint], [swiftlint], [swiftformat] |
88+
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
89+
| Terragrunt | [terragrunt] |
90+
| Textproto | [txtpbfmt] |
91+
| TOML | [taplo] |
92+
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
93+
| YAML | [prettier], [semgrep], [yamllint] |
9494

9595
[actionlint]: https://trunk.io/linters/infra/actionlint
9696
[ansible-lint]: https://github.com/ansible/ansible-lint#readme
@@ -195,6 +195,7 @@ trunk check enable {linter}
195195
[trufflehog]: https://trunk.io/linters/security/trufflehog
196196
[trunk-toolbox]: https://github.com/trunk-io/toolbox#readme
197197
[txtpbfmt]: https://github.com/protocolbuffers/txtpbfmt#readme
198+
[ty]: https://github.com/astral-sh/ty#readme
198199
[vale]: https://vale.sh/docs/
199200
[yamllint]: https://trunk.io/linters/yaml/yamllint
200201
[yapf]: https://github.com/google/yapf#readme

linters/ty/plugin.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 0.1
2+
downloads:
3+
- name: ty
4+
version: 0.0.1-alpha.1
5+
downloads:
6+
- os:
7+
linux: unknown-linux-gnu
8+
macos: apple-darwin
9+
cpu:
10+
x86_64: x86_64
11+
arm_64: aarch64
12+
url: https://github.com/astral-sh/ty/releases/download/${version}/ty-${cpu}-${os}.tar.gz
13+
strip_components: 1
14+
- os:
15+
windows: windows
16+
cpu:
17+
x86_64: x86_64
18+
url: https://github.com/astral-sh/ty/releases/download/${version}/ty-x86_64-pc-windows-msvc.zip
19+
strip_components: 1
20+
tools:
21+
definitions:
22+
- name: ty
23+
download: ty
24+
known_good_version: 0.0.1-alpha.1
25+
shims: [ty]
26+
health_checks:
27+
- command: ty --version
28+
parse_regex: ${semver}
29+
lint:
30+
definitions:
31+
- name: ty
32+
description: A Python type checker
33+
files: [python, python-interface]
34+
tools: [ty]
35+
known_good_version: 0.0.1-alpha.1
36+
suggest_if: never
37+
commands:
38+
- name: check
39+
output: regex
40+
parse_regex:
41+
((?P<severity>.+)\[(?P<code>.+)\]
42+
(?P<path>.+):(?P<line>\d+):(?P<column>\d+):\s*(?P<message>.*))
43+
run: ty check --output-format=concise ${target}
44+
success_codes: [0, 1]
45+
batch: true

linters/ty/test_data/basic.in.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import Callable, Iterator, Union, Optional, Enum
2+
3+
4+
def wrong_type(x: int) -> str:
5+
return x # error: Incompatible return value type (got "int", expected "str")
6+
7+
class A:
8+
def method1(self) -> None:
9+
self.x = 1
10+
11+
def method2(self) -> None:
12+
self.x = ""
13+
14+
a = A()
15+
reveal_type(a.x)
16+
17+
a.x = ""
18+
a.x = 3.0
19+
20+
21+
22+
class A:
23+
x: int = 0 # Regular class variable
24+
y: ClassVar[int] = 0 # Pure class variable
25+
26+
def __init__(self):
27+
self.z = 0 # Pure instance variable
28+
29+
print(A.x)
30+
print(A.y)
31+
print(A.z)
32+
33+
34+
35+
class Color(Enum):
36+
RED = 1
37+
BLUE = 2
38+
39+
def is_red(color: Color) -> bool:
40+
if color == Color.RED:
41+
return True
42+
elif color == Color.BLUE:
43+
return False
44+
45+
46+
def func(val: int | None):
47+
if val is not None:
48+
49+
def inner_1() -> None:
50+
reveal_type(val)
51+
print(val + 1)
52+
53+
inner_2 = lambda: reveal_type(val) + 1
54+
55+
inner_1()
56+
inner_2()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Based on test file input from astral-sh/ruff
2+
import json
3+
4+
from typing import Any, Sequence
5+
6+
class MissingCommand(TypeError): ...
7+
class AnoherClass: ...
8+
9+
def a(): ...
10+
11+
@overload
12+
def a(arg: int): ...
13+
14+
@overload
15+
def a(arg: int, name: str): ...
16+
17+
18+
def grouped1(): ...
19+
def grouped2(): ...
20+
def grouped3( ): ...
21+
22+
23+
class BackendProxy:
24+
backend_module: str
25+
backend_object: str | None
26+
backend: Any
27+
28+
def grouped1(): ...
29+
def grouped2(): ...
30+
def grouped3( ): ...
31+
@decorated
32+
33+
def with_blank_line(): ...
34+
35+
36+
def ungrouped(): ...
37+
a = "test"
38+
39+
def function_def():
40+
pass
41+
b = "test"
42+
43+
44+
def outer():
45+
def inner():
46+
pass
47+
def inner2():
48+
pass
49+
50+
class Foo: ...
51+
class Bar: ...

0 commit comments

Comments
 (0)