Dogfood ty on the `scripts` directory (#21617)

## Summary

This PR sets up CI jobs to run ty from the `main` branch on the files
and subdirectories in our `scripts` directory

## Test Plan

Both these commands pass for me locally:
- `uv run --project=./scripts cargo run -p ty check --project=./scripts`
- `uv run --project=./scripts/ty_benchmark cargo run -p ty check
--project=./scripts/ty_benchmark`
This commit is contained in:
Alex Waygood 2025-11-24 23:13:44 +00:00 committed by GitHub
parent 0631e72187
commit bfd65c4215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 5 deletions

View File

@ -284,6 +284,10 @@ jobs:
run: cargo insta test --all-features --unreferenced reject --test-runner nextest run: cargo insta test --all-features --unreferenced reject --test-runner nextest
- name: Dogfood ty on py-fuzzer - name: Dogfood ty on py-fuzzer
run: uv run --project=./python/py-fuzzer cargo run -p ty check --project=./python/py-fuzzer run: uv run --project=./python/py-fuzzer cargo run -p ty check --project=./python/py-fuzzer
- name: Dogfood ty on the scripts directory
run: uv run --project=./scripts cargo run -p ty check --project=./scripts
- name: Dogfood ty on ty_benchmark
run: uv run --project=./scripts/ty_benchmark cargo run -p ty check --project=./scripts/ty_benchmark
# Check for broken links in the documentation. # Check for broken links in the documentation.
- run: cargo doc --all --no-deps - run: cargo doc --all --no-deps
env: env:

View File

@ -14,6 +14,7 @@ from __future__ import annotations
import argparse import argparse
import subprocess import subprocess
from pathlib import Path
from _utils import ROOT_DIR, dir_name, get_indent, pascal_case, snake_case from _utils import ROOT_DIR, dir_name, get_indent, pascal_case, snake_case
@ -153,7 +154,7 @@ pub(crate) fn {rule_name_snake}(checker: &mut Checker) {{}}
_rustfmt(rules_mod) _rustfmt(rules_mod)
def _rustfmt(path: str) -> None: def _rustfmt(path: str | Path) -> None:
subprocess.run(["rustfmt", path]) subprocess.run(["rustfmt", path])

View File

@ -22,10 +22,11 @@ import re
import tempfile import tempfile
import time import time
from asyncio.subprocess import PIPE, create_subprocess_exec from asyncio.subprocess import PIPE, create_subprocess_exec
from collections.abc import Awaitable
from contextlib import asynccontextmanager, nullcontext from contextlib import asynccontextmanager, nullcontext
from pathlib import Path from pathlib import Path
from signal import SIGINT, SIGTERM from signal import SIGINT, SIGTERM
from typing import TYPE_CHECKING, NamedTuple, Self, TypeVar from typing import TYPE_CHECKING, Any, NamedTuple, Self, TypeVar
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import AsyncIterator, Iterator, Sequence from collections.abc import AsyncIterator, Iterator, Sequence
@ -342,7 +343,7 @@ DIFF_LINE_RE = re.compile(
r"^(?P<pre>[+-]) (?P<inner>(?P<path>[^:]+):(?P<lnum>\d+):\d+:) (?P<post>.*)$", r"^(?P<pre>[+-]) (?P<inner>(?P<path>[^:]+):(?P<lnum>\d+):\d+:) (?P<post>.*)$",
) )
T = TypeVar("T") T = TypeVar("T", bound=Awaitable[Any])
async def main( async def main(

View File

@ -1,7 +1,7 @@
[project] [project]
name = "scripts" name = "scripts"
version = "0.0.1" version = "0.0.1"
dependencies = ["stdlibs"] dependencies = ["stdlibs", "tqdm", "mdformat", "pyyaml"]
requires-python = ">=3.12" requires-python = ">=3.12"
[tool.black] [tool.black]
@ -9,3 +9,11 @@ line-length = 88
[tool.ruff] [tool.ruff]
extend = "../pyproject.toml" extend = "../pyproject.toml"
[tool.ty.src]
# `ty_benchmark` is a standalone project with its own pyproject.toml files, search paths, etc.
exclude = ["./ty_benchmark"]
[tool.ty.rules]
possibly-unresolved-reference = "error"
division-by-zero = "error"

View File

@ -19,3 +19,7 @@ packages = ["src/benchmark"]
ignore = [ ignore = [
"E501", # We use ruff format "E501", # We use ruff format
] ]
[tool.ty.rules]
possibly-unresolved-reference = "error"
division-by-zero = "error"

View File

@ -43,7 +43,7 @@ def format_number(number: int) -> str:
# underscore-delimited in the generated file, so we now preserve that property to # underscore-delimited in the generated file, so we now preserve that property to
# avoid unnecessary churn. # avoid unnecessary churn.
if number > 100000: if number > 100000:
number = str(number) number: str = str(number)
number = "_".join(number[i : i + 3] for i in range(0, len(number), 3)) number = "_".join(number[i : i + 3] for i in range(0, len(number), 3))
return f"{number}_u32" return f"{number}_u32"