Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Linters which are not language-specific:
| Kotlin | [ktfmt] | [ktlint] |
| Markdown | [Prettier] | [Vale] |
| Protocol Buffer | [buf] | [buf lint] |
| Python | [ruff] | [flake8], [pylint], [ruff] |
| Python | [ruff] | [flake8], [pylint], [ruff], [ty] |
| Ruby | | [RuboCop], [Standard] |
| Rust | [rustfmt] | |
| SQL | [prettier-plugin-sql] | |
Expand Down Expand Up @@ -87,6 +87,7 @@ Linters which are not language-specific:
[rubocop]: https://docs.rubocop.org/
[standard]: https://github.com/standardrb/standard
[ruff]: https://docs.astral.sh/ruff/
[ty]: https://docs.astral.sh/ty/
[pylint]: https://pylint.readthedocs.io/en/stable/
[shellcheck]: https://www.shellcheck.net/
[shfmt]: https://github.com/mvdan/sh
Expand Down
1 change: 1 addition & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports_files(
"ktlint-baseline.xml",
".clang-tidy",
"spotbugs-exclude.xml",
"ty.toml",
],
visibility = ["//visibility:public"],
)
Expand Down
4 changes: 2 additions & 2 deletions example/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ esac
args=()
if [ $machine == "Windows" ]; then
# avoid missing linters on windows platform
args=("--aspects=$(echo //tools/lint:linters.bzl%{flake8,pylint,pmd,ruff,vale,yamllint,clang_tidy} | tr ' ' ',')")
args=("--aspects=$(echo //tools/lint:linters.bzl%{flake8,pylint,pmd,ruff,ty,vale,yamllint,clang_tidy} | tr ' ' ',')")
else
args=("--aspects=$(echo //tools/lint:linters.bzl%{buf,eslint,flake8,keep_sorted,ktlint,pmd,pylint,ruff,shellcheck,stylelint,vale,yamllint,clang_tidy,cppcheck,spotbugs} | tr ' ' ',')")
args=("--aspects=$(echo //tools/lint:linters.bzl%{buf,eslint,flake8,keep_sorted,ktlint,pmd,pylint,ruff,ty,shellcheck,stylelint,vale,yamllint,clang_tidy,cppcheck,spotbugs} | tr ' ' ',')")
fi

# NB: perhaps --remote_download_toplevel is needed as well with remote execution?
Expand Down
10 changes: 10 additions & 0 deletions example/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ py_library(
srcs = ["unused_import.py"],
)

py_library(
name = "unsupported_operator",
srcs = ["unsupported_operator.py"],
)

py_library(
name = "call_non_callable",
srcs = ["call_non_callable.py"],
)

filegroup(
name = "unused_import_pyi",
srcs = ["unused_import.pyi"],
Expand Down
5 changes: 5 additions & 0 deletions example/src/call_non_callable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Demo with just running ty:
Copy link
Member

Choose a reason for hiding this comment

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

this demo should look like bazel run @some_label//:ty -- some_file.py - we want to convince ourselves we know how to call the tool standalone

# $ ./lint.sh src:call_non_callable
B = 1
# This error should be ignored, as it is specified as ignored in src/ty.toml
B()
3 changes: 3 additions & 0 deletions example/src/unsupported_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Demo with just running ty from the examples dir:
# $ bazel run --run_under="cd $PWD &&" -- //tools/lint:ty check --config-file=ty.toml src/*.py
a = 10 + "test"
13 changes: 13 additions & 0 deletions example/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load(
"ruff_test",
"shellcheck_test",
"standardrb_test",
"ty_test",
)

write_file(
Expand Down Expand Up @@ -79,6 +80,11 @@ py_library(
srcs = ["excluded.py"],
)

py_library(
name = "unsupported_operator",
srcs = ["unsupported_operator.py"],
)

java_library(
name = "generated_java",
srcs = ["generated.java"],
Expand Down Expand Up @@ -140,6 +146,13 @@ pylint_test(
tags = ["manual"],
)

ty_test(
name = "ty_should_fail_unsupported_operator",
srcs = ["//src:unsupported_operator"],
# Expected to fail based on current content of the file.
tags = ["manual"],
)

pmd_test(
name = "pmd",
srcs = ["//src:foo"],
Expand Down
22 changes: 22 additions & 0 deletions example/test/lint_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ EOF
src/unused_import.py:15:0: C0301: Line too long (180/120) (line-too-long)
src/unused_import.py:22:6: W1302: Invalid format string (bad-format-string)
src/unused_import.py:18:0: W0611: Unused import os (unused-import)
EOF

# Ty
echo <<"EOF" | assert_output --partial
error[unsupported-operator]: Operator `+` is unsupported between objects of type `Literal[10]` and `Literal["test"]`
--> src/unsupported_operator.py:3:5
|
1 | # Demo with just running ty from the examples dir:
2 | # $ ./lint.sh src:unsupported_operator
3 | a = 10 + "test"
| ^^^^^^^^^^^
|
info: rule `unsupported-operator` is enabled by default

Found 1 diagnostic
EOF

# pylint
echo <<"EOF" | assert_output --partial
src/unused_import.py:15:0: C0301: Line too long (180/120) (line-too-long)
src/unused_import.py:22:6: W1302: Invalid format string (bad-format-string)
src/unused_import.py:18:0: W0611: Unused import os (unused-import)
EOF

# Flake8
Expand Down
13 changes: 13 additions & 0 deletions example/test/machine_outputs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
"machine_ruff_report",
"machine_shellcheck_report",
"machine_stylelint_report",
"machine_ty_report",
"machine_vale_report",
"machine_yamllint_report",
"report_test",
Expand Down Expand Up @@ -38,6 +39,18 @@ report_test(
report = "machine_ruff_pyi_report",
)

machine_ty_report(
name = "machine_ty_report",
src = "//src:unsupported_operator",
)

report_test(
name = "ty_machine_output_test",
expected_tool = "Ty",
expected_uri = "src/unsupported_operator.py",
report = "machine_ty_report",
)

machine_shellcheck_report(
name = "machine_shellcheck_report",
src = "//src:hello_shell",
Expand Down
7 changes: 6 additions & 1 deletion example/test/machine_outputs/machine_output.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_features//:features.bzl", "bazel_features")
load("@jq.bzl//jq:jq.bzl", "jq_test")
load("//tools/lint:linters.bzl", "buf", "clang_tidy", "eslint", "flake8", "pylint", "ruff", "shellcheck", "stylelint", "vale", "yamllint")
load("//tools/lint:linters.bzl", "buf", "clang_tidy", "eslint", "flake8", "pylint", "ruff", "shellcheck", "stylelint", "ty", "vale", "yamllint")

SARIF_TOOL_DRIVER_NAME_FILTER = ".runs[].tool.driver.name"
PHYSICAL_ARTIFACT_LOCATION_URI_FILTER = ".runs[].results | map(.locations | map(.physicalLocation.artifactLocation.uri)) | flatten | unique[]"
Expand Down Expand Up @@ -35,6 +35,11 @@ machine_ruff_report = rule(
attrs = {"src": attr.label(aspects = [ruff])},
)

machine_ty_report = rule(
implementation = _machine_report,
attrs = {"src": attr.label(aspects = [ty])},
)

machine_shellcheck_report = rule(
implementation = _machine_report,
attrs = {"src": attr.label(aspects = [shellcheck])},
Expand Down
3 changes: 3 additions & 0 deletions example/test/unsupported_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Demo with just running ty:
# $ bazel run --run_under="cd $PWD &&" -- //tools/lint:ty check --config-file=ty.toml test/*.py
a = 10 + "test"
6 changes: 6 additions & 0 deletions example/tools/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ we don't want to trigger eager fetches of these for builds that don't want to ru

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_rules_lint//lint:vale_library.bzl", "VALE_STYLES")
load("@aspect_rules_lint//lint:ty.bzl", "lint_ty_aspect")
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
load("@npm//:stylelint/package_json.bzl", stylelint_bin = "bin")
Expand All @@ -20,6 +21,11 @@ alias(
actual = "@rules_buf_toolchains//:buf",
)

alias(
name = "ty",
actual = "@aspect_rules_lint//lint:ty_bin"
)

# We can test that it works with:
# bazel run :flake8 -- --help
py_console_script_binary(
Expand Down
8 changes: 8 additions & 0 deletions example/tools/lint/linters.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("@aspect_rules_lint//lint:shellcheck.bzl", "lint_shellcheck_aspect")
load("@aspect_rules_lint//lint:spotbugs.bzl", "lint_spotbugs_aspect")
load("@aspect_rules_lint//lint:standardrb.bzl", "lint_standardrb_aspect")
load("@aspect_rules_lint//lint:stylelint.bzl", "lint_stylelint_aspect")
load("@aspect_rules_lint//lint:ty.bzl", "lint_ty_aspect")
load("@aspect_rules_lint//lint:vale.bzl", "lint_vale_aspect")
load("@aspect_rules_lint//lint:yamllint.bzl", "lint_yamllint_aspect")

Expand Down Expand Up @@ -87,6 +88,13 @@ shellcheck = lint_shellcheck_aspect(

shellcheck_test = lint_test(aspect = shellcheck)

ty = lint_ty_aspect(
binary = Label("@aspect_rules_lint//lint:ty_bin"),
config = Label("@//:ty.toml"),
)

ty_test = lint_test(aspect = ty)

vale = lint_vale_aspect(
binary = Label("//tools/lint:vale"),
config = Label("//:.vale.ini"),
Expand Down
3 changes: 3 additions & 0 deletions example/ty.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file should be used by ty when linting, and should ignore one lint
[rules]
call-non-callable = "ignore"
5 changes: 5 additions & 0 deletions lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ alias(
actual = "@multitool//tools/shellcheck",
)

alias(
name = "ty_bin",
actual = "@multitool//tools/ty",
)

# Used as a default for vale_aspect#styles
filegroup(
name = "empty_styles",
Expand Down
44 changes: 44 additions & 0 deletions lint/multitool.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,49 @@
"cpu": "x86_64"
}
]
},
"ty": {
"binaries": [
{
"kind": "archive",
"url": "https://github.com/astral-sh/ty/releases/download/0.0.1-alpha.27/ty-aarch64-unknown-linux-musl.tar.gz",
"file": "ty-aarch64-unknown-linux-musl/ty",
"sha256": "cc910066aed5068110d566a469d101d91dd8eb42bc5651f24c724ab7785de2bd",
"os": "linux",
"cpu": "arm64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ty/releases/download/0.0.1-alpha.27/ty-x86_64-unknown-linux-musl.tar.gz",
"file": "ty-x86_64-unknown-linux-musl/ty",
"sha256": "3b4995d36c477956ea1dc52a3e84a8c044b98957a658697420d22c4b7e55a05a",
"os": "linux",
"cpu": "x86_64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ty/releases/download/0.0.1-alpha.27/ty-aarch64-apple-darwin.tar.gz",
"file": "ty-aarch64-apple-darwin/ty",
"sha256": "05049ad02442045ac42c4a2a541e6aaf62e43ff585008c55b2ab1505de168661",
"os": "macos",
"cpu": "arm64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ty/releases/download/0.0.1-alpha.27/ty-x86_64-apple-darwin.tar.gz",
"file": "ty-x86_64-apple-darwin/ty",
"sha256": "d29f3cfc745ef8ab19c3f2b1db2d6e18ec3ef433e824778db2a0ef168acec6fd",
"os": "macos",
"cpu": "x86_64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ty/releases/download/0.0.1-alpha.27/ty-x86_64-pc-windows-msvc.zip",
"file": "ty.exe",
"sha256": "ec651f5df2fe705c1f7a915340a5946cfde3f9b49b9a6cb1fadf8348095e19d3",
"os": "windows",
"cpu": "x86_64"
}
]
}
}
Loading