Compare commits
95 Commits
cjm/pep613
...
gankra/roo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e12163754 | ||
|
|
5473636256 | ||
|
|
b96e1b9759 | ||
|
|
05cde8bd19 | ||
|
|
83a3bc4ee9 | ||
|
|
155fd603e8 | ||
|
|
48f1771877 | ||
|
|
4ca74593dd | ||
|
|
dab3d4e917 | ||
|
|
01695513ce | ||
|
|
e92fd51a2c | ||
|
|
c3631c78bd | ||
|
|
589e8ac0d9 | ||
|
|
76a55314e4 | ||
|
|
6c18f18450 | ||
|
|
7ba176d395 | ||
|
|
766ed5b5f3 | ||
|
|
81c1d36088 | ||
|
|
20510e1d71 | ||
|
|
58a68f1bbd | ||
|
|
2c9433796a | ||
|
|
40148d7b11 | ||
|
|
6271fba1e1 | ||
|
|
a51a0f16e4 | ||
|
|
4b0fa5f270 | ||
|
|
2e13b13012 | ||
|
|
9d1ffd605c | ||
|
|
2dbca6370b | ||
|
|
3dd78e711e | ||
|
|
e1cada1ec3 | ||
|
|
69ce064569 | ||
|
|
523fc418ed | ||
|
|
24d0f65d62 | ||
|
|
a802d7a0ea | ||
|
|
692b7d7f0c | ||
|
|
d363d49ab7 | ||
|
|
281ae8eb34 | ||
|
|
d61902c89f | ||
|
|
511710e1ef | ||
|
|
da04d92ff2 | ||
|
|
0f21567405 | ||
|
|
be32f8acb1 | ||
|
|
1197035c02 | ||
|
|
a7c38eb122 | ||
|
|
0520d11a66 | ||
|
|
54cd9d889d | ||
|
|
44e678a222 | ||
|
|
38c074e67d | ||
|
|
c2ae9c7806 | ||
|
|
5a1201b868 | ||
|
|
48b50128eb | ||
|
|
991e8ed178 | ||
|
|
0fc5520404 | ||
|
|
b82404f706 | ||
|
|
4622b8f849 | ||
|
|
bb3a88cdd5 | ||
|
|
029a7aa200 | ||
|
|
590ce9d9ed | ||
|
|
0b8de723c6 | ||
|
|
36d4b02fa9 | ||
|
|
1f8297cfe6 | ||
|
|
b6b96d75eb | ||
|
|
3c229ae58a | ||
|
|
44d9063058 | ||
|
|
09306a1d69 | ||
|
|
68c1fa86c8 | ||
|
|
16efe53a72 | ||
|
|
7532155c9b | ||
|
|
7198e53182 | ||
|
|
8ca2b5555d | ||
|
|
6d2cf3475f | ||
|
|
e4384fc212 | ||
|
|
6e7ff07065 | ||
|
|
c7e2bfd759 | ||
|
|
c424007645 | ||
|
|
0115fd3757 | ||
|
|
cfbd42c22a | ||
|
|
fc3b341529 | ||
|
|
baaa8dad3a | ||
|
|
a21cde8a5a | ||
|
|
64edfb6ef6 | ||
|
|
96b156303b | ||
|
|
b0e10a9777 | ||
|
|
25023cc0ea | ||
|
|
1ade4f2081 | ||
|
|
8dad58de37 | ||
|
|
2bffef5966 | ||
|
|
e64d772788 | ||
|
|
03696687ea | ||
|
|
058fc37542 | ||
|
|
ec9faa34be | ||
|
|
7155a62e5c | ||
|
|
a67e0690f2 | ||
|
|
6a1e91ce97 | ||
|
|
3db5d5906e |
@@ -8,7 +8,3 @@ benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --"
|
||||
# See: https://github.com/astral-sh/ruff/issues/11503
|
||||
[target.'cfg(all(target_env="msvc", target_os = "windows"))']
|
||||
rustflags = ["-C", "target-feature=+crt-static"]
|
||||
|
||||
[target.'wasm32-unknown-unknown']
|
||||
# See https://docs.rs/getrandom/latest/getrandom/#webassembly-support
|
||||
rustflags = ["--cfg", 'getrandom_backend="wasm_js"']
|
||||
@@ -1,3 +1,12 @@
|
||||
# Define serial test group for running tests sequentially.
|
||||
[test-groups]
|
||||
serial = { max-threads = 1 }
|
||||
|
||||
# Run ty file watching tests sequentially to avoid race conditions.
|
||||
[[profile.default.overrides]]
|
||||
filter = 'binary(file_watching)'
|
||||
test-group = 'serial'
|
||||
|
||||
[profile.ci]
|
||||
# Print out output for failing tests as soon as they fail, and also at the end
|
||||
# of the run (for easy scrollability).
|
||||
|
||||
135
.github/workflows/ci.yaml
vendored
135
.github/workflows/ci.yaml
vendored
@@ -12,13 +12,18 @@ concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
|
||||
cancel-in-progress: true
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTUP_MAX_RETRIES: 10
|
||||
PACKAGE_NAME: ruff
|
||||
PYTHON_VERSION: "3.13"
|
||||
PYTHON_VERSION: "3.14"
|
||||
NEXTEST_PROFILE: ci
|
||||
|
||||
jobs:
|
||||
determine_changes:
|
||||
@@ -237,7 +242,7 @@ jobs:
|
||||
|
||||
cargo-test-linux:
|
||||
name: "cargo test (linux)"
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
|
||||
needs: determine_changes
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
|
||||
timeout-minutes: 20
|
||||
@@ -271,11 +276,9 @@ jobs:
|
||||
# This step is just to get nice GitHub annotations on the PR diff in the files-changed tab.
|
||||
run: cargo test -p ty_python_semantic --test mdtest || true
|
||||
- name: "Run tests"
|
||||
shell: bash
|
||||
env:
|
||||
NEXTEST_PROFILE: "ci"
|
||||
run: cargo insta test --all-features --unreferenced reject --test-runner nextest
|
||||
|
||||
# Dogfood ty on py-fuzzer
|
||||
- run: uv run --project=./python/py-fuzzer cargo run -p ty check --project=./python/py-fuzzer
|
||||
# Check for broken links in the documentation.
|
||||
- run: cargo doc --all --no-deps
|
||||
env:
|
||||
@@ -299,9 +302,13 @@ jobs:
|
||||
|
||||
cargo-test-linux-release:
|
||||
name: "cargo test (linux, release)"
|
||||
# release builds timeout on GitHub runners, so this job is just skipped on forks in the `if` check
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
needs: determine_changes
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
|
||||
if: |
|
||||
github.repository == 'astral-sh/ruff' &&
|
||||
!contains(github.event.pull_request.labels.*.name, 'no-test') &&
|
||||
(needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main')
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -325,14 +332,16 @@ jobs:
|
||||
with:
|
||||
enable-cache: "true"
|
||||
- name: "Run tests"
|
||||
shell: bash
|
||||
env:
|
||||
NEXTEST_PROFILE: "ci"
|
||||
run: cargo insta test --release --all-features --unreferenced reject --test-runner nextest
|
||||
|
||||
cargo-test-windows:
|
||||
name: "cargo test (windows)"
|
||||
runs-on: depot-windows-2022-16
|
||||
cargo-test-other:
|
||||
strategy:
|
||||
matrix:
|
||||
platform:
|
||||
- ${{ github.repository == 'astral-sh/ruff' && 'depot-windows-2022-16' || 'windows-latest' }}
|
||||
- macos-latest
|
||||
name: "cargo test (${{ matrix.platform }})"
|
||||
runs-on: ${{ matrix.platform }}
|
||||
needs: determine_changes
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
|
||||
timeout-minutes: 20
|
||||
@@ -352,42 +361,6 @@ jobs:
|
||||
with:
|
||||
enable-cache: "true"
|
||||
- name: "Run tests"
|
||||
shell: bash
|
||||
env:
|
||||
NEXTEST_PROFILE: "ci"
|
||||
# Workaround for <https://github.com/nextest-rs/nextest/issues/1493>.
|
||||
RUSTUP_WINDOWS_PATH_ADD_BIN: 1
|
||||
run: |
|
||||
cargo nextest run --all-features --profile ci
|
||||
cargo test --all-features --doc
|
||||
|
||||
cargo-test-macos:
|
||||
name: "cargo test (macos)"
|
||||
runs-on: macos-latest
|
||||
needs: determine_changes
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@522492a8c115f1b6d4d318581f09638e9442547b # v2.62.21
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install uv"
|
||||
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
with:
|
||||
enable-cache: "true"
|
||||
- name: "Run tests"
|
||||
shell: bash
|
||||
env:
|
||||
NEXTEST_PROFILE: "ci"
|
||||
run: |
|
||||
cargo nextest run --all-features --profile ci
|
||||
cargo test --all-features --doc
|
||||
@@ -424,7 +397,7 @@ jobs:
|
||||
|
||||
cargo-build-msrv:
|
||||
name: "cargo build (msrv)"
|
||||
runs-on: depot-ubuntu-latest-8
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-latest-8' || 'ubuntu-latest' }}
|
||||
needs: determine_changes
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
|
||||
timeout-minutes: 20
|
||||
@@ -445,7 +418,6 @@ jobs:
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
|
||||
- name: "Build tests"
|
||||
shell: bash
|
||||
env:
|
||||
MSRV: ${{ steps.msrv.outputs.value }}
|
||||
run: cargo "+${MSRV}" test --no-run --all-features
|
||||
@@ -501,9 +473,10 @@ jobs:
|
||||
chmod +x "${DOWNLOAD_PATH}/ruff"
|
||||
|
||||
(
|
||||
uvx \
|
||||
uv run \
|
||||
--python="${PYTHON_VERSION}" \
|
||||
--from=./python/py-fuzzer \
|
||||
--project=./python/py-fuzzer \
|
||||
--locked \
|
||||
fuzz \
|
||||
--test-executable="${DOWNLOAD_PATH}/ruff" \
|
||||
--bin=ruff \
|
||||
@@ -521,6 +494,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
|
||||
- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup component add rustfmt
|
||||
# Run all code generation scripts, and verify that the current output is
|
||||
@@ -535,10 +509,15 @@ jobs:
|
||||
./scripts/add_plugin.py test --url https://pypi.org/project/-test/0.1.0/ --prefix TST
|
||||
./scripts/add_rule.py --name FirstRule --prefix TST --code 001 --linter test
|
||||
- run: cargo check
|
||||
# Lint/format/type-check py-fuzzer
|
||||
# (dogfooding with ty is done in a separate job)
|
||||
- run: uv run --directory=./python/py-fuzzer mypy
|
||||
- run: uv run --directory=./python/py-fuzzer ruff format --check
|
||||
- run: uv run --directory=./python/py-fuzzer ruff check
|
||||
|
||||
ecosystem:
|
||||
name: "ecosystem"
|
||||
runs-on: depot-ubuntu-latest-8
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-latest-8' || 'ubuntu-latest' }}
|
||||
needs:
|
||||
- cargo-test-linux
|
||||
- determine_changes
|
||||
@@ -550,9 +529,11 @@ jobs:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
|
||||
- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
# TODO: figure out why `ruff-ecosystem` crashes on Python 3.14
|
||||
python-version: "3.13"
|
||||
activate-environment: true
|
||||
|
||||
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
|
||||
name: Download comparison Ruff binary
|
||||
@@ -571,7 +552,7 @@ jobs:
|
||||
|
||||
- name: Install ruff-ecosystem
|
||||
run: |
|
||||
pip install ./python/ruff-ecosystem
|
||||
uv pip install ./python/ruff-ecosystem
|
||||
|
||||
- name: Run `ruff check` stable ecosystem check
|
||||
if: ${{ needs.determine_changes.outputs.linter == 'true' }}
|
||||
@@ -663,13 +644,13 @@ jobs:
|
||||
|
||||
fuzz-ty:
|
||||
name: "Fuzz for new ty panics"
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
|
||||
needs:
|
||||
- cargo-test-linux
|
||||
- determine_changes
|
||||
# Only runs on pull requests, since that is the only we way we can find the base version for comparison.
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && github.event_name == 'pull_request' && (needs.determine_changes.outputs.ty == 'true' || needs.determine_changes.outputs.py-fuzzer == 'true') }}
|
||||
timeout-minutes: 20
|
||||
timeout-minutes: ${{ github.repository == 'astral-sh/ruff' && 5 || 20 }}
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
@@ -697,15 +678,16 @@ jobs:
|
||||
chmod +x "${PWD}/ty" "${NEW_TY}/ty"
|
||||
|
||||
(
|
||||
uvx \
|
||||
uv run \
|
||||
--python="${PYTHON_VERSION}" \
|
||||
--from=./python/py-fuzzer \
|
||||
--project=./python/py-fuzzer \
|
||||
--locked \
|
||||
fuzz \
|
||||
--test-executable="${NEW_TY}/ty" \
|
||||
--baseline-executable="${PWD}/ty" \
|
||||
--only-new-bugs \
|
||||
--bin=ty \
|
||||
0-500
|
||||
0-1000
|
||||
)
|
||||
|
||||
cargo-shear:
|
||||
@@ -723,7 +705,7 @@ jobs:
|
||||
|
||||
ty-completion-evaluation:
|
||||
name: "ty completion evaluation"
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
|
||||
needs: determine_changes
|
||||
if: ${{ needs.determine_changes.outputs.ty == 'true' || github.ref == 'refs/heads/main' }}
|
||||
steps:
|
||||
@@ -769,7 +751,7 @@ jobs:
|
||||
|
||||
pre-commit:
|
||||
name: "pre-commit"
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -806,9 +788,6 @@ jobs:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
|
||||
with:
|
||||
python-version: "3.13"
|
||||
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
|
||||
- name: "Add SSH key"
|
||||
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
|
||||
@@ -819,12 +798,15 @@ jobs:
|
||||
run: rustup show
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
with:
|
||||
python-version: 3.13
|
||||
activate-environment: true
|
||||
- name: "Install Insiders dependencies"
|
||||
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
|
||||
run: uv pip install -r docs/requirements-insiders.txt --system
|
||||
run: uv pip install -r docs/requirements-insiders.txt
|
||||
- name: "Install dependencies"
|
||||
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS != 'true' }}
|
||||
run: uv pip install -r docs/requirements.txt --system
|
||||
run: uv pip install -r docs/requirements.txt
|
||||
- name: "Update README File"
|
||||
run: python scripts/transform_readme.py --target mkdocs
|
||||
- name: "Generate docs"
|
||||
@@ -943,8 +925,12 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: determine_changes
|
||||
if: |
|
||||
github.ref == 'refs/heads/main' ||
|
||||
(needs.determine_changes.outputs.formatter == 'true' || needs.determine_changes.outputs.linter == 'true')
|
||||
github.repository == 'astral-sh/ruff' &&
|
||||
(
|
||||
github.ref == 'refs/heads/main' ||
|
||||
needs.determine_changes.outputs.formatter == 'true' ||
|
||||
needs.determine_changes.outputs.linter == 'true'
|
||||
)
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- name: "Checkout Branch"
|
||||
@@ -978,8 +964,11 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: determine_changes
|
||||
if: |
|
||||
github.ref == 'refs/heads/main' ||
|
||||
needs.determine_changes.outputs.ty == 'true'
|
||||
github.repository == 'astral-sh/ruff' &&
|
||||
(
|
||||
github.ref == 'refs/heads/main' ||
|
||||
needs.determine_changes.outputs.ty == 'true'
|
||||
)
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- name: "Checkout Branch"
|
||||
|
||||
7
.github/workflows/daily_fuzz.yaml
vendored
7
.github/workflows/daily_fuzz.yaml
vendored
@@ -48,9 +48,10 @@ jobs:
|
||||
run: |
|
||||
# shellcheck disable=SC2046
|
||||
(
|
||||
uvx \
|
||||
--python=3.12 \
|
||||
--from=./python/py-fuzzer \
|
||||
uv run \
|
||||
--python=3.14 \
|
||||
--project=./python/py-fuzzer \
|
||||
--locked \
|
||||
fuzz \
|
||||
--test-executable=target/debug/ruff \
|
||||
--bin=ruff \
|
||||
|
||||
10
.github/workflows/mypy_primer.yaml
vendored
10
.github/workflows/mypy_primer.yaml
vendored
@@ -19,6 +19,10 @@ concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
|
||||
cancel-in-progress: true
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
@@ -29,7 +33,7 @@ env:
|
||||
jobs:
|
||||
mypy_primer:
|
||||
name: Run mypy_primer
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-32' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -49,7 +53,6 @@ jobs:
|
||||
run: rustup show
|
||||
|
||||
- name: Run mypy_primer
|
||||
shell: bash
|
||||
env:
|
||||
PRIMER_SELECTOR: crates/ty_python_semantic/resources/primer/good.txt
|
||||
DIFF_FILE: mypy_primer.diff
|
||||
@@ -72,7 +75,7 @@ jobs:
|
||||
|
||||
memory_usage:
|
||||
name: Run memory statistics
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-32' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -92,7 +95,6 @@ jobs:
|
||||
run: rustup show
|
||||
|
||||
- name: Run mypy_primer
|
||||
shell: bash
|
||||
env:
|
||||
TY_MAX_PARALLELISM: 1 # for deterministic memory numbers
|
||||
TY_MEMORY_REPORT: mypy_primer
|
||||
|
||||
5
.github/workflows/publish-playground.yml
vendored
5
.github/workflows/publish-playground.yml
vendored
@@ -18,6 +18,8 @@ env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTUP_MAX_RETRIES: 10
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -32,8 +34,7 @@ jobs:
|
||||
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
|
||||
with:
|
||||
node-version: 22
|
||||
cache: "npm"
|
||||
cache-dependency-path: playground/package-lock.json
|
||||
package-manager-cache: false
|
||||
- uses: jetli/wasm-bindgen-action@20b33e20595891ab1a0ed73145d8a21fc96e7c29 # v0.2.0
|
||||
- name: "Install Node dependencies"
|
||||
run: npm ci
|
||||
|
||||
1
.github/workflows/publish-ty-playground.yml
vendored
1
.github/workflows/publish-ty-playground.yml
vendored
@@ -38,6 +38,7 @@ jobs:
|
||||
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
|
||||
with:
|
||||
node-version: 22
|
||||
package-manager-cache: false
|
||||
- uses: jetli/wasm-bindgen-action@20b33e20595891ab1a0ed73145d8a21fc96e7c29 # v0.2.0
|
||||
- name: "Install Node dependencies"
|
||||
run: npm ci
|
||||
|
||||
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
@@ -1,7 +1,6 @@
|
||||
# This file was autogenerated by dist: https://github.com/astral-sh/cargo-dist
|
||||
# This file was autogenerated by dist: https://axodotdev.github.io/cargo-dist
|
||||
#
|
||||
# Copyright 2022-2024, axodotdev
|
||||
# Copyright 2025 Astral Software Inc.
|
||||
# SPDX-License-Identifier: MIT or Apache-2.0
|
||||
#
|
||||
# CI that:
|
||||
@@ -69,7 +68,7 @@ jobs:
|
||||
# we specify bash to get pipefail; it guards against the `curl` command
|
||||
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
||||
shell: bash
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/cargo-dist/releases/download/v0.28.5-prerelease.1/cargo-dist-installer.sh | sh"
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.30.0/cargo-dist-installer.sh | sh"
|
||||
- name: Cache dist
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
with:
|
||||
|
||||
6
.github/workflows/sync_typeshed.yaml
vendored
6
.github/workflows/sync_typeshed.yaml
vendored
@@ -28,6 +28,10 @@ on:
|
||||
# Run on the 1st and the 15th of every month:
|
||||
- cron: "0 0 1,15 * *"
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
# Don't set this flag globally for the workflow: it does strange things
|
||||
# to the snapshots in the `cargo insta test --accept` step in the MacOS job.
|
||||
@@ -35,6 +39,7 @@ env:
|
||||
# FORCE_COLOR: 1
|
||||
|
||||
CARGO_TERM_COLOR: always
|
||||
NEXTEST_PROFILE: "ci"
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
# The name of the upstream branch that the first worker creates,
|
||||
@@ -133,7 +138,6 @@ jobs:
|
||||
git config --global user.email '<>'
|
||||
- name: Sync Windows docstrings
|
||||
id: docstrings
|
||||
shell: bash
|
||||
env:
|
||||
FORCE_COLOR: 1
|
||||
run: ./scripts/codemod_docstrings.sh
|
||||
|
||||
5
.github/workflows/ty-ecosystem-analyzer.yaml
vendored
5
.github/workflows/ty-ecosystem-analyzer.yaml
vendored
@@ -22,7 +22,7 @@ env:
|
||||
jobs:
|
||||
ty-ecosystem-analyzer:
|
||||
name: Compute diagnostic diff
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-32' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 20
|
||||
if: contains(github.event.label.name, 'ecosystem-analyzer')
|
||||
steps:
|
||||
@@ -34,10 +34,13 @@ jobs:
|
||||
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
with:
|
||||
enable-cache: true # zizmor: ignore[cache-poisoning] acceptable risk for CloudFlare pages artifact
|
||||
|
||||
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
|
||||
with:
|
||||
workspaces: "ruff"
|
||||
lookup-only: false # zizmor: ignore[cache-poisoning] acceptable risk for CloudFlare pages artifact
|
||||
|
||||
- name: Install Rust toolchain
|
||||
run: rustup show
|
||||
|
||||
5
.github/workflows/ty-ecosystem-report.yaml
vendored
5
.github/workflows/ty-ecosystem-report.yaml
vendored
@@ -19,7 +19,7 @@ env:
|
||||
jobs:
|
||||
ty-ecosystem-report:
|
||||
name: Create ecosystem report
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-32' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -30,10 +30,13 @@ jobs:
|
||||
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
|
||||
with:
|
||||
enable-cache: true # zizmor: ignore[cache-poisoning] acceptable risk for CloudFlare pages artifact
|
||||
|
||||
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
|
||||
with:
|
||||
workspaces: "ruff"
|
||||
lookup-only: false # zizmor: ignore[cache-poisoning] acceptable risk for CloudFlare pages artifact
|
||||
|
||||
- name: Install Rust toolchain
|
||||
run: rustup show
|
||||
|
||||
2
.github/workflows/typing_conformance.yaml
vendored
2
.github/workflows/typing_conformance.yaml
vendored
@@ -29,7 +29,7 @@ env:
|
||||
jobs:
|
||||
typing_conformance:
|
||||
name: Compute diagnostic diff
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
runs-on: ${{ github.repository == 'astral-sh/ruff' && 'depot-ubuntu-22.04-32' || 'ubuntu-latest' }}
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
|
||||
13
.github/zizmor.yml
vendored
13
.github/zizmor.yml
vendored
@@ -9,13 +9,18 @@ rules:
|
||||
cache-poisoning:
|
||||
ignore:
|
||||
- build-docker.yml
|
||||
- publish-playground.yml
|
||||
- ty-ecosystem-analyzer.yaml
|
||||
- ty-ecosystem-report.yaml
|
||||
excessive-permissions:
|
||||
# it's hard to test what the impact of removing these ignores would be
|
||||
# without actually running the release workflow...
|
||||
ignore:
|
||||
- build-docker.yml
|
||||
- publish-playground.yml
|
||||
- publish-docs.yml
|
||||
secrets-inherit:
|
||||
# `cargo dist` makes extensive use of `secrets: inherit`,
|
||||
# and we can't easily fix that until an upstream release changes that.
|
||||
disable: true
|
||||
template-injection:
|
||||
ignore:
|
||||
# like with `secrets-inherit`, `cargo dist` introduces some
|
||||
# template injections. We've manually audited these usages for safety.
|
||||
- release.yml
|
||||
|
||||
@@ -35,6 +35,7 @@ repos:
|
||||
rev: 0.7.22
|
||||
hooks:
|
||||
- id: mdformat
|
||||
language: python # means renovate will also update `additional_dependencies`
|
||||
additional_dependencies:
|
||||
- mdformat-mkdocs==4.0.0
|
||||
- mdformat-footnote==0.1.1
|
||||
@@ -58,6 +59,7 @@ repos:
|
||||
rev: 1.19.1
|
||||
hooks:
|
||||
- id: blacken-docs
|
||||
language: python # means renovate will also update `additional_dependencies`
|
||||
args: ["--pyi", "--line-length", "130"]
|
||||
files: '^crates/.*/resources/mdtest/.*\.md'
|
||||
exclude: |
|
||||
@@ -99,8 +101,8 @@ repos:
|
||||
|
||||
# zizmor detects security vulnerabilities in GitHub Actions workflows.
|
||||
# Additional configuration for the tool is found in `.github/zizmor.yml`
|
||||
- repo: https://github.com/woodruffw/zizmor-pre-commit
|
||||
rev: v1.11.0
|
||||
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
||||
rev: v1.15.2
|
||||
hooks:
|
||||
- id: zizmor
|
||||
|
||||
|
||||
106
CHANGELOG.md
106
CHANGELOG.md
@@ -1,5 +1,111 @@
|
||||
# Changelog
|
||||
|
||||
## 0.14.2
|
||||
|
||||
Released on 2025-10-23.
|
||||
|
||||
### Preview features
|
||||
|
||||
- \[`flake8-gettext`\] Resolve qualified names and built-in bindings (`INT001`, `INT002`, `INT003`) ([#19045](https://github.com/astral-sh/ruff/pull/19045))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Avoid reusing nested, interpolated quotes before Python 3.12 ([#20930](https://github.com/astral-sh/ruff/pull/20930))
|
||||
- Catch syntax errors in nested interpolations before Python 3.12 ([#20949](https://github.com/astral-sh/ruff/pull/20949))
|
||||
- \[`fastapi`\] Handle ellipsis defaults in `FAST002` autofix ([#20810](https://github.com/astral-sh/ruff/pull/20810))
|
||||
- \[`flake8-simplify`\] Skip `SIM911` when unknown arguments are present ([#20697](https://github.com/astral-sh/ruff/pull/20697))
|
||||
- \[`pyupgrade`\] Always parenthesize assignment expressions in fix for `f-string` (`UP032`) ([#21003](https://github.com/astral-sh/ruff/pull/21003))
|
||||
- \[`pyupgrade`\] Fix `UP032` conversion for decimal ints with underscores ([#21022](https://github.com/astral-sh/ruff/pull/21022))
|
||||
- \[`fastapi`\] Skip autofix for keyword and `__debug__` path params (`FAST003`) ([#20960](https://github.com/astral-sh/ruff/pull/20960))
|
||||
|
||||
### Rule changes
|
||||
|
||||
- \[`flake8-bugbear`\] Skip `B905` and `B912` for fewer than two iterables and no starred arguments ([#20998](https://github.com/astral-sh/ruff/pull/20998))
|
||||
- \[`ruff`\] Use `DiagnosticTag` for more `pyflakes` and `pandas` rules ([#20801](https://github.com/astral-sh/ruff/pull/20801))
|
||||
|
||||
### CLI
|
||||
|
||||
- Improve JSON output from `ruff rule` ([#20168](https://github.com/astral-sh/ruff/pull/20168))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add source to testimonial ([#20971](https://github.com/astral-sh/ruff/pull/20971))
|
||||
- Document when a rule was added ([#21035](https://github.com/astral-sh/ruff/pull/21035))
|
||||
|
||||
### Other changes
|
||||
|
||||
- [syntax-errors] Name is parameter and global ([#20426](https://github.com/astral-sh/ruff/pull/20426))
|
||||
- [syntax-errors] Alternative `match` patterns bind different names ([#20682](https://github.com/astral-sh/ruff/pull/20682))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@hengky-kurniawan-1](https://github.com/hengky-kurniawan-1)
|
||||
- [@ShalokShalom](https://github.com/ShalokShalom)
|
||||
- [@robsdedude](https://github.com/robsdedude)
|
||||
- [@LoicRiegel](https://github.com/LoicRiegel)
|
||||
- [@TaKO8Ki](https://github.com/TaKO8Ki)
|
||||
- [@dylwil3](https://github.com/dylwil3)
|
||||
- [@11happy](https://github.com/11happy)
|
||||
- [@ntBre](https://github.com/ntBre)
|
||||
|
||||
## 0.14.1
|
||||
|
||||
Released on 2025-10-16.
|
||||
|
||||
### Preview features
|
||||
|
||||
- [formatter] Remove parentheses around multiple exception types on Python 3.14+ ([#20768](https://github.com/astral-sh/ruff/pull/20768))
|
||||
- \[`flake8-bugbear`\] Omit annotation in preview fix for `B006` ([#20877](https://github.com/astral-sh/ruff/pull/20877))
|
||||
- \[`flake8-logging-format`\] Avoid dropping implicitly concatenated pieces in the `G004` fix ([#20793](https://github.com/astral-sh/ruff/pull/20793))
|
||||
- \[`pydoclint`\] Implement `docstring-extraneous-parameter` (`DOC102`) ([#20376](https://github.com/astral-sh/ruff/pull/20376))
|
||||
- \[`pyupgrade`\] Extend `UP019` to detect `typing_extensions.Text` (`UP019`) ([#20825](https://github.com/astral-sh/ruff/pull/20825))
|
||||
- \[`pyupgrade`\] Fix false negative for `TypeVar` with default argument in `non-pep695-generic-class` (`UP046`) ([#20660](https://github.com/astral-sh/ruff/pull/20660))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fix false negatives in `Truthiness::from_expr` for lambdas, generators, and f-strings ([#20704](https://github.com/astral-sh/ruff/pull/20704))
|
||||
- Fix syntax error false positives for escapes and quotes in f-strings ([#20867](https://github.com/astral-sh/ruff/pull/20867))
|
||||
- Fix syntax error false positives on parenthesized context managers ([#20846](https://github.com/astral-sh/ruff/pull/20846))
|
||||
- \[`fastapi`\] Fix false positives for path parameters that FastAPI doesn't recognize (`FAST003`) ([#20687](https://github.com/astral-sh/ruff/pull/20687))
|
||||
- \[`flake8-pyi`\] Fix operator precedence by adding parentheses when needed (`PYI061`) ([#20508](https://github.com/astral-sh/ruff/pull/20508))
|
||||
- \[`ruff`\] Suppress diagnostic for f-string interpolations with debug text (`RUF010`) ([#20525](https://github.com/astral-sh/ruff/pull/20525))
|
||||
|
||||
### Rule changes
|
||||
|
||||
- \[`airflow`\] Add warning to `airflow.datasets.DatasetEvent` usage (`AIR301`) ([#20551](https://github.com/astral-sh/ruff/pull/20551))
|
||||
- \[`flake8-bugbear`\] Mark `B905` and `B912` fixes as unsafe ([#20695](https://github.com/astral-sh/ruff/pull/20695))
|
||||
- Use `DiagnosticTag` for more rules - changes display in editors ([#20758](https://github.com/astral-sh/ruff/pull/20758),[#20734](https://github.com/astral-sh/ruff/pull/20734))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Update Python compatibility from 3.13 to 3.14 in README.md ([#20852](https://github.com/astral-sh/ruff/pull/20852))
|
||||
- Update `lint.flake8-type-checking.quoted-annotations` docs ([#20765](https://github.com/astral-sh/ruff/pull/20765))
|
||||
- Update setup instructions for Zed 0.208.0+ ([#20902](https://github.com/astral-sh/ruff/pull/20902))
|
||||
- \[`flake8-datetimez`\] Clarify docs for several rules ([#20778](https://github.com/astral-sh/ruff/pull/20778))
|
||||
- Fix typo in `RUF015` description ([#20873](https://github.com/astral-sh/ruff/pull/20873))
|
||||
|
||||
### Other changes
|
||||
|
||||
- Reduce binary size ([#20863](https://github.com/astral-sh/ruff/pull/20863))
|
||||
- Improved error recovery for unclosed strings (including f- and t-strings) ([#20848](https://github.com/astral-sh/ruff/pull/20848))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@ntBre](https://github.com/ntBre)
|
||||
- [@Paillat-dev](https://github.com/Paillat-dev)
|
||||
- [@terror](https://github.com/terror)
|
||||
- [@pieterh-oai](https://github.com/pieterh-oai)
|
||||
- [@MichaReiser](https://github.com/MichaReiser)
|
||||
- [@TaKO8Ki](https://github.com/TaKO8Ki)
|
||||
- [@ageorgou](https://github.com/ageorgou)
|
||||
- [@danparizher](https://github.com/danparizher)
|
||||
- [@mgaitan](https://github.com/mgaitan)
|
||||
- [@augustelalande](https://github.com/augustelalande)
|
||||
- [@dylwil3](https://github.com/dylwil3)
|
||||
- [@Lee-W](https://github.com/Lee-W)
|
||||
- [@injust](https://github.com/injust)
|
||||
- [@CarrotManMatt](https://github.com/CarrotManMatt)
|
||||
|
||||
## 0.14.0
|
||||
|
||||
Released on 2025-10-07.
|
||||
|
||||
140
Cargo.lock
generated
140
Cargo.lock
generated
@@ -433,9 +433,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.48"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae"
|
||||
checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -443,9 +443,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.48"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9"
|
||||
checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -486,9 +486,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.47"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
|
||||
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -633,7 +633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -642,7 +642,7 @@ version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1007,7 +1007,7 @@ dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.61.0",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1093,7 +1093,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.61.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1262,20 +1262,20 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.7+wasi-0.2.4",
|
||||
"wasip2",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
@@ -1287,9 +1287,9 @@ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
||||
|
||||
[[package]]
|
||||
name = "globset"
|
||||
version = "0.4.16"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54a1028dfc5f5df5da8a56a73e6c153c9a9708ec57232470703592a3f18e49f5"
|
||||
checksum = "eab69130804d941f8075cfd713bf8848a2c3b3f201a9457a11e6f87e1ab62305"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"bstr",
|
||||
@@ -1690,7 +1690,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1754,7 +1754,7 @@ dependencies = [
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1789,7 +1789,7 @@ version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@@ -2072,7 +2072,7 @@ checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
"wasi",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
@@ -2627,9 +2627,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
version = "1.0.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -2724,7 +2724,7 @@ version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2767,6 +2767,26 @@ dependencies = [
|
||||
"thiserror 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ref-cast"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d"
|
||||
dependencies = [
|
||||
"ref-cast-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ref-cast-impl"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.3"
|
||||
@@ -2781,9 +2801,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.11"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "833eb9ce86d40ef33cb1306d8accf7bc8ec2bfea4355cbdebb3df68b40925cad"
|
||||
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -2815,7 +2835,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruff"
|
||||
version = "0.14.0"
|
||||
version = "0.14.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argfile",
|
||||
@@ -3072,7 +3092,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruff_linter"
|
||||
version = "0.14.0"
|
||||
version = "0.14.2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"anyhow",
|
||||
@@ -3197,6 +3217,7 @@ dependencies = [
|
||||
"salsa",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.16",
|
||||
]
|
||||
|
||||
@@ -3426,11 +3447,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruff_wasm"
|
||||
version = "0.14.0"
|
||||
version = "0.14.2"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"console_log",
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
"js-sys",
|
||||
"log",
|
||||
"ruff_formatter",
|
||||
@@ -3484,6 +3505,7 @@ dependencies = [
|
||||
"rustc-hash",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shellexpand",
|
||||
"strum",
|
||||
"tempfile",
|
||||
@@ -3523,7 +3545,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.61.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3541,7 +3563,7 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
[[package]]
|
||||
name = "salsa"
|
||||
version = "0.24.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=ef9f9329be6923acd050c8dddd172e3bc93e8051#ef9f9329be6923acd050c8dddd172e3bc93e8051"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=d38145c29574758de7ffbe8a13cd4584c3b09161#d38145c29574758de7ffbe8a13cd4584c3b09161"
|
||||
dependencies = [
|
||||
"boxcar",
|
||||
"compact_str",
|
||||
@@ -3565,12 +3587,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "salsa-macro-rules"
|
||||
version = "0.24.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=ef9f9329be6923acd050c8dddd172e3bc93e8051#ef9f9329be6923acd050c8dddd172e3bc93e8051"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=d38145c29574758de7ffbe8a13cd4584c3b09161#d38145c29574758de7ffbe8a13cd4584c3b09161"
|
||||
|
||||
[[package]]
|
||||
name = "salsa-macros"
|
||||
version = "0.24.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=ef9f9329be6923acd050c8dddd172e3bc93e8051#ef9f9329be6923acd050c8dddd172e3bc93e8051"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=d38145c29574758de7ffbe8a13cd4584c3b09161#d38145c29574758de7ffbe8a13cd4584c3b09161"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3589,11 +3611,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "schemars"
|
||||
version = "0.8.22"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615"
|
||||
checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0"
|
||||
dependencies = [
|
||||
"dyn-clone",
|
||||
"ref-cast",
|
||||
"schemars_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -3601,9 +3624,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "schemars_derive"
|
||||
version = "0.8.22"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d"
|
||||
checksum = "33d020396d1d138dc19f1165df7545479dcd58d93810dc5d646a16e55abefa80"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3625,9 +3648,9 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.226"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
@@ -3646,18 +3669,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.226"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.226"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3795,9 +3818,9 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
|
||||
[[package]]
|
||||
name = "snapbox"
|
||||
version = "0.6.21"
|
||||
version = "0.6.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96dcfc4581e3355d70ac2ee14cfdf81dce3d85c85f1ed9e2c1d3013f53b3436b"
|
||||
checksum = "805d09a74586d9b17061e5be6ee5f8cc37e5982c349948114ffc5f68093fe5ec"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -3810,7 +3833,7 @@ dependencies = [
|
||||
"similar",
|
||||
"snapbox-macros",
|
||||
"wait-timeout",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3915,10 +3938,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.61.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4353,6 +4376,7 @@ dependencies = [
|
||||
"tracing",
|
||||
"ty_project",
|
||||
"ty_python_semantic",
|
||||
"ty_vendored",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4384,6 +4408,7 @@ dependencies = [
|
||||
"salsa",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.16",
|
||||
"toml",
|
||||
"tracing",
|
||||
@@ -4409,10 +4434,12 @@ dependencies = [
|
||||
"glob",
|
||||
"hashbrown 0.16.0",
|
||||
"indexmap",
|
||||
"indoc",
|
||||
"insta",
|
||||
"itertools 0.14.0",
|
||||
"memchr",
|
||||
"ordermap",
|
||||
"pretty_assertions",
|
||||
"quickcheck",
|
||||
"quickcheck_macros",
|
||||
"ruff_annotate_snippets",
|
||||
@@ -4431,6 +4458,7 @@ dependencies = [
|
||||
"salsa",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"static_assertions",
|
||||
"strsim",
|
||||
@@ -4479,7 +4507,6 @@ dependencies = [
|
||||
"ty_ide",
|
||||
"ty_project",
|
||||
"ty_python_semantic",
|
||||
"ty_vendored",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4539,7 +4566,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"console_log",
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
"js-sys",
|
||||
"log",
|
||||
"ruff_db",
|
||||
@@ -4732,7 +4759,7 @@ version = "1.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"getrandom 0.3.4",
|
||||
"js-sys",
|
||||
"rand 0.9.2",
|
||||
"uuid-macro-internal",
|
||||
@@ -4844,15 +4871,6 @@ version = "0.11.1+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.14.7+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
|
||||
dependencies = [
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
@@ -5004,7 +5022,7 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -146,13 +146,13 @@ regex-automata = { version = "0.4.9" }
|
||||
rustc-hash = { version = "2.0.0" }
|
||||
rustc-stable-hash = { version = "0.1.2" }
|
||||
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
|
||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "ef9f9329be6923acd050c8dddd172e3bc93e8051", default-features = false, features = [
|
||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "d38145c29574758de7ffbe8a13cd4584c3b09161", default-features = false, features = [
|
||||
"compact_str",
|
||||
"macros",
|
||||
"salsa_unstable",
|
||||
"inventory",
|
||||
] }
|
||||
schemars = { version = "0.8.16" }
|
||||
schemars = { version = "1.0.4" }
|
||||
seahash = { version = "4.1.0" }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde-wasm-bindgen = { version = "0.6.4" }
|
||||
|
||||
@@ -89,8 +89,7 @@ creator of [isort](https://github.com/PyCQA/isort):
|
||||
> Just switched my first project to Ruff. Only one downside so far: it's so fast I couldn't believe
|
||||
> it was working till I intentionally introduced some errors.
|
||||
|
||||
[**Tim Abbott**](https://github.com/astral-sh/ruff/issues/465#issuecomment-1317400028), lead
|
||||
developer of [Zulip](https://github.com/zulip/zulip):
|
||||
[**Tim Abbott**](https://github.com/zulip/zulip/pull/23431#issuecomment-1302557034), lead developer of [Zulip](https://github.com/zulip/zulip) (also [here](https://github.com/astral-sh/ruff/issues/465#issuecomment-1317400028)):
|
||||
|
||||
> This is just ridiculously fast... `ruff` is amazing.
|
||||
|
||||
@@ -148,8 +147,8 @@ curl -LsSf https://astral.sh/ruff/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"
|
||||
|
||||
# For a specific version.
|
||||
curl -LsSf https://astral.sh/ruff/0.14.0/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/0.14.0/install.ps1 | iex"
|
||||
curl -LsSf https://astral.sh/ruff/0.14.2/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/0.14.2/install.ps1 | iex"
|
||||
```
|
||||
|
||||
You can also install Ruff via [Homebrew](https://formulae.brew.sh/formula/ruff), [Conda](https://anaconda.org/conda-forge/ruff),
|
||||
@@ -182,7 +181,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com/) hook via [`ruff
|
||||
```yaml
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.14.0
|
||||
rev: v0.14.2
|
||||
hooks:
|
||||
# Run the linter.
|
||||
- id: ruff-check
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ruff"
|
||||
version = "0.14.0"
|
||||
version = "0.14.2"
|
||||
publish = true
|
||||
authors = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
|
||||
@@ -879,19 +879,7 @@ impl From<&FormatCommandError> for Diagnostic {
|
||||
| FormatCommandError::Write(_, source_error) => {
|
||||
Diagnostic::new(DiagnosticId::Io, Severity::Error, source_error)
|
||||
}
|
||||
FormatCommandError::Format(_, format_module_error) => match format_module_error {
|
||||
FormatModuleError::ParseError(parse_error) => Diagnostic::new(
|
||||
DiagnosticId::InternalError,
|
||||
Severity::Error,
|
||||
&parse_error.error,
|
||||
),
|
||||
FormatModuleError::FormatError(format_error) => {
|
||||
Diagnostic::new(DiagnosticId::InternalError, Severity::Error, format_error)
|
||||
}
|
||||
FormatModuleError::PrintError(print_error) => {
|
||||
Diagnostic::new(DiagnosticId::InternalError, Severity::Error, print_error)
|
||||
}
|
||||
},
|
||||
FormatCommandError::Format(_, format_module_error) => format_module_error.into(),
|
||||
FormatCommandError::RangeFormatNotebook(_) => Diagnostic::new(
|
||||
DiagnosticId::InvalidCliOption,
|
||||
Severity::Error,
|
||||
|
||||
@@ -7,6 +7,7 @@ use serde::{Serialize, Serializer};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff_linter::FixAvailability;
|
||||
use ruff_linter::codes::RuleGroup;
|
||||
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
|
||||
|
||||
use crate::args::HelpFormat;
|
||||
@@ -19,9 +20,12 @@ struct Explanation<'a> {
|
||||
summary: &'a str,
|
||||
message_formats: &'a [&'a str],
|
||||
fix: String,
|
||||
fix_availability: FixAvailability,
|
||||
#[expect(clippy::struct_field_names)]
|
||||
explanation: Option<&'a str>,
|
||||
preview: bool,
|
||||
status: RuleGroup,
|
||||
source_location: SourceLocation,
|
||||
}
|
||||
|
||||
impl<'a> Explanation<'a> {
|
||||
@@ -36,8 +40,14 @@ impl<'a> Explanation<'a> {
|
||||
summary: rule.message_formats()[0],
|
||||
message_formats: rule.message_formats(),
|
||||
fix,
|
||||
fix_availability: rule.fixable(),
|
||||
explanation: rule.explanation(),
|
||||
preview: rule.is_preview(),
|
||||
status: rule.group(),
|
||||
source_location: SourceLocation {
|
||||
file: rule.file(),
|
||||
line: rule.line(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,3 +132,14 @@ pub(crate) fn rules(format: HelpFormat) -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The location of the rule's implementation in the Ruff source tree, relative to the repository
|
||||
/// root.
|
||||
///
|
||||
/// For most rules this will point to the `#[derive(ViolationMetadata)]` line above the rule's
|
||||
/// struct.
|
||||
#[derive(Serialize)]
|
||||
struct SourceLocation {
|
||||
file: &'static str,
|
||||
line: u32,
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use log::{debug, warn};
|
||||
use ruff_db::diagnostic::Diagnostic;
|
||||
use ruff_linter::codes::Rule;
|
||||
use ruff_linter::linter::{FixTable, FixerResult, LinterResult, ParseSource, lint_fix, lint_only};
|
||||
use ruff_linter::message::create_syntax_error_diagnostic;
|
||||
use ruff_linter::package::PackageRoot;
|
||||
use ruff_linter::pyproject_toml::lint_pyproject_toml;
|
||||
use ruff_linter::settings::types::UnsafeFixes;
|
||||
@@ -103,11 +102,7 @@ impl Diagnostics {
|
||||
let name = path.map_or_else(|| "-".into(), Path::to_string_lossy);
|
||||
let dummy = SourceFileBuilder::new(name, "").finish();
|
||||
Self::new(
|
||||
vec![create_syntax_error_diagnostic(
|
||||
dummy,
|
||||
err,
|
||||
TextRange::default(),
|
||||
)],
|
||||
vec![Diagnostic::invalid_syntax(dummy, err, TextRange::default())],
|
||||
FxHashMap::default(),
|
||||
)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@ use std::{
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
|
||||
mod format;
|
||||
mod lint;
|
||||
|
||||
const BIN_NAME: &str = "ruff";
|
||||
@@ -57,6 +58,16 @@ impl CliTest {
|
||||
Self::with_settings(|_, settings| settings)
|
||||
}
|
||||
|
||||
pub(crate) fn with_files<'a>(
|
||||
files: impl IntoIterator<Item = (&'a str, &'a str)>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let case = Self::new()?;
|
||||
for file in files {
|
||||
case.write_file(file.0, file.1)?;
|
||||
}
|
||||
Ok(case)
|
||||
}
|
||||
|
||||
pub(crate) fn with_settings(
|
||||
setup_settings: impl FnOnce(&Path, insta::Settings) -> insta::Settings,
|
||||
) -> Result<Self> {
|
||||
@@ -174,4 +185,10 @@ impl CliTest {
|
||||
|
||||
command
|
||||
}
|
||||
|
||||
pub(crate) fn format_command(&self) -> Command {
|
||||
let mut command = self.command();
|
||||
command.args(["format", "--no-cache"]);
|
||||
command
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -7,6 +7,7 @@ info:
|
||||
- "--no-cache"
|
||||
- "--output-format"
|
||||
- grouped
|
||||
- "--preview"
|
||||
- "--check"
|
||||
- input.py
|
||||
---
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -7,6 +7,7 @@ info:
|
||||
- "--no-cache"
|
||||
- "--output-format"
|
||||
- pylint
|
||||
- "--preview"
|
||||
- "--check"
|
||||
- input.py
|
||||
---
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: crates/ruff/tests/format.rs
|
||||
source: crates/ruff/tests/cli/format.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
@@ -951,6 +951,20 @@ fn rule_f401() {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "F401"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_f401_output_json() {
|
||||
insta::with_settings!({filters => vec![
|
||||
(r#"("file": ")[^"]+(",)"#, "$1<FILE>$2"),
|
||||
]}, {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "F401", "--output-format", "json"]));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_f401_output_text() {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "F401", "--output-format", "text"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_invalid_rule_name() {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "RUF404"]), @r"
|
||||
@@ -965,6 +979,34 @@ fn rule_invalid_rule_name() {
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_invalid_rule_name_output_json() {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "RUF404", "--output-format", "json"]), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: invalid value 'RUF404' for '[RULE]'
|
||||
|
||||
For more information, try '--help'.
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_invalid_rule_name_output_text() {
|
||||
assert_cmd_snapshot!(ruff_cmd().args(["rule", "RUF404", "--output-format", "text"]), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: invalid value 'RUF404' for '[RULE]'
|
||||
|
||||
For more information, try '--help'.
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_statistics() {
|
||||
let mut cmd = RuffCheck::default()
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
source: crates/ruff/tests/integration_test.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
- rule
|
||||
- F401
|
||||
- "--output-format"
|
||||
- json
|
||||
---
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
{
|
||||
"name": "unused-import",
|
||||
"code": "F401",
|
||||
"linter": "Pyflakes",
|
||||
"summary": "`{name}` imported but unused; consider using `importlib.util.find_spec` to test for availability",
|
||||
"message_formats": [
|
||||
"`{name}` imported but unused; consider using `importlib.util.find_spec` to test for availability",
|
||||
"`{name}` imported but unused; consider removing, adding to `__all__`, or using a redundant alias",
|
||||
"`{name}` imported but unused"
|
||||
],
|
||||
"fix": "Fix is sometimes available.",
|
||||
"fix_availability": "Sometimes",
|
||||
"explanation": "## What it does\nChecks for unused imports.\n\n## Why is this bad?\nUnused imports add a performance overhead at runtime, and risk creating\nimport cycles. They also increase the cognitive load of reading the code.\n\nIf an import statement is used to check for the availability or existence\nof a module, consider using `importlib.util.find_spec` instead.\n\nIf an import statement is used to re-export a symbol as part of a module's\npublic interface, consider using a \"redundant\" import alias, which\ninstructs Ruff (and other tools) to respect the re-export, and avoid\nmarking it as unused, as in:\n\n```python\nfrom module import member as member\n```\n\nAlternatively, you can use `__all__` to declare a symbol as part of the module's\ninterface, as in:\n\n```python\n# __init__.py\nimport some_module\n\n__all__ = [\"some_module\"]\n```\n\n## Preview\nWhen [preview] is enabled (and certain simplifying assumptions\nare met), we analyze all import statements for a given module\nwhen determining whether an import is used, rather than simply\nthe last of these statements. This can result in both different and\nmore import statements being marked as unused.\n\nFor example, if a module consists of\n\n```python\nimport a\nimport a.b\n```\n\nthen both statements are marked as unused under [preview], whereas\nonly the second is marked as unused under stable behavior.\n\nAs another example, if a module consists of\n\n```python\nimport a.b\nimport a\n\na.b.foo()\n```\n\nthen a diagnostic will only be emitted for the first line under [preview],\nwhereas a diagnostic would only be emitted for the second line under\nstable behavior.\n\nNote that this behavior is somewhat subjective and is designed\nto conform to the developer's intuition rather than Python's actual\nexecution. To wit, the statement `import a.b` automatically executes\n`import a`, so in some sense `import a` is _always_ redundant\nin the presence of `import a.b`.\n\n\n## Fix safety\n\nFixes to remove unused imports are safe, except in `__init__.py` files.\n\nApplying fixes to `__init__.py` files is currently in preview. The fix offered depends on the\ntype of the unused import. Ruff will suggest a safe fix to export first-party imports with\neither a redundant alias or, if already present in the file, an `__all__` entry. If multiple\n`__all__` declarations are present, Ruff will not offer a fix. Ruff will suggest an unsafe fix\nto remove third-party and standard library imports -- the fix is unsafe because the module's\ninterface changes.\n\nSee [this FAQ section](https://docs.astral.sh/ruff/faq/#how-does-ruff-determine-which-of-my-imports-are-first-party-third-party-etc)\nfor more details on how Ruff\ndetermines whether an import is first or third-party.\n\n## Example\n\n```python\nimport numpy as np # unused import\n\n\ndef area(radius):\n return 3.14 * radius**2\n```\n\nUse instead:\n\n```python\ndef area(radius):\n return 3.14 * radius**2\n```\n\nTo check the availability of a module, use `importlib.util.find_spec`:\n\n```python\nfrom importlib.util import find_spec\n\nif find_spec(\"numpy\") is not None:\n print(\"numpy is installed\")\nelse:\n print(\"numpy is not installed\")\n```\n\n## Options\n- `lint.ignore-init-module-imports`\n- `lint.pyflakes.allowed-unused-imports`\n\n## References\n- [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement)\n- [Python documentation: `importlib.util.find_spec`](https://docs.python.org/3/library/importlib.html#importlib.util.find_spec)\n- [Typing documentation: interface conventions](https://typing.python.org/en/latest/spec/distributing.html#library-interface-public-and-private-symbols)\n\n[preview]: https://docs.astral.sh/ruff/preview/\n",
|
||||
"preview": false,
|
||||
"status": {
|
||||
"Stable": {
|
||||
"since": "v0.0.18"
|
||||
}
|
||||
},
|
||||
"source_location": {
|
||||
"file": "<FILE>",
|
||||
"line": 145
|
||||
}
|
||||
}
|
||||
----- stderr -----
|
||||
@@ -0,0 +1,140 @@
|
||||
---
|
||||
source: crates/ruff/tests/integration_test.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
- rule
|
||||
- F401
|
||||
- "--output-format"
|
||||
- text
|
||||
---
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# unused-import (F401)
|
||||
|
||||
Derived from the **Pyflakes** linter.
|
||||
|
||||
Fix is sometimes available.
|
||||
|
||||
## What it does
|
||||
Checks for unused imports.
|
||||
|
||||
## Why is this bad?
|
||||
Unused imports add a performance overhead at runtime, and risk creating
|
||||
import cycles. They also increase the cognitive load of reading the code.
|
||||
|
||||
If an import statement is used to check for the availability or existence
|
||||
of a module, consider using `importlib.util.find_spec` instead.
|
||||
|
||||
If an import statement is used to re-export a symbol as part of a module's
|
||||
public interface, consider using a "redundant" import alias, which
|
||||
instructs Ruff (and other tools) to respect the re-export, and avoid
|
||||
marking it as unused, as in:
|
||||
|
||||
```python
|
||||
from module import member as member
|
||||
```
|
||||
|
||||
Alternatively, you can use `__all__` to declare a symbol as part of the module's
|
||||
interface, as in:
|
||||
|
||||
```python
|
||||
# __init__.py
|
||||
import some_module
|
||||
|
||||
__all__ = ["some_module"]
|
||||
```
|
||||
|
||||
## Preview
|
||||
When [preview] is enabled (and certain simplifying assumptions
|
||||
are met), we analyze all import statements for a given module
|
||||
when determining whether an import is used, rather than simply
|
||||
the last of these statements. This can result in both different and
|
||||
more import statements being marked as unused.
|
||||
|
||||
For example, if a module consists of
|
||||
|
||||
```python
|
||||
import a
|
||||
import a.b
|
||||
```
|
||||
|
||||
then both statements are marked as unused under [preview], whereas
|
||||
only the second is marked as unused under stable behavior.
|
||||
|
||||
As another example, if a module consists of
|
||||
|
||||
```python
|
||||
import a.b
|
||||
import a
|
||||
|
||||
a.b.foo()
|
||||
```
|
||||
|
||||
then a diagnostic will only be emitted for the first line under [preview],
|
||||
whereas a diagnostic would only be emitted for the second line under
|
||||
stable behavior.
|
||||
|
||||
Note that this behavior is somewhat subjective and is designed
|
||||
to conform to the developer's intuition rather than Python's actual
|
||||
execution. To wit, the statement `import a.b` automatically executes
|
||||
`import a`, so in some sense `import a` is _always_ redundant
|
||||
in the presence of `import a.b`.
|
||||
|
||||
|
||||
## Fix safety
|
||||
|
||||
Fixes to remove unused imports are safe, except in `__init__.py` files.
|
||||
|
||||
Applying fixes to `__init__.py` files is currently in preview. The fix offered depends on the
|
||||
type of the unused import. Ruff will suggest a safe fix to export first-party imports with
|
||||
either a redundant alias or, if already present in the file, an `__all__` entry. If multiple
|
||||
`__all__` declarations are present, Ruff will not offer a fix. Ruff will suggest an unsafe fix
|
||||
to remove third-party and standard library imports -- the fix is unsafe because the module's
|
||||
interface changes.
|
||||
|
||||
See [this FAQ section](https://docs.astral.sh/ruff/faq/#how-does-ruff-determine-which-of-my-imports-are-first-party-third-party-etc)
|
||||
for more details on how Ruff
|
||||
determines whether an import is first or third-party.
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
import numpy as np # unused import
|
||||
|
||||
|
||||
def area(radius):
|
||||
return 3.14 * radius**2
|
||||
```
|
||||
|
||||
Use instead:
|
||||
|
||||
```python
|
||||
def area(radius):
|
||||
return 3.14 * radius**2
|
||||
```
|
||||
|
||||
To check the availability of a module, use `importlib.util.find_spec`:
|
||||
|
||||
```python
|
||||
from importlib.util import find_spec
|
||||
|
||||
if find_spec("numpy") is not None:
|
||||
print("numpy is installed")
|
||||
else:
|
||||
print("numpy is not installed")
|
||||
```
|
||||
|
||||
## Options
|
||||
- `lint.ignore-init-module-imports`
|
||||
- `lint.pyflakes.allowed-unused-imports`
|
||||
|
||||
## References
|
||||
- [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement)
|
||||
- [Python documentation: `importlib.util.find_spec`](https://docs.python.org/3/library/importlib.html#importlib.util.find_spec)
|
||||
- [Typing documentation: interface conventions](https://typing.python.org/en/latest/spec/distributing.html#library-interface-public-and-private-symbols)
|
||||
|
||||
[preview]: https://docs.astral.sh/ruff/preview/
|
||||
|
||||
----- stderr -----
|
||||
@@ -667,7 +667,7 @@ fn attrs(criterion: &mut Criterion) {
|
||||
max_dep_date: "2025-06-17",
|
||||
python_version: PythonVersion::PY313,
|
||||
},
|
||||
100,
|
||||
110,
|
||||
);
|
||||
|
||||
bench_project(&benchmark, criterion);
|
||||
@@ -684,7 +684,7 @@ fn anyio(criterion: &mut Criterion) {
|
||||
max_dep_date: "2025-06-17",
|
||||
python_version: PythonVersion::PY313,
|
||||
},
|
||||
100,
|
||||
150,
|
||||
);
|
||||
|
||||
bench_project(&benchmark, criterion);
|
||||
|
||||
@@ -210,7 +210,7 @@ static TANJUN: Benchmark = Benchmark::new(
|
||||
max_dep_date: "2025-06-17",
|
||||
python_version: PythonVersion::PY312,
|
||||
},
|
||||
100,
|
||||
320,
|
||||
);
|
||||
|
||||
static STATIC_FRAME: Benchmark = Benchmark::new(
|
||||
@@ -226,7 +226,7 @@ static STATIC_FRAME: Benchmark = Benchmark::new(
|
||||
max_dep_date: "2025-08-09",
|
||||
python_version: PythonVersion::PY311,
|
||||
},
|
||||
630,
|
||||
750,
|
||||
);
|
||||
|
||||
#[track_caller]
|
||||
|
||||
@@ -84,17 +84,14 @@ impl Diagnostic {
|
||||
/// at time of writing, `ruff_db` depends on `ruff_python_parser` instead of
|
||||
/// the other way around. And since we want to do this conversion in a couple
|
||||
/// places, it makes sense to centralize it _somewhere_. So it's here for now.
|
||||
///
|
||||
/// Note that `message` is stored in the primary annotation, _not_ in the primary diagnostic
|
||||
/// message.
|
||||
pub fn invalid_syntax(
|
||||
span: impl Into<Span>,
|
||||
message: impl IntoDiagnosticMessage,
|
||||
range: impl Ranged,
|
||||
) -> Diagnostic {
|
||||
let mut diag = Diagnostic::new(DiagnosticId::InvalidSyntax, Severity::Error, "");
|
||||
let mut diag = Diagnostic::new(DiagnosticId::InvalidSyntax, Severity::Error, message);
|
||||
let span = span.into().with_range(range.range());
|
||||
diag.annotate(Annotation::primary(span).message(message));
|
||||
diag.annotate(Annotation::primary(span));
|
||||
diag
|
||||
}
|
||||
|
||||
|
||||
@@ -190,9 +190,21 @@ impl Files {
|
||||
let roots = self.inner.roots.read().unwrap();
|
||||
|
||||
let absolute = SystemPath::absolute(path, db.system().current_directory());
|
||||
|
||||
roots.at(&absolute)
|
||||
}
|
||||
|
||||
/// The same as [`Self::root`] but panics if no root is found.
|
||||
#[track_caller]
|
||||
pub fn expect_root(&self, db: &dyn Db, path: &SystemPath) -> FileRoot {
|
||||
if let Some(root) = self.root(db, path) {
|
||||
return root;
|
||||
}
|
||||
|
||||
let roots = self.inner.roots.read().unwrap();
|
||||
panic!("No root found for path '{path}'. Known roots: {roots:#?}");
|
||||
}
|
||||
|
||||
/// Adds a new root for `path` and returns the root.
|
||||
///
|
||||
/// The root isn't added nor is the file root's kind updated if a root for `path` already exists.
|
||||
@@ -200,7 +212,10 @@ impl Files {
|
||||
let mut roots = self.inner.roots.write().unwrap();
|
||||
|
||||
let absolute = SystemPath::absolute(path, db.system().current_directory());
|
||||
roots.try_add(db, absolute, kind)
|
||||
// We need to resolve away symlinks here to avoid getting confused about subdirectories.
|
||||
let canonicalized = db.system().canonicalize_path(&absolute).unwrap_or(absolute);
|
||||
|
||||
roots.try_add(db, canonicalized, kind)
|
||||
}
|
||||
|
||||
/// Updates the revision of the root for `path`.
|
||||
|
||||
@@ -81,6 +81,8 @@ impl FileRoots {
|
||||
}
|
||||
}
|
||||
|
||||
tracing::debug!("Adding new file root '{path}' of kind {kind:?}");
|
||||
|
||||
// normalize the path to use `/` separators and escape the '{' and '}' characters,
|
||||
// which matchit uses for routing parameters
|
||||
let mut route = normalized_path.replace('{', "{{").replace('}', "}}");
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::path::PathBuf;
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
use regex::{Captures, Regex};
|
||||
use ruff_linter::codes::RuleGroup;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff_linter::FixAvailability;
|
||||
@@ -31,6 +32,47 @@ pub(crate) fn main(args: &Args) -> Result<()> {
|
||||
|
||||
let _ = writeln!(&mut output, "# {} ({})", rule.name(), rule.noqa_code());
|
||||
|
||||
let status_text = match rule.group() {
|
||||
RuleGroup::Stable { since } => {
|
||||
format!(
|
||||
r#"Added in <a href="https://github.com/astral-sh/ruff/releases/tag/{since}">{since}</a>"#
|
||||
)
|
||||
}
|
||||
RuleGroup::Preview { since } => {
|
||||
format!(
|
||||
r#"Preview (since <a href="https://github.com/astral-sh/ruff/releases/tag/{since}">{since}</a>)"#
|
||||
)
|
||||
}
|
||||
RuleGroup::Deprecated { since } => {
|
||||
format!(
|
||||
r#"Deprecated (since <a href="https://github.com/astral-sh/ruff/releases/tag/{since}">{since}</a>)"#
|
||||
)
|
||||
}
|
||||
RuleGroup::Removed { since } => {
|
||||
format!(
|
||||
r#"Removed (since <a href="https://github.com/astral-sh/ruff/releases/tag/{since}">{since}</a>)"#
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let _ = writeln!(
|
||||
&mut output,
|
||||
r#"<small>
|
||||
{status_text} ·
|
||||
<a href="https://github.com/astral-sh/ruff/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20(%27{encoded_name}%27%20OR%20{rule_code})" target="_blank">Related issues</a> ·
|
||||
<a href="https://github.com/astral-sh/ruff/blob/main/{file}#L{line}" target="_blank">View source</a>
|
||||
</small>
|
||||
|
||||
"#,
|
||||
encoded_name =
|
||||
url::form_urlencoded::byte_serialize(rule.name().as_str().as_bytes())
|
||||
.collect::<String>(),
|
||||
rule_code = rule.noqa_code(),
|
||||
file =
|
||||
url::form_urlencoded::byte_serialize(rule.file().replace('\\', "/").as_bytes())
|
||||
.collect::<String>(),
|
||||
line = rule.line(),
|
||||
);
|
||||
let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap();
|
||||
if linter.url().is_some() {
|
||||
let common_prefix: String = match linter.common_prefix() {
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use pretty_assertions::StrComparison;
|
||||
use schemars::schema_for;
|
||||
use schemars::generate::SchemaSettings;
|
||||
|
||||
use crate::ROOT_DIR;
|
||||
use crate::generate_all::{Mode, REGENERATE_ALL_COMMAND};
|
||||
@@ -17,7 +17,9 @@ pub(crate) struct Args {
|
||||
}
|
||||
|
||||
pub(crate) fn main(args: &Args) -> Result<()> {
|
||||
let schema = schema_for!(Options);
|
||||
let settings = SchemaSettings::draft07();
|
||||
let generator = settings.into_generator();
|
||||
let schema = generator.into_root_schema_for::<Options>();
|
||||
let schema_string = serde_json::to_string_pretty(&schema).unwrap();
|
||||
let filename = "ruff.schema.json";
|
||||
let schema_path = PathBuf::from(ROOT_DIR).join(filename);
|
||||
|
||||
@@ -32,20 +32,24 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
|
||||
table_out.push('\n');
|
||||
for rule in rules {
|
||||
let status_token = match rule.group() {
|
||||
RuleGroup::Removed => {
|
||||
RuleGroup::Removed { since } => {
|
||||
format!(
|
||||
"<span {SYMBOL_STYLE} title='Rule has been removed'>{REMOVED_SYMBOL}</span>"
|
||||
"<span {SYMBOL_STYLE} title='Rule was removed in {since}'>{REMOVED_SYMBOL}</span>"
|
||||
)
|
||||
}
|
||||
RuleGroup::Deprecated => {
|
||||
RuleGroup::Deprecated { since } => {
|
||||
format!(
|
||||
"<span {SYMBOL_STYLE} title='Rule has been deprecated'>{WARNING_SYMBOL}</span>"
|
||||
"<span {SYMBOL_STYLE} title='Rule has been deprecated since {since}'>{WARNING_SYMBOL}</span>"
|
||||
)
|
||||
}
|
||||
RuleGroup::Preview => {
|
||||
format!("<span {SYMBOL_STYLE} title='Rule is in preview'>{PREVIEW_SYMBOL}</span>")
|
||||
RuleGroup::Preview { since } => {
|
||||
format!(
|
||||
"<span {SYMBOL_STYLE} title='Rule has been in preview since {since}'>{PREVIEW_SYMBOL}</span>"
|
||||
)
|
||||
}
|
||||
RuleGroup::Stable { since } => {
|
||||
format!("<span {SYMBOL_STYLE} title='Rule has been stable since {since}'></span>")
|
||||
}
|
||||
RuleGroup::Stable => format!("<span {SYMBOL_STYLE}></span>"),
|
||||
};
|
||||
|
||||
let fix_token = match rule.fixable() {
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use pretty_assertions::StrComparison;
|
||||
use schemars::schema_for;
|
||||
use schemars::generate::SchemaSettings;
|
||||
|
||||
use crate::ROOT_DIR;
|
||||
use crate::generate_all::{Mode, REGENERATE_ALL_COMMAND};
|
||||
@@ -17,7 +17,9 @@ pub(crate) struct Args {
|
||||
}
|
||||
|
||||
pub(crate) fn main(args: &Args) -> Result<()> {
|
||||
let schema = schema_for!(Options);
|
||||
let settings = SchemaSettings::draft07();
|
||||
let generator = settings.into_generator();
|
||||
let schema = generator.into_root_schema_for::<Options>();
|
||||
let schema_string = serde_json::to_string_pretty(&schema).unwrap();
|
||||
let filename = "ty.schema.json";
|
||||
let schema_path = PathBuf::from(ROOT_DIR).join(filename);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ruff_linter"
|
||||
version = "0.14.0"
|
||||
version = "0.14.2"
|
||||
publish = false
|
||||
authors = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
|
||||
@@ -91,10 +91,20 @@ get_unique_task_id()
|
||||
task_decorator_factory()
|
||||
|
||||
|
||||
from airflow.models import Param
|
||||
from airflow.models import DagParam, Param, ParamsDict
|
||||
|
||||
# airflow.models
|
||||
Param()
|
||||
DagParam()
|
||||
ParamsDict()
|
||||
|
||||
|
||||
from airflow.models.param import DagParam, Param, ParamsDict
|
||||
|
||||
# airflow.models.param
|
||||
Param()
|
||||
DagParam()
|
||||
ParamsDict()
|
||||
|
||||
|
||||
from airflow.sensors.base import (
|
||||
|
||||
87
crates/ruff_linter/resources/test/fixtures/fastapi/FAST002_2.py
vendored
Normal file
87
crates/ruff_linter/resources/test/fixtures/fastapi/FAST002_2.py
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"""Test FAST002 ellipsis handling."""
|
||||
|
||||
from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
# Cases that should be fixed - ellipsis should be removed
|
||||
|
||||
|
||||
@app.get("/test1")
|
||||
async def test_ellipsis_query(
|
||||
# This should become: param: Annotated[str, Query(description="Test param")]
|
||||
param: str = Query(..., description="Test param"),
|
||||
) -> str:
|
||||
return param
|
||||
|
||||
|
||||
@app.get("/test2")
|
||||
async def test_ellipsis_header(
|
||||
# This should become: auth: Annotated[str, Header(description="Auth header")]
|
||||
auth: str = Header(..., description="Auth header"),
|
||||
) -> str:
|
||||
return auth
|
||||
|
||||
|
||||
@app.post("/test3")
|
||||
async def test_ellipsis_body(
|
||||
# This should become: data: Annotated[dict, Body(description="Request body")]
|
||||
data: dict = Body(..., description="Request body"),
|
||||
) -> dict:
|
||||
return data
|
||||
|
||||
|
||||
@app.get("/test4")
|
||||
async def test_ellipsis_cookie(
|
||||
# This should become: session: Annotated[str, Cookie(description="Session ID")]
|
||||
session: str = Cookie(..., description="Session ID"),
|
||||
) -> str:
|
||||
return session
|
||||
|
||||
|
||||
@app.get("/test5")
|
||||
async def test_simple_ellipsis(
|
||||
# This should become: id: Annotated[str, Query()]
|
||||
id: str = Query(...),
|
||||
) -> str:
|
||||
return id
|
||||
|
||||
|
||||
@app.get("/test6")
|
||||
async def test_multiple_kwargs_with_ellipsis(
|
||||
# This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
|
||||
param: str = Query(..., description="Test", min_length=1, max_length=10),
|
||||
) -> str:
|
||||
return param
|
||||
|
||||
|
||||
# Cases with actual default values - these should preserve the default
|
||||
|
||||
|
||||
@app.get("/test7")
|
||||
async def test_with_default_value(
|
||||
# This should become: param: Annotated[str, Query(description="Test")] = "default"
|
||||
param: str = Query("default", description="Test"),
|
||||
) -> str:
|
||||
return param
|
||||
|
||||
|
||||
@app.get("/test8")
|
||||
async def test_with_default_none(
|
||||
# This should become: param: Annotated[str | None, Query(description="Test")] = None
|
||||
param: str | None = Query(None, description="Test"),
|
||||
) -> str:
|
||||
return param or "empty"
|
||||
|
||||
|
||||
@app.get("/test9")
|
||||
async def test_mixed_parameters(
|
||||
# First param should be fixed with default preserved
|
||||
optional_param: str = Query("default", description="Optional"),
|
||||
# Second param should not be fixed because of the preceding default
|
||||
required_param: str = Query(..., description="Required"),
|
||||
# Third param should be fixed with default preserved
|
||||
another_optional_param: int = Query(42, description="Another optional"),
|
||||
) -> str:
|
||||
return f"{required_param}-{optional_param}-{another_optional_param}"
|
||||
@@ -256,3 +256,12 @@ async def f4():
|
||||
@app.get("/f5/{param: int}")
|
||||
async def f5():
|
||||
return locals()
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/20941
|
||||
@app.get("/imports/{import}")
|
||||
async def get_import():
|
||||
...
|
||||
|
||||
@app.get("/debug/{__debug__}")
|
||||
async def get_debug():
|
||||
...
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
from itertools import count, cycle, repeat
|
||||
|
||||
# Errors
|
||||
zip()
|
||||
zip(range(3))
|
||||
zip("a", "b")
|
||||
zip("a", "b", *zip("c"))
|
||||
zip(zip("a"), strict=False)
|
||||
zip(zip("a", strict=True))
|
||||
zip(zip("a", "b"), strict=False)
|
||||
zip(zip("a", strict=True),"b")
|
||||
|
||||
# OK
|
||||
zip(range(3), strict=True)
|
||||
@@ -27,3 +25,10 @@ zip([1, 2, 3], repeat(1, times=4))
|
||||
import builtins
|
||||
# Still an error even though it uses the qualified name
|
||||
builtins.zip([1, 2, 3])
|
||||
|
||||
# Regression https://github.com/astral-sh/ruff/issues/20997
|
||||
# Ok
|
||||
zip()
|
||||
zip(range(3))
|
||||
# Error
|
||||
zip(*lot_of_iterators)
|
||||
|
||||
@@ -31,3 +31,6 @@ map(lambda x, y: x + y, [1, 2, 3], cycle([1, 2, 3]))
|
||||
map(lambda x, y: x + y, [1, 2, 3], repeat(1))
|
||||
map(lambda x, y: x + y, [1, 2, 3], repeat(1, times=None))
|
||||
map(lambda x, y: x + y, [1, 2, 3], count())
|
||||
|
||||
# Regression https://github.com/astral-sh/ruff/issues/20997
|
||||
map(f, *lots_of_iterators)
|
||||
|
||||
@@ -2,3 +2,52 @@ _(f"{'value'}")
|
||||
|
||||
# Don't trigger for t-strings
|
||||
_(t"{'value'}")
|
||||
|
||||
gettext(f"{'value'}")
|
||||
ngettext(f"{'value'}", f"{'values'}", 2)
|
||||
|
||||
_gettext(f"{'value'}") # no lint
|
||||
gettext_fn(f"{'value'}") # no lint
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028 - import aliases
|
||||
import gettext as gettext_mod
|
||||
from gettext import (
|
||||
gettext as gettext_fn,
|
||||
ngettext as ngettext_fn,
|
||||
)
|
||||
|
||||
name = "Guido"
|
||||
|
||||
gettext_mod.gettext(f"Hello, {name}!")
|
||||
gettext_mod.ngettext(f"Hello, {name}!", f"Hello, {name}s!", 2)
|
||||
gettext_fn(f"Hello, {name}!")
|
||||
ngettext_fn(f"Hello, {name}!", f"Hello, {name}s!", 2)
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028 - deferred translations
|
||||
def _(message): return message
|
||||
|
||||
animals = [_(f"{'mollusk'}"),
|
||||
_(f"{'albatross'}"),
|
||||
_(f"{'rat'}"),
|
||||
_(f"{'penguin'}"),
|
||||
_(f"{'python'}"),]
|
||||
|
||||
del _
|
||||
|
||||
for a in animals:
|
||||
print(_(a))
|
||||
print(_(f"{a}"))
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028
|
||||
# - installed translations/i18n functions dynamically assigned to builtins
|
||||
import builtins
|
||||
|
||||
gettext_mod.install("domain")
|
||||
builtins.__dict__["gettext"] = gettext_fn
|
||||
|
||||
builtins._(f"{'value'}")
|
||||
builtins.gettext(f"{'value'}")
|
||||
builtins.ngettext(f"{'value'}", f"{'values'}", 2)
|
||||
|
||||
@@ -1 +1,49 @@
|
||||
_("{}".format("line"))
|
||||
gettext("{}".format("line"))
|
||||
ngettext("{}".format("line"), "{}".format("lines"), 2)
|
||||
|
||||
_gettext("{}".format("line")) # no lint
|
||||
gettext_fn("{}".format("line")) # no lint
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028
|
||||
import gettext as gettext_mod
|
||||
from gettext import (
|
||||
gettext as gettext_fn,
|
||||
ngettext as ngettext_fn,
|
||||
)
|
||||
|
||||
name = "Guido"
|
||||
|
||||
gettext_mod.gettext("Hello, {}!".format(name))
|
||||
gettext_mod.ngettext("Hello, {}!".format(name), "Hello, {}s!".format(name), 2)
|
||||
gettext_fn("Hello, {}!".format(name))
|
||||
ngettext_fn("Hello, {}!".format(name), "Hello, {}s!".format(name), 2)
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028 - deferred translations
|
||||
def _(message): return message
|
||||
|
||||
animals = [_("{}".format("mollusk")),
|
||||
_("{}".format("albatross")),
|
||||
_("{}".format("rat")),
|
||||
_("{}".format("penguin")),
|
||||
_("{}".format("python")),]
|
||||
|
||||
del _
|
||||
|
||||
for a in animals:
|
||||
print(_(a))
|
||||
print(_("{}".format(a)))
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028
|
||||
# - installed translations/i18n functions dynamically assigned to builtins
|
||||
import builtins
|
||||
|
||||
gettext_mod.install("domain")
|
||||
builtins.__dict__["gettext"] = gettext_fn
|
||||
|
||||
builtins._("{}".format("line"))
|
||||
builtins.gettext("{}".format("line"))
|
||||
builtins.ngettext("{}".format("line"), "{}".format("lines"), 2)
|
||||
|
||||
@@ -1 +1,49 @@
|
||||
_("%s" % "line")
|
||||
gettext("%s" % "line")
|
||||
ngettext("%s" % "line", "%s" % "lines", 2)
|
||||
|
||||
_gettext("%s" % "line") # no lint
|
||||
gettext_fn("%s" % "line") # no lint
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028
|
||||
import gettext as gettext_mod
|
||||
from gettext import (
|
||||
gettext as gettext_fn,
|
||||
ngettext as ngettext_fn,
|
||||
)
|
||||
|
||||
name = "Guido"
|
||||
|
||||
gettext_mod.gettext("Hello, %s!" % name)
|
||||
gettext_mod.ngettext("Hello, %s!" % name, "Hello, %ss!" % name, 2)
|
||||
gettext_fn("Hello, %s!" % name)
|
||||
ngettext_fn("Hello, %s!" % name, "Hello, %ss!" % name, 2)
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028 - deferred translations
|
||||
def _(message): return message
|
||||
|
||||
animals = [_("%s" %"mollusk"),
|
||||
_("%s" %"albatross"),
|
||||
_("%s" %"rat"),
|
||||
_("%s" %"penguin"),
|
||||
_("%s" %"python"),]
|
||||
|
||||
del _
|
||||
|
||||
for a in animals:
|
||||
print(_(a))
|
||||
print(_("%s" % a))
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/19028
|
||||
# - installed translations/i18n functions dynamically assigned to builtins
|
||||
import builtins
|
||||
|
||||
gettext_mod.install("domain")
|
||||
builtins.__dict__["gettext"] = gettext_fn
|
||||
|
||||
builtins._("%s" % "line")
|
||||
builtins.gettext("%s" % "line")
|
||||
builtins.ngettext("%s" % "line", "%s" % "lines", 2)
|
||||
|
||||
@@ -34,3 +34,7 @@ def foo():
|
||||
# https://github.com/astral-sh/ruff/issues/18776
|
||||
flag_stars = {}
|
||||
for country, stars in(zip)(flag_stars.keys(), flag_stars.values()):...
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/18778
|
||||
d = {}
|
||||
for country, stars in zip(d.keys(*x), d.values("hello")):...
|
||||
|
||||
264
crates/ruff_linter/resources/test/fixtures/pydoclint/DOC102_google.py
vendored
Normal file
264
crates/ruff_linter/resources/test/fixtures/pydoclint/DOC102_google.py
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
# DOC102
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Args:
|
||||
a (int): The first number to add.
|
||||
b (int): The second number to add.
|
||||
|
||||
Returns:
|
||||
int: The sum of the two numbers.
|
||||
"""
|
||||
return a + b
|
||||
|
||||
|
||||
# DOC102
|
||||
def multiply_list_elements(lst):
|
||||
"""
|
||||
Multiplies each element in a list by a given multiplier.
|
||||
|
||||
Args:
|
||||
lst (list of int): A list of integers.
|
||||
multiplier (int): The multiplier for each element in the list.
|
||||
|
||||
Returns:
|
||||
list of int: A new list with each element multiplied.
|
||||
"""
|
||||
return [x * multiplier for x in lst]
|
||||
|
||||
|
||||
# DOC102
|
||||
def find_max_value():
|
||||
"""
|
||||
Finds the maximum value in a list of numbers.
|
||||
|
||||
Args:
|
||||
numbers (list of int): A list of integers to search through.
|
||||
|
||||
Returns:
|
||||
int: The maximum value found in the list.
|
||||
"""
|
||||
return max(numbers)
|
||||
|
||||
|
||||
# DOC102
|
||||
def create_user_profile(location="here"):
|
||||
"""
|
||||
Creates a user profile with basic information.
|
||||
|
||||
Args:
|
||||
name (str): The name of the user.
|
||||
age (int): The age of the user.
|
||||
email (str): The user's email address.
|
||||
location (str): The location of the user.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the user's profile.
|
||||
"""
|
||||
return {
|
||||
'name': name,
|
||||
'age': age,
|
||||
'email': email,
|
||||
'location': location
|
||||
}
|
||||
|
||||
|
||||
# DOC102
|
||||
def calculate_total_price(item_prices, discount):
|
||||
"""
|
||||
Calculates the total price after applying tax and a discount.
|
||||
|
||||
Args:
|
||||
item_prices (list of float): A list of prices for each item.
|
||||
tax_rate (float): The tax rate to apply.
|
||||
discount (float): The discount to subtract from the total.
|
||||
|
||||
Returns:
|
||||
float: The final total price after tax and discount.
|
||||
"""
|
||||
total = sum(item_prices)
|
||||
total_with_tax = total + (total * tax_rate)
|
||||
final_total = total_with_tax - discount
|
||||
return final_total
|
||||
|
||||
|
||||
# DOC102
|
||||
def send_email(subject, body, bcc_address=None):
|
||||
"""
|
||||
Sends an email to the specified recipients.
|
||||
|
||||
Args:
|
||||
subject (str): The subject of the email.
|
||||
body (str): The content of the email.
|
||||
to_address (str): The recipient's email address.
|
||||
cc_address (str, optional): The email address for CC. Defaults to None.
|
||||
bcc_address (str, optional): The email address for BCC. Defaults to None.
|
||||
|
||||
Returns:
|
||||
bool: True if the email was sent successfully, False otherwise.
|
||||
"""
|
||||
return True
|
||||
|
||||
|
||||
# DOC102
|
||||
def concatenate_strings(*args):
|
||||
"""
|
||||
Concatenates multiple strings with a specified separator.
|
||||
|
||||
Args:
|
||||
separator (str): The separator to use between strings.
|
||||
*args (str): Variable length argument list of strings to concatenate.
|
||||
|
||||
Returns:
|
||||
str: A single concatenated string.
|
||||
"""
|
||||
return separator.join(args)
|
||||
|
||||
|
||||
# DOC102
|
||||
def process_order(order_id):
|
||||
"""
|
||||
Processes an order with a list of items and optional order details.
|
||||
|
||||
Args:
|
||||
order_id (int): The unique identifier for the order.
|
||||
*items (str): Variable length argument list of items in the order.
|
||||
**details (dict): Additional details such as shipping method and address.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the order summary.
|
||||
"""
|
||||
return {
|
||||
'order_id': order_id,
|
||||
'items': items,
|
||||
'details': details
|
||||
}
|
||||
|
||||
|
||||
class Calculator:
|
||||
"""
|
||||
A simple calculator class that can perform basic arithmetic operations.
|
||||
"""
|
||||
|
||||
# DOC102
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the calculator with an initial value.
|
||||
|
||||
Args:
|
||||
value (int, optional): The initial value of the calculator. Defaults to 0.
|
||||
"""
|
||||
self.value = value
|
||||
|
||||
# DOC102
|
||||
def add(self, number2):
|
||||
"""
|
||||
Adds a number to the current value.
|
||||
|
||||
Args:
|
||||
number (int or float): The number to add to the current value.
|
||||
|
||||
Returns:
|
||||
int or float: The updated value after addition.
|
||||
"""
|
||||
self.value += number + number2
|
||||
return self.value
|
||||
|
||||
# DOC102
|
||||
@classmethod
|
||||
def from_string(cls):
|
||||
"""
|
||||
Creates a Calculator instance from a string representation of a number.
|
||||
|
||||
Args:
|
||||
value_str (str): The string representing the initial value.
|
||||
|
||||
Returns:
|
||||
Calculator: A new instance of Calculator initialized with the value from the string.
|
||||
"""
|
||||
value = float(value_str)
|
||||
return cls(value)
|
||||
|
||||
# DOC102
|
||||
@staticmethod
|
||||
def is_valid_number():
|
||||
"""
|
||||
Checks if a given number is valid (int or float).
|
||||
|
||||
Args:
|
||||
number (any): The value to check.
|
||||
|
||||
Returns:
|
||||
bool: True if the number is valid, False otherwise.
|
||||
"""
|
||||
return isinstance(number, (int, float))
|
||||
|
||||
# OK
|
||||
def foo(param1, param2, *args, **kwargs):
|
||||
"""Foo.
|
||||
|
||||
Args:
|
||||
param1 (int): The first parameter.
|
||||
param2 (:obj:`str`, optional): The second parameter. Defaults to None.
|
||||
Second line of description: should be indented.
|
||||
*args: Variable length argument list.
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
"""
|
||||
return
|
||||
|
||||
# OK
|
||||
def on_server_unloaded(self, server_context: ServerContext) -> None:
|
||||
''' Execute ``on_server_unloaded`` from ``server_lifecycle.py`` (if
|
||||
it is defined) when the server cleanly exits. (Before stopping the
|
||||
server's ``IOLoop``.)
|
||||
|
||||
Args:
|
||||
server_context (ServerContext) :
|
||||
|
||||
.. warning::
|
||||
In practice this code may not run, since servers are often killed
|
||||
by a signal.
|
||||
|
||||
|
||||
'''
|
||||
return self._lifecycle_handler.on_server_unloaded(server_context)
|
||||
|
||||
# OK
|
||||
def function_with_kwargs(param1, param2, **kwargs):
|
||||
"""Function with **kwargs parameter.
|
||||
|
||||
Args:
|
||||
param1 (int): The first parameter.
|
||||
param2 (str): The second parameter.
|
||||
extra_param (str): An extra parameter that may be passed via **kwargs.
|
||||
another_extra (int): Another extra parameter.
|
||||
"""
|
||||
return
|
||||
|
||||
# OK
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Args:
|
||||
b: The second number to add.
|
||||
|
||||
Returns:
|
||||
int: The sum of the two numbers.
|
||||
"""
|
||||
return
|
||||
|
||||
# DOC102
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Args:
|
||||
a: The first number to add.
|
||||
b: The second number to add.
|
||||
|
||||
Returns:
|
||||
int: The sum of the two numbers.
|
||||
"""
|
||||
return a + b
|
||||
372
crates/ruff_linter/resources/test/fixtures/pydoclint/DOC102_numpy.py
vendored
Normal file
372
crates/ruff_linter/resources/test/fixtures/pydoclint/DOC102_numpy.py
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
# DOC102
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
a : int
|
||||
The first number to add.
|
||||
b : int
|
||||
The second number to add.
|
||||
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
The sum of the two numbers.
|
||||
"""
|
||||
return a + b
|
||||
|
||||
|
||||
# DOC102
|
||||
def multiply_list_elements(lst):
|
||||
"""
|
||||
Multiplies each element in a list by a given multiplier.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
lst : list of int
|
||||
A list of integers.
|
||||
multiplier : int
|
||||
The multiplier for each element in the list.
|
||||
|
||||
Returns
|
||||
-------
|
||||
list of int
|
||||
A new list with each element multiplied.
|
||||
"""
|
||||
return [x * multiplier for x in lst]
|
||||
|
||||
|
||||
# DOC102
|
||||
def find_max_value():
|
||||
"""
|
||||
Finds the maximum value in a list of numbers.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
numbers : list of int
|
||||
A list of integers to search through.
|
||||
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
The maximum value found in the list.
|
||||
"""
|
||||
return max(numbers)
|
||||
|
||||
|
||||
# DOC102
|
||||
def create_user_profile(location="here"):
|
||||
"""
|
||||
Creates a user profile with basic information.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The name of the user.
|
||||
age : int
|
||||
The age of the user.
|
||||
email : str
|
||||
The user's email address.
|
||||
location : str, optional
|
||||
The location of the user, by default "here".
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict
|
||||
A dictionary containing the user's profile.
|
||||
"""
|
||||
return {
|
||||
'name': name,
|
||||
'age': age,
|
||||
'email': email,
|
||||
'location': location
|
||||
}
|
||||
|
||||
|
||||
# DOC102
|
||||
def calculate_total_price(item_prices, discount):
|
||||
"""
|
||||
Calculates the total price after applying tax and a discount.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
item_prices : list of float
|
||||
A list of prices for each item.
|
||||
tax_rate : float
|
||||
The tax rate to apply.
|
||||
discount : float
|
||||
The discount to subtract from the total.
|
||||
|
||||
Returns
|
||||
-------
|
||||
float
|
||||
The final total price after tax and discount.
|
||||
"""
|
||||
total = sum(item_prices)
|
||||
total_with_tax = total + (total * tax_rate)
|
||||
final_total = total_with_tax - discount
|
||||
return final_total
|
||||
|
||||
|
||||
# DOC102
|
||||
def send_email(subject, body, bcc_address=None):
|
||||
"""
|
||||
Sends an email to the specified recipients.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
subject : str
|
||||
The subject of the email.
|
||||
body : str
|
||||
The content of the email.
|
||||
to_address : str
|
||||
The recipient's email address.
|
||||
cc_address : str, optional
|
||||
The email address for CC, by default None.
|
||||
bcc_address : str, optional
|
||||
The email address for BCC, by default None.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if the email was sent successfully, False otherwise.
|
||||
"""
|
||||
return True
|
||||
|
||||
|
||||
# DOC102
|
||||
def concatenate_strings(*args):
|
||||
"""
|
||||
Concatenates multiple strings with a specified separator.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
separator : str
|
||||
The separator to use between strings.
|
||||
*args : str
|
||||
Variable length argument list of strings to concatenate.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
A single concatenated string.
|
||||
"""
|
||||
return True
|
||||
|
||||
|
||||
# DOC102
|
||||
def process_order(order_id):
|
||||
"""
|
||||
Processes an order with a list of items and optional order details.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
order_id : int
|
||||
The unique identifier for the order.
|
||||
*items : str
|
||||
Variable length argument list of items in the order.
|
||||
**details : dict
|
||||
Additional details such as shipping method and address.
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict
|
||||
A dictionary containing the order summary.
|
||||
"""
|
||||
return {
|
||||
'order_id': order_id,
|
||||
'items': items,
|
||||
'details': details
|
||||
}
|
||||
|
||||
|
||||
class Calculator:
|
||||
"""
|
||||
A simple calculator class that can perform basic arithmetic operations.
|
||||
"""
|
||||
|
||||
# DOC102
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the calculator with an initial value.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
value : int, optional
|
||||
The initial value of the calculator, by default 0.
|
||||
"""
|
||||
self.value = value
|
||||
|
||||
# DOC102
|
||||
def add(self, number2):
|
||||
"""
|
||||
Adds two numbers to the current value.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
number : int or float
|
||||
The first number to add.
|
||||
number2 : int or float
|
||||
The second number to add.
|
||||
|
||||
Returns
|
||||
-------
|
||||
int or float
|
||||
The updated value after addition.
|
||||
"""
|
||||
self.value += number + number2
|
||||
return self.value
|
||||
|
||||
# DOC102
|
||||
@classmethod
|
||||
def from_string(cls):
|
||||
"""
|
||||
Creates a Calculator instance from a string representation of a number.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
value_str : str
|
||||
The string representing the initial value.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Calculator
|
||||
A new instance of Calculator initialized with the value from the string.
|
||||
"""
|
||||
value = float(value_str)
|
||||
return cls(value)
|
||||
|
||||
# DOC102
|
||||
@staticmethod
|
||||
def is_valid_number():
|
||||
"""
|
||||
Checks if a given number is valid (int or float).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
number : any
|
||||
The value to check.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if the number is valid, False otherwise.
|
||||
"""
|
||||
return isinstance(number, (int, float))
|
||||
|
||||
# OK
|
||||
def function_with_kwargs(param1, param2, **kwargs):
|
||||
"""Function with **kwargs parameter.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
param1 : int
|
||||
The first parameter.
|
||||
param2 : str
|
||||
The second parameter.
|
||||
extra_param : str
|
||||
An extra parameter that may be passed via **kwargs.
|
||||
another_extra : int
|
||||
Another extra parameter.
|
||||
"""
|
||||
return True
|
||||
|
||||
# OK
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
b
|
||||
The second number to add.
|
||||
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
The sum of the two numbers.
|
||||
"""
|
||||
return a + b
|
||||
|
||||
# DOC102
|
||||
def add_numbers(b):
|
||||
"""
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
a
|
||||
The first number to add.
|
||||
b
|
||||
The second number to add.
|
||||
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
The sum of the two numbers.
|
||||
"""
|
||||
return a + b
|
||||
|
||||
class Foo:
|
||||
# OK
|
||||
def send_help(self, *args: Any) -> Any:
|
||||
"""|coro|
|
||||
|
||||
Shows the help command for the specified entity if given.
|
||||
The entity can be a command or a cog.
|
||||
|
||||
If no entity is given, then it'll show help for the
|
||||
entire bot.
|
||||
|
||||
If the entity is a string, then it looks up whether it's a
|
||||
:class:`Cog` or a :class:`Command`.
|
||||
|
||||
.. note::
|
||||
|
||||
Due to the way this function works, instead of returning
|
||||
something similar to :meth:`~.commands.HelpCommand.command_not_found`
|
||||
this returns :class:`None` on bad input or no help command.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
entity: Optional[Union[:class:`Command`, :class:`Cog`, :class:`str`]]
|
||||
The entity to show help for.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Any
|
||||
The result of the help command, if any.
|
||||
"""
|
||||
return
|
||||
|
||||
# OK
|
||||
@classmethod
|
||||
async def convert(cls, ctx: Context, argument: str) -> Self:
|
||||
"""|coro|
|
||||
|
||||
The method that actually converters an argument to the flag mapping.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
cls: Type[:class:`FlagConverter`]
|
||||
The flag converter class.
|
||||
ctx: :class:`Context`
|
||||
The invocation context.
|
||||
argument: :class:`str`
|
||||
The argument to convert from.
|
||||
|
||||
Raises
|
||||
------
|
||||
FlagError
|
||||
A flag related parsing error.
|
||||
CommandError
|
||||
A command related error.
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class:`FlagConverter`
|
||||
The flag converter instance with all flags parsed.
|
||||
"""
|
||||
return
|
||||
@@ -269,3 +269,10 @@ raise ValueError(
|
||||
# Not a valid type annotation but this test shouldn't result in a panic.
|
||||
# Refer: https://github.com/astral-sh/ruff/issues/11736
|
||||
x: "'{} + {}'.format(x, y)"
|
||||
|
||||
# Regression https://github.com/astral-sh/ruff/issues/21000
|
||||
# Fix should parenthesize walrus
|
||||
if __name__ == "__main__":
|
||||
number = 0
|
||||
string = "{}".format(number := number + 1)
|
||||
print(string)
|
||||
|
||||
@@ -26,3 +26,8 @@
|
||||
"{.real}".format({1, 2})
|
||||
"{.real}".format({1: 2, 3: 4})
|
||||
"{}".format((i for i in range(2)))
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/21017
|
||||
"{.real}".format(1_2)
|
||||
"{0.real}".format(1_2)
|
||||
"{a.real}".format(a=1_2)
|
||||
|
||||
@@ -81,6 +81,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
Rule::UndocumentedPublicPackage,
|
||||
]);
|
||||
let enforce_pydoclint = checker.any_rule_enabled(&[
|
||||
Rule::DocstringExtraneousParameter,
|
||||
Rule::DocstringMissingReturns,
|
||||
Rule::DocstringExtraneousReturns,
|
||||
Rule::DocstringMissingYields,
|
||||
|
||||
@@ -1034,6 +1034,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
Rule::FormatInGetTextFuncCall,
|
||||
Rule::PrintfInGetTextFuncCall,
|
||||
]) && flake8_gettext::is_gettext_func_call(
|
||||
checker,
|
||||
func,
|
||||
&checker.settings().flake8_gettext.functions_names,
|
||||
) {
|
||||
|
||||
@@ -723,7 +723,9 @@ impl SemanticSyntaxContext for Checker<'_> {
|
||||
| SemanticSyntaxErrorKind::IrrefutableCasePattern(_)
|
||||
| SemanticSyntaxErrorKind::SingleStarredAssignment
|
||||
| SemanticSyntaxErrorKind::WriteToDebug(_)
|
||||
| SemanticSyntaxErrorKind::DifferentMatchPatternBindings
|
||||
| SemanticSyntaxErrorKind::InvalidExpression(..)
|
||||
| SemanticSyntaxErrorKind::GlobalParameter(_)
|
||||
| SemanticSyntaxErrorKind::DuplicateMatchKey(_)
|
||||
| SemanticSyntaxErrorKind::DuplicateMatchClassAttribute(_)
|
||||
| SemanticSyntaxErrorKind::InvalidStarExpression
|
||||
@@ -845,6 +847,26 @@ impl SemanticSyntaxContext for Checker<'_> {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn is_bound_parameter(&self, name: &str) -> bool {
|
||||
for scope in self.semantic.current_scopes() {
|
||||
match scope.kind {
|
||||
ScopeKind::Class(_) => return false,
|
||||
ScopeKind::Function(ast::StmtFunctionDef { parameters, .. })
|
||||
| ScopeKind::Lambda(ast::ExprLambda {
|
||||
parameters: Some(parameters),
|
||||
..
|
||||
}) => return parameters.includes(name),
|
||||
ScopeKind::Lambda(_)
|
||||
| ScopeKind::Generator { .. }
|
||||
| ScopeKind::Module
|
||||
| ScopeKind::Type
|
||||
| ScopeKind::DunderClassCell => {}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Visitor<'a> for Checker<'a> {
|
||||
|
||||
@@ -130,6 +130,7 @@ pub(crate) fn check_noqa(
|
||||
let edit = delete_comment(directive.range(), locator);
|
||||
let mut diagnostic = context
|
||||
.report_diagnostic(UnusedNOQA { codes: None }, directive.range());
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Unnecessary);
|
||||
diagnostic.set_fix(Fix::safe_edit(edit));
|
||||
}
|
||||
}
|
||||
@@ -226,6 +227,7 @@ pub(crate) fn check_noqa(
|
||||
},
|
||||
directive.range(),
|
||||
);
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Unnecessary);
|
||||
diagnostic.set_fix(Fix::safe_edit(edit));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,6 @@ use crate::checkers::tokens::check_tokens;
|
||||
use crate::directives::Directives;
|
||||
use crate::doc_lines::{doc_lines_from_ast, doc_lines_from_tokens};
|
||||
use crate::fix::{FixResult, fix_file};
|
||||
use crate::message::create_syntax_error_diagnostic;
|
||||
use crate::noqa::add_noqa;
|
||||
use crate::package::PackageRoot;
|
||||
use crate::registry::Rule;
|
||||
@@ -496,15 +495,15 @@ fn diagnostics_to_messages(
|
||||
parse_errors
|
||||
.iter()
|
||||
.map(|parse_error| {
|
||||
create_syntax_error_diagnostic(source_file.clone(), &parse_error.error, parse_error)
|
||||
Diagnostic::invalid_syntax(source_file.clone(), &parse_error.error, parse_error)
|
||||
})
|
||||
.chain(unsupported_syntax_errors.iter().map(|syntax_error| {
|
||||
create_syntax_error_diagnostic(source_file.clone(), syntax_error, syntax_error)
|
||||
Diagnostic::invalid_syntax(source_file.clone(), syntax_error, syntax_error)
|
||||
}))
|
||||
.chain(
|
||||
semantic_syntax_errors
|
||||
.iter()
|
||||
.map(|error| create_syntax_error_diagnostic(source_file.clone(), error, error)),
|
||||
.map(|error| Diagnostic::invalid_syntax(source_file.clone(), error, error)),
|
||||
)
|
||||
.chain(diagnostics.into_iter().map(|mut diagnostic| {
|
||||
if let Some(range) = diagnostic.range() {
|
||||
@@ -1041,6 +1040,42 @@ mod tests {
|
||||
PythonVersion::PY310,
|
||||
"DuplicateMatchKey"
|
||||
)]
|
||||
#[test_case(
|
||||
"global_parameter",
|
||||
"
|
||||
def f(a):
|
||||
global a
|
||||
|
||||
def g(a):
|
||||
if True:
|
||||
global a
|
||||
|
||||
def h(a):
|
||||
def inner():
|
||||
global a
|
||||
|
||||
def i(a):
|
||||
try:
|
||||
global a
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def f(a):
|
||||
a = 1
|
||||
global a
|
||||
|
||||
def f(a):
|
||||
a = 1
|
||||
a = 2
|
||||
global a
|
||||
|
||||
def f(a):
|
||||
class Inner:
|
||||
global a # ok
|
||||
",
|
||||
PythonVersion::PY310,
|
||||
"GlobalParameter"
|
||||
)]
|
||||
#[test_case(
|
||||
"duplicate_match_class_attribute",
|
||||
"
|
||||
|
||||
@@ -16,7 +16,7 @@ use ruff_db::files::File;
|
||||
pub use grouped::GroupedEmitter;
|
||||
use ruff_notebook::NotebookIndex;
|
||||
use ruff_source_file::{SourceFile, SourceFileBuilder};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
pub use sarif::SarifEmitter;
|
||||
|
||||
use crate::Fix;
|
||||
@@ -26,24 +26,6 @@ use crate::settings::types::{OutputFormat, RuffOutputFormat};
|
||||
mod grouped;
|
||||
mod sarif;
|
||||
|
||||
/// Creates a `Diagnostic` from a syntax error, with the format expected by Ruff.
|
||||
///
|
||||
/// This is almost identical to `ruff_db::diagnostic::create_syntax_error_diagnostic`, except the
|
||||
/// `message` is stored as the primary diagnostic message instead of on the primary annotation.
|
||||
///
|
||||
/// TODO(brent) These should be unified at some point, but we keep them separate for now to avoid a
|
||||
/// ton of snapshot changes while combining ruff's diagnostic type with `Diagnostic`.
|
||||
pub fn create_syntax_error_diagnostic(
|
||||
span: impl Into<Span>,
|
||||
message: impl std::fmt::Display,
|
||||
range: impl Ranged,
|
||||
) -> Diagnostic {
|
||||
let mut diag = Diagnostic::new(DiagnosticId::InvalidSyntax, Severity::Error, message);
|
||||
let span = span.into().with_range(range.range());
|
||||
diag.annotate(Annotation::primary(span));
|
||||
diag
|
||||
}
|
||||
|
||||
/// Create a `Diagnostic` from a panic.
|
||||
pub fn create_panic_diagnostic(error: &PanicError, path: Option<&Path>) -> Diagnostic {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
@@ -260,8 +242,6 @@ mod tests {
|
||||
use crate::message::{Emitter, EmitterContext, create_lint_diagnostic};
|
||||
use crate::{Edit, Fix};
|
||||
|
||||
use super::create_syntax_error_diagnostic;
|
||||
|
||||
pub(super) fn create_syntax_error_diagnostics() -> Vec<Diagnostic> {
|
||||
let source = r"from os import
|
||||
|
||||
@@ -274,7 +254,7 @@ if call(foo
|
||||
.errors()
|
||||
.iter()
|
||||
.map(|parse_error| {
|
||||
create_syntax_error_diagnostic(source_file.clone(), &parse_error.error, parse_error)
|
||||
Diagnostic::invalid_syntax(source_file.clone(), &parse_error.error, parse_error)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -274,3 +274,8 @@ pub(crate) const fn is_fix_write_whole_file_enabled(settings: &LinterSettings) -
|
||||
pub(crate) const fn is_typing_extensions_str_alias_enabled(settings: &LinterSettings) -> bool {
|
||||
settings.preview.is_enabled()
|
||||
}
|
||||
|
||||
// https://github.com/astral-sh/ruff/pull/19045
|
||||
pub(crate) const fn is_extended_i18n_function_matching_enabled(settings: &LinterSettings) -> bool {
|
||||
settings.preview.is_enabled()
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ mod tests {
|
||||
for rule in Rule::iter() {
|
||||
let (code, group) = (rule.noqa_code(), rule.group());
|
||||
|
||||
if matches!(group, RuleGroup::Removed) {
|
||||
if matches!(group, RuleGroup::Removed { .. }) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -209,15 +209,15 @@ impl RuleSelector {
|
||||
self.all_rules().filter(move |rule| {
|
||||
match rule.group() {
|
||||
// Always include stable rules
|
||||
RuleGroup::Stable => true,
|
||||
RuleGroup::Stable { .. } => true,
|
||||
// Enabling preview includes all preview rules unless explicit selection is turned on
|
||||
RuleGroup::Preview => {
|
||||
RuleGroup::Preview { .. } => {
|
||||
preview_enabled && (self.is_exact() || !preview_require_explicit)
|
||||
}
|
||||
// Deprecated rules are excluded by default unless explicitly selected
|
||||
RuleGroup::Deprecated => !preview_enabled && self.is_exact(),
|
||||
RuleGroup::Deprecated { .. } => !preview_enabled && self.is_exact(),
|
||||
// Removed rules are included if explicitly selected but will error downstream
|
||||
RuleGroup::Removed => self.is_exact(),
|
||||
RuleGroup::Removed { .. } => self.is_exact(),
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -257,9 +257,8 @@ pub struct PreviewOptions {
|
||||
#[cfg(feature = "schemars")]
|
||||
mod schema {
|
||||
use itertools::Itertools;
|
||||
use schemars::_serde_json::Value;
|
||||
use schemars::JsonSchema;
|
||||
use schemars::schema::{InstanceType, Schema, SchemaObject};
|
||||
use schemars::{JsonSchema, Schema, SchemaGenerator};
|
||||
use serde_json::Value;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::RuleSelector;
|
||||
@@ -267,64 +266,65 @@ mod schema {
|
||||
use crate::rule_selector::{Linter, RuleCodePrefix};
|
||||
|
||||
impl JsonSchema for RuleSelector {
|
||||
fn schema_name() -> String {
|
||||
"RuleSelector".to_string()
|
||||
fn schema_name() -> std::borrow::Cow<'static, str> {
|
||||
std::borrow::Cow::Borrowed("RuleSelector")
|
||||
}
|
||||
|
||||
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> Schema {
|
||||
Schema::Object(SchemaObject {
|
||||
instance_type: Some(InstanceType::String.into()),
|
||||
enum_values: Some(
|
||||
[
|
||||
// Include the non-standard "ALL" selectors.
|
||||
"ALL".to_string(),
|
||||
// Include the legacy "C" and "T" selectors.
|
||||
"C".to_string(),
|
||||
"T".to_string(),
|
||||
// Include some common redirect targets for those legacy selectors.
|
||||
"C9".to_string(),
|
||||
"T1".to_string(),
|
||||
"T2".to_string(),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(
|
||||
RuleCodePrefix::iter()
|
||||
.map(|p| {
|
||||
let prefix = p.linter().common_prefix();
|
||||
let code = p.short_code();
|
||||
format!("{prefix}{code}")
|
||||
})
|
||||
.chain(Linter::iter().filter_map(|l| {
|
||||
let prefix = l.common_prefix();
|
||||
(!prefix.is_empty()).then(|| prefix.to_string())
|
||||
})),
|
||||
)
|
||||
.filter(|p| {
|
||||
// Exclude any prefixes where all of the rules are removed
|
||||
if let Ok(Self::Rule { prefix, .. } | Self::Prefix { prefix, .. }) =
|
||||
RuleSelector::parse_no_redirect(p)
|
||||
{
|
||||
!prefix.rules().all(|rule| rule.is_removed())
|
||||
} else {
|
||||
true
|
||||
}
|
||||
fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
|
||||
let enum_values: Vec<String> = [
|
||||
// Include the non-standard "ALL" selectors.
|
||||
"ALL".to_string(),
|
||||
// Include the legacy "C" and "T" selectors.
|
||||
"C".to_string(),
|
||||
"T".to_string(),
|
||||
// Include some common redirect targets for those legacy selectors.
|
||||
"C9".to_string(),
|
||||
"T1".to_string(),
|
||||
"T2".to_string(),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(
|
||||
RuleCodePrefix::iter()
|
||||
.map(|p| {
|
||||
let prefix = p.linter().common_prefix();
|
||||
let code = p.short_code();
|
||||
format!("{prefix}{code}")
|
||||
})
|
||||
.filter(|_rule| {
|
||||
// Filter out all test-only rules
|
||||
#[cfg(any(feature = "test-rules", test))]
|
||||
#[expect(clippy::used_underscore_binding)]
|
||||
if _rule.starts_with("RUF9") || _rule == "PLW0101" {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
})
|
||||
.sorted()
|
||||
.map(Value::String)
|
||||
.collect(),
|
||||
),
|
||||
..SchemaObject::default()
|
||||
.chain(Linter::iter().filter_map(|l| {
|
||||
let prefix = l.common_prefix();
|
||||
(!prefix.is_empty()).then(|| prefix.to_string())
|
||||
})),
|
||||
)
|
||||
.filter(|p| {
|
||||
// Exclude any prefixes where all of the rules are removed
|
||||
if let Ok(Self::Rule { prefix, .. } | Self::Prefix { prefix, .. }) =
|
||||
RuleSelector::parse_no_redirect(p)
|
||||
{
|
||||
!prefix.rules().all(|rule| rule.is_removed())
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.filter(|_rule| {
|
||||
// Filter out all test-only rules
|
||||
#[cfg(any(feature = "test-rules", test))]
|
||||
#[expect(clippy::used_underscore_binding)]
|
||||
if _rule.starts_with("RUF9") || _rule == "PLW0101" {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
})
|
||||
.sorted()
|
||||
.collect();
|
||||
|
||||
let mut schema = schemars::json_schema!({ "type": "string" });
|
||||
schema.ensure_object().insert(
|
||||
"enum".to_string(),
|
||||
Value::Array(enum_values.into_iter().map(Value::String).collect()),
|
||||
);
|
||||
|
||||
schema
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ use crate::checkers::ast::Checker;
|
||||
/// dag = DAG(dag_id="my_dag", schedule=timedelta(days=1))
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.13.0")]
|
||||
pub(crate) struct AirflowDagNoScheduleArgument;
|
||||
|
||||
impl Violation for AirflowDagNoScheduleArgument {
|
||||
|
||||
@@ -35,6 +35,7 @@ use crate::{FixAvailability, Violation};
|
||||
/// fab_auth_manager_app = FabAuthManager().get_fastapi_app()
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.13.0")]
|
||||
pub(crate) struct Airflow3MovedToProvider<'a> {
|
||||
deprecated: QualifiedName<'a>,
|
||||
replacement: ProviderReplacement,
|
||||
|
||||
@@ -41,6 +41,7 @@ use ruff_text_size::TextRange;
|
||||
/// yesterday = today - timedelta(days=1)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.13.0")]
|
||||
pub(crate) struct Airflow3Removal {
|
||||
deprecated: String,
|
||||
replacement: Replacement,
|
||||
|
||||
@@ -51,6 +51,7 @@ use ruff_text_size::TextRange;
|
||||
/// )
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.13.0")]
|
||||
pub(crate) struct Airflow3SuggestedToMoveToProvider<'a> {
|
||||
deprecated: QualifiedName<'a>,
|
||||
replacement: ProviderReplacement,
|
||||
|
||||
@@ -37,6 +37,7 @@ use ruff_text_size::TextRange;
|
||||
/// Asset(uri="test://test/")
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.13.0")]
|
||||
pub(crate) struct Airflow3SuggestedUpdate {
|
||||
deprecated: String,
|
||||
replacement: Replacement,
|
||||
@@ -261,9 +262,14 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
|
||||
name: (*rest).to_string(),
|
||||
}
|
||||
}
|
||||
["airflow", "models", "Param"] => Replacement::Rename {
|
||||
[
|
||||
"airflow",
|
||||
"models",
|
||||
..,
|
||||
rest @ ("Param" | "ParamsDict" | "DagParam"),
|
||||
] => Replacement::SourceModuleMoved {
|
||||
module: "airflow.sdk.definitions.param",
|
||||
name: "Param",
|
||||
name: (*rest).to_string(),
|
||||
},
|
||||
|
||||
// airflow.models.baseoperator
|
||||
|
||||
@@ -32,6 +32,7 @@ use crate::checkers::ast::Checker;
|
||||
/// my_task = PythonOperator(task_id="my_task")
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.271")]
|
||||
pub(crate) struct AirflowVariableNameTaskIdMismatch {
|
||||
task_id: String,
|
||||
}
|
||||
|
||||
@@ -737,79 +737,185 @@ AIR311 [*] `airflow.models.Param` is removed in Airflow 3.0; It still works in A
|
||||
96 | # airflow.models
|
||||
97 | Param()
|
||||
| ^^^^^
|
||||
98 | DagParam()
|
||||
99 | ParamsDict()
|
||||
|
|
||||
help: Use `Param` from `airflow.sdk.definitions.param` instead.
|
||||
91 | task_decorator_factory()
|
||||
92 |
|
||||
93 |
|
||||
- from airflow.models import Param
|
||||
94 + from airflow.sdk.definitions.param import Param
|
||||
95 |
|
||||
- from airflow.models import DagParam, Param, ParamsDict
|
||||
94 + from airflow.models import DagParam, ParamsDict
|
||||
95 + from airflow.sdk.definitions.param import Param
|
||||
96 |
|
||||
97 | # airflow.models
|
||||
98 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.models.DagParam` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:98:1
|
||||
|
|
||||
96 | # airflow.models
|
||||
97 | Param()
|
||||
98 | DagParam()
|
||||
| ^^^^^^^^
|
||||
99 | ParamsDict()
|
||||
|
|
||||
help: Use `DagParam` from `airflow.sdk.definitions.param` instead.
|
||||
91 | task_decorator_factory()
|
||||
92 |
|
||||
93 |
|
||||
- from airflow.models import DagParam, Param, ParamsDict
|
||||
94 + from airflow.models import Param, ParamsDict
|
||||
95 + from airflow.sdk.definitions.param import DagParam
|
||||
96 |
|
||||
97 | # airflow.models
|
||||
98 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.models.ParamsDict` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:99:1
|
||||
|
|
||||
97 | Param()
|
||||
98 | DagParam()
|
||||
99 | ParamsDict()
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Use `ParamsDict` from `airflow.sdk.definitions.param` instead.
|
||||
91 | task_decorator_factory()
|
||||
92 |
|
||||
93 |
|
||||
- from airflow.models import DagParam, Param, ParamsDict
|
||||
94 + from airflow.models import DagParam, Param
|
||||
95 + from airflow.sdk.definitions.param import ParamsDict
|
||||
96 |
|
||||
97 | # airflow.models
|
||||
98 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.models.param.Param` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:105:1
|
||||
|
|
||||
104 | # airflow.models.param
|
||||
105 | Param()
|
||||
| ^^^^^
|
||||
106 | DagParam()
|
||||
107 | ParamsDict()
|
||||
|
|
||||
help: Use `Param` from `airflow.sdk.definitions.param` instead.
|
||||
99 | ParamsDict()
|
||||
100 |
|
||||
101 |
|
||||
- from airflow.models.param import DagParam, Param, ParamsDict
|
||||
102 + from airflow.models.param import DagParam, ParamsDict
|
||||
103 + from airflow.sdk.definitions.param import Param
|
||||
104 |
|
||||
105 | # airflow.models.param
|
||||
106 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.models.param.DagParam` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:106:1
|
||||
|
|
||||
104 | # airflow.models.param
|
||||
105 | Param()
|
||||
106 | DagParam()
|
||||
| ^^^^^^^^
|
||||
107 | ParamsDict()
|
||||
|
|
||||
help: Use `DagParam` from `airflow.sdk.definitions.param` instead.
|
||||
99 | ParamsDict()
|
||||
100 |
|
||||
101 |
|
||||
- from airflow.models.param import DagParam, Param, ParamsDict
|
||||
102 + from airflow.models.param import Param, ParamsDict
|
||||
103 + from airflow.sdk.definitions.param import DagParam
|
||||
104 |
|
||||
105 | # airflow.models.param
|
||||
106 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.models.param.ParamsDict` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:107:1
|
||||
|
|
||||
105 | Param()
|
||||
106 | DagParam()
|
||||
107 | ParamsDict()
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Use `ParamsDict` from `airflow.sdk.definitions.param` instead.
|
||||
99 | ParamsDict()
|
||||
100 |
|
||||
101 |
|
||||
- from airflow.models.param import DagParam, Param, ParamsDict
|
||||
102 + from airflow.models.param import DagParam, Param
|
||||
103 + from airflow.sdk.definitions.param import ParamsDict
|
||||
104 |
|
||||
105 | # airflow.models.param
|
||||
106 | Param()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.sensors.base.BaseSensorOperator` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:107:1
|
||||
--> AIR311_names.py:117:1
|
||||
|
|
||||
106 | # airflow.sensors.base
|
||||
107 | BaseSensorOperator()
|
||||
116 | # airflow.sensors.base
|
||||
117 | BaseSensorOperator()
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
108 | PokeReturnValue()
|
||||
109 | poke_mode_only()
|
||||
118 | PokeReturnValue()
|
||||
119 | poke_mode_only()
|
||||
|
|
||||
help: Use `BaseSensorOperator` from `airflow.sdk` instead.
|
||||
98 |
|
||||
99 |
|
||||
100 | from airflow.sensors.base import (
|
||||
108 |
|
||||
109 |
|
||||
110 | from airflow.sensors.base import (
|
||||
- BaseSensorOperator,
|
||||
101 | PokeReturnValue,
|
||||
102 | poke_mode_only,
|
||||
103 | )
|
||||
104 + from airflow.sdk import BaseSensorOperator
|
||||
105 |
|
||||
106 | # airflow.sensors.base
|
||||
107 | BaseSensorOperator()
|
||||
111 | PokeReturnValue,
|
||||
112 | poke_mode_only,
|
||||
113 | )
|
||||
114 + from airflow.sdk import BaseSensorOperator
|
||||
115 |
|
||||
116 | # airflow.sensors.base
|
||||
117 | BaseSensorOperator()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.sensors.base.PokeReturnValue` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:108:1
|
||||
--> AIR311_names.py:118:1
|
||||
|
|
||||
106 | # airflow.sensors.base
|
||||
107 | BaseSensorOperator()
|
||||
108 | PokeReturnValue()
|
||||
116 | # airflow.sensors.base
|
||||
117 | BaseSensorOperator()
|
||||
118 | PokeReturnValue()
|
||||
| ^^^^^^^^^^^^^^^
|
||||
109 | poke_mode_only()
|
||||
119 | poke_mode_only()
|
||||
|
|
||||
help: Use `PokeReturnValue` from `airflow.sdk` instead.
|
||||
99 |
|
||||
100 | from airflow.sensors.base import (
|
||||
101 | BaseSensorOperator,
|
||||
109 |
|
||||
110 | from airflow.sensors.base import (
|
||||
111 | BaseSensorOperator,
|
||||
- PokeReturnValue,
|
||||
102 | poke_mode_only,
|
||||
103 | )
|
||||
104 + from airflow.sdk import PokeReturnValue
|
||||
105 |
|
||||
106 | # airflow.sensors.base
|
||||
107 | BaseSensorOperator()
|
||||
112 | poke_mode_only,
|
||||
113 | )
|
||||
114 + from airflow.sdk import PokeReturnValue
|
||||
115 |
|
||||
116 | # airflow.sensors.base
|
||||
117 | BaseSensorOperator()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
AIR311 [*] `airflow.sensors.base.poke_mode_only` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
|
||||
--> AIR311_names.py:109:1
|
||||
--> AIR311_names.py:119:1
|
||||
|
|
||||
107 | BaseSensorOperator()
|
||||
108 | PokeReturnValue()
|
||||
109 | poke_mode_only()
|
||||
117 | BaseSensorOperator()
|
||||
118 | PokeReturnValue()
|
||||
119 | poke_mode_only()
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: Use `poke_mode_only` from `airflow.sdk` instead.
|
||||
100 | from airflow.sensors.base import (
|
||||
101 | BaseSensorOperator,
|
||||
102 | PokeReturnValue,
|
||||
110 | from airflow.sensors.base import (
|
||||
111 | BaseSensorOperator,
|
||||
112 | PokeReturnValue,
|
||||
- poke_mode_only,
|
||||
103 | )
|
||||
104 + from airflow.sdk import poke_mode_only
|
||||
105 |
|
||||
106 | # airflow.sensors.base
|
||||
107 | BaseSensorOperator()
|
||||
113 | )
|
||||
114 + from airflow.sdk import poke_mode_only
|
||||
115 |
|
||||
116 | # airflow.sensors.base
|
||||
117 | BaseSensorOperator()
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
@@ -30,6 +30,7 @@ use crate::rules::eradicate::detection::comment_contains_code;
|
||||
///
|
||||
/// [#4845]: https://github.com/astral-sh/ruff/issues/4845
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.145")]
|
||||
pub(crate) struct CommentedOutCode;
|
||||
|
||||
impl Violation for CommentedOutCode {
|
||||
|
||||
@@ -18,6 +18,7 @@ mod tests {
|
||||
#[test_case(Rule::FastApiRedundantResponseModel, Path::new("FAST001.py"))]
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_0.py"))]
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_1.py"))]
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_2.py"))]
|
||||
#[test_case(Rule::FastApiUnusedPathParameter, Path::new("FAST003.py"))]
|
||||
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.name(), path.to_string_lossy());
|
||||
@@ -56,6 +57,7 @@ mod tests {
|
||||
// since `typing.Annotated` was added in Python 3.9
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_0.py"))]
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_1.py"))]
|
||||
#[test_case(Rule::FastApiNonAnnotatedDependency, Path::new("FAST002_2.py"))]
|
||||
fn rules_py38(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}_py38", rule_code.name(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
||||
@@ -79,6 +79,7 @@ use ruff_python_ast::PythonVersion;
|
||||
/// [typing-annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated
|
||||
/// [typing-extensions]: https://typing-extensions.readthedocs.io/en/stable/
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.8.0")]
|
||||
pub(crate) struct FastApiNonAnnotatedDependency {
|
||||
py_version: PythonVersion,
|
||||
}
|
||||
@@ -275,19 +276,42 @@ fn create_diagnostic(
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
|
||||
seen_default = true;
|
||||
format!(
|
||||
"{parameter_name}: {binding}[{annotation}, {default_}({kwarg_list})] \
|
||||
= {default_value}",
|
||||
// Check if the default argument is ellipsis (...), which in FastAPI means "required"
|
||||
let is_default_argument_ellipsis = matches!(
|
||||
dependency_call.default_argument.value(),
|
||||
ast::Expr::EllipsisLiteral(_)
|
||||
);
|
||||
|
||||
if is_default_argument_ellipsis && seen_default {
|
||||
// For ellipsis after a parameter with default, can't remove the default
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
if !is_default_argument_ellipsis {
|
||||
// For actual default values, mark that we've seen a default
|
||||
seen_default = true;
|
||||
}
|
||||
|
||||
let base_format = format!(
|
||||
"{parameter_name}: {binding}[{annotation}, {default_}({kwarg_list})]",
|
||||
parameter_name = parameter.name,
|
||||
annotation = checker.locator().slice(parameter.annotation.range()),
|
||||
default_ = checker
|
||||
.locator()
|
||||
.slice(map_callable(parameter.default).range()),
|
||||
default_value = checker
|
||||
);
|
||||
|
||||
if is_default_argument_ellipsis {
|
||||
// For ellipsis, don't add a default value since the parameter
|
||||
// should remain required after conversion to Annotated
|
||||
base_format
|
||||
} else {
|
||||
// For actual default values, preserve them
|
||||
let default_value = checker
|
||||
.locator()
|
||||
.slice(dependency_call.default_argument.value().range()),
|
||||
)
|
||||
.slice(dependency_call.default_argument.value().range());
|
||||
format!("{base_format} = {default_value}")
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if seen_default {
|
||||
|
||||
@@ -59,6 +59,7 @@ use crate::{AlwaysFixableViolation, Fix};
|
||||
/// return item
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.8.0")]
|
||||
pub(crate) struct FastApiRedundantResponseModel;
|
||||
|
||||
impl AlwaysFixableViolation for FastApiRedundantResponseModel {
|
||||
|
||||
@@ -7,6 +7,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats};
|
||||
use ruff_python_ast as ast;
|
||||
use ruff_python_ast::{Arguments, Expr, ExprCall, ExprSubscript, Parameter, ParameterWithDefault};
|
||||
use ruff_python_semantic::{BindingKind, Modules, ScopeKind, SemanticModel};
|
||||
use ruff_python_stdlib::identifiers::is_identifier;
|
||||
use ruff_text_size::{Ranged, TextSize};
|
||||
|
||||
use crate::Fix;
|
||||
@@ -63,6 +64,7 @@ use crate::{FixAvailability, Violation};
|
||||
/// This rule's fix is marked as unsafe, as modifying a function signature can
|
||||
/// change the behavior of the code.
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.10.0")]
|
||||
pub(crate) struct FastApiUnusedPathParameter {
|
||||
arg_name: String,
|
||||
function_name: String,
|
||||
@@ -191,7 +193,7 @@ pub(crate) fn fastapi_unused_path_parameter(
|
||||
.add_start(TextSize::from(range.start as u32 + 1))
|
||||
.sub_end(TextSize::from((path.len() - range.end + 1) as u32)),
|
||||
);
|
||||
if !is_positional {
|
||||
if !is_positional && is_identifier(path_param) && path_param != "__debug__" {
|
||||
diagnostic.set_fix(Fix::unsafe_edit(add_parameter(
|
||||
path_param,
|
||||
&function_def.parameters,
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/fastapi/mod.rs
|
||||
---
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:14:5
|
||||
|
|
||||
12 | async def test_ellipsis_query(
|
||||
13 | # This should become: param: Annotated[str, Query(description="Test param")]
|
||||
14 | param: str = Query(..., description="Test param"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
15 | ) -> str:
|
||||
16 | return param
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
12 | @app.get("/test1")
|
||||
13 | async def test_ellipsis_query(
|
||||
14 | # This should become: param: Annotated[str, Query(description="Test param")]
|
||||
- param: str = Query(..., description="Test param"),
|
||||
15 + param: Annotated[str, Query(description="Test param")],
|
||||
16 | ) -> str:
|
||||
17 | return param
|
||||
18 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:22:5
|
||||
|
|
||||
20 | async def test_ellipsis_header(
|
||||
21 | # This should become: auth: Annotated[str, Header(description="Auth header")]
|
||||
22 | auth: str = Header(..., description="Auth header"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
23 | ) -> str:
|
||||
24 | return auth
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
20 | @app.get("/test2")
|
||||
21 | async def test_ellipsis_header(
|
||||
22 | # This should become: auth: Annotated[str, Header(description="Auth header")]
|
||||
- auth: str = Header(..., description="Auth header"),
|
||||
23 + auth: Annotated[str, Header(description="Auth header")],
|
||||
24 | ) -> str:
|
||||
25 | return auth
|
||||
26 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:30:5
|
||||
|
|
||||
28 | async def test_ellipsis_body(
|
||||
29 | # This should become: data: Annotated[dict, Body(description="Request body")]
|
||||
30 | data: dict = Body(..., description="Request body"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
31 | ) -> dict:
|
||||
32 | return data
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
28 | @app.post("/test3")
|
||||
29 | async def test_ellipsis_body(
|
||||
30 | # This should become: data: Annotated[dict, Body(description="Request body")]
|
||||
- data: dict = Body(..., description="Request body"),
|
||||
31 + data: Annotated[dict, Body(description="Request body")],
|
||||
32 | ) -> dict:
|
||||
33 | return data
|
||||
34 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:38:5
|
||||
|
|
||||
36 | async def test_ellipsis_cookie(
|
||||
37 | # This should become: session: Annotated[str, Cookie(description="Session ID")]
|
||||
38 | session: str = Cookie(..., description="Session ID"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
39 | ) -> str:
|
||||
40 | return session
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
36 | @app.get("/test4")
|
||||
37 | async def test_ellipsis_cookie(
|
||||
38 | # This should become: session: Annotated[str, Cookie(description="Session ID")]
|
||||
- session: str = Cookie(..., description="Session ID"),
|
||||
39 + session: Annotated[str, Cookie(description="Session ID")],
|
||||
40 | ) -> str:
|
||||
41 | return session
|
||||
42 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:46:5
|
||||
|
|
||||
44 | async def test_simple_ellipsis(
|
||||
45 | # This should become: id: Annotated[str, Query()]
|
||||
46 | id: str = Query(...),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
47 | ) -> str:
|
||||
48 | return id
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
44 | @app.get("/test5")
|
||||
45 | async def test_simple_ellipsis(
|
||||
46 | # This should become: id: Annotated[str, Query()]
|
||||
- id: str = Query(...),
|
||||
47 + id: Annotated[str, Query()],
|
||||
48 | ) -> str:
|
||||
49 | return id
|
||||
50 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:54:5
|
||||
|
|
||||
52 | async def test_multiple_kwargs_with_ellipsis(
|
||||
53 | # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
|
||||
54 | param: str = Query(..., description="Test", min_length=1, max_length=10),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
55 | ) -> str:
|
||||
56 | return param
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
52 | @app.get("/test6")
|
||||
53 | async def test_multiple_kwargs_with_ellipsis(
|
||||
54 | # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
|
||||
- param: str = Query(..., description="Test", min_length=1, max_length=10),
|
||||
55 + param: Annotated[str, Query(description="Test", min_length=1, max_length=10)],
|
||||
56 | ) -> str:
|
||||
57 | return param
|
||||
58 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:65:5
|
||||
|
|
||||
63 | async def test_with_default_value(
|
||||
64 | # This should become: param: Annotated[str, Query(description="Test")] = "default"
|
||||
65 | param: str = Query("default", description="Test"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
66 | ) -> str:
|
||||
67 | return param
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
63 | @app.get("/test7")
|
||||
64 | async def test_with_default_value(
|
||||
65 | # This should become: param: Annotated[str, Query(description="Test")] = "default"
|
||||
- param: str = Query("default", description="Test"),
|
||||
66 + param: Annotated[str, Query(description="Test")] = "default",
|
||||
67 | ) -> str:
|
||||
68 | return param
|
||||
69 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:73:5
|
||||
|
|
||||
71 | async def test_with_default_none(
|
||||
72 | # This should become: param: Annotated[str | None, Query(description="Test")] = None
|
||||
73 | param: str | None = Query(None, description="Test"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
74 | ) -> str:
|
||||
75 | return param or "empty"
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
71 | @app.get("/test8")
|
||||
72 | async def test_with_default_none(
|
||||
73 | # This should become: param: Annotated[str | None, Query(description="Test")] = None
|
||||
- param: str | None = Query(None, description="Test"),
|
||||
74 + param: Annotated[str | None, Query(description="Test")] = None,
|
||||
75 | ) -> str:
|
||||
76 | return param or "empty"
|
||||
77 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:81:5
|
||||
|
|
||||
79 | async def test_mixed_parameters(
|
||||
80 | # First param should be fixed with default preserved
|
||||
81 | optional_param: str = Query("default", description="Optional"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
82 | # Second param should not be fixed because of the preceding default
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
79 | @app.get("/test9")
|
||||
80 | async def test_mixed_parameters(
|
||||
81 | # First param should be fixed with default preserved
|
||||
- optional_param: str = Query("default", description="Optional"),
|
||||
82 + optional_param: Annotated[str, Query(description="Optional")] = "default",
|
||||
83 | # Second param should not be fixed because of the preceding default
|
||||
84 | required_param: str = Query(..., description="Required"),
|
||||
85 | # Third param should be fixed with default preserved
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:83:5
|
||||
|
|
||||
81 | optional_param: str = Query("default", description="Optional"),
|
||||
82 | # Second param should not be fixed because of the preceding default
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
84 | # Third param should be fixed with default preserved
|
||||
85 | another_optional_param: int = Query(42, description="Another optional"),
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:85:5
|
||||
|
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
84 | # Third param should be fixed with default preserved
|
||||
85 | another_optional_param: int = Query(42, description="Another optional"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
86 | ) -> str:
|
||||
87 | return f"{required_param}-{optional_param}-{another_optional_param}"
|
||||
|
|
||||
help: Replace with `typing.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
83 | # Second param should not be fixed because of the preceding default
|
||||
84 | required_param: str = Query(..., description="Required"),
|
||||
85 | # Third param should be fixed with default preserved
|
||||
- another_optional_param: int = Query(42, description="Another optional"),
|
||||
86 + another_optional_param: Annotated[int, Query(description="Another optional")] = 42,
|
||||
87 | ) -> str:
|
||||
88 | return f"{required_param}-{optional_param}-{another_optional_param}"
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
@@ -0,0 +1,303 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/fastapi/mod.rs
|
||||
---
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:14:5
|
||||
|
|
||||
12 | async def test_ellipsis_query(
|
||||
13 | # This should become: param: Annotated[str, Query(description="Test param")]
|
||||
14 | param: str = Query(..., description="Test param"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
15 | ) -> str:
|
||||
16 | return param
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
12 | @app.get("/test1")
|
||||
13 | async def test_ellipsis_query(
|
||||
14 | # This should become: param: Annotated[str, Query(description="Test param")]
|
||||
- param: str = Query(..., description="Test param"),
|
||||
15 + param: Annotated[str, Query(description="Test param")],
|
||||
16 | ) -> str:
|
||||
17 | return param
|
||||
18 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:22:5
|
||||
|
|
||||
20 | async def test_ellipsis_header(
|
||||
21 | # This should become: auth: Annotated[str, Header(description="Auth header")]
|
||||
22 | auth: str = Header(..., description="Auth header"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
23 | ) -> str:
|
||||
24 | return auth
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
20 | @app.get("/test2")
|
||||
21 | async def test_ellipsis_header(
|
||||
22 | # This should become: auth: Annotated[str, Header(description="Auth header")]
|
||||
- auth: str = Header(..., description="Auth header"),
|
||||
23 + auth: Annotated[str, Header(description="Auth header")],
|
||||
24 | ) -> str:
|
||||
25 | return auth
|
||||
26 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:30:5
|
||||
|
|
||||
28 | async def test_ellipsis_body(
|
||||
29 | # This should become: data: Annotated[dict, Body(description="Request body")]
|
||||
30 | data: dict = Body(..., description="Request body"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
31 | ) -> dict:
|
||||
32 | return data
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
28 | @app.post("/test3")
|
||||
29 | async def test_ellipsis_body(
|
||||
30 | # This should become: data: Annotated[dict, Body(description="Request body")]
|
||||
- data: dict = Body(..., description="Request body"),
|
||||
31 + data: Annotated[dict, Body(description="Request body")],
|
||||
32 | ) -> dict:
|
||||
33 | return data
|
||||
34 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:38:5
|
||||
|
|
||||
36 | async def test_ellipsis_cookie(
|
||||
37 | # This should become: session: Annotated[str, Cookie(description="Session ID")]
|
||||
38 | session: str = Cookie(..., description="Session ID"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
39 | ) -> str:
|
||||
40 | return session
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
36 | @app.get("/test4")
|
||||
37 | async def test_ellipsis_cookie(
|
||||
38 | # This should become: session: Annotated[str, Cookie(description="Session ID")]
|
||||
- session: str = Cookie(..., description="Session ID"),
|
||||
39 + session: Annotated[str, Cookie(description="Session ID")],
|
||||
40 | ) -> str:
|
||||
41 | return session
|
||||
42 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:46:5
|
||||
|
|
||||
44 | async def test_simple_ellipsis(
|
||||
45 | # This should become: id: Annotated[str, Query()]
|
||||
46 | id: str = Query(...),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
47 | ) -> str:
|
||||
48 | return id
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
44 | @app.get("/test5")
|
||||
45 | async def test_simple_ellipsis(
|
||||
46 | # This should become: id: Annotated[str, Query()]
|
||||
- id: str = Query(...),
|
||||
47 + id: Annotated[str, Query()],
|
||||
48 | ) -> str:
|
||||
49 | return id
|
||||
50 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:54:5
|
||||
|
|
||||
52 | async def test_multiple_kwargs_with_ellipsis(
|
||||
53 | # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
|
||||
54 | param: str = Query(..., description="Test", min_length=1, max_length=10),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
55 | ) -> str:
|
||||
56 | return param
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
52 | @app.get("/test6")
|
||||
53 | async def test_multiple_kwargs_with_ellipsis(
|
||||
54 | # This should become: param: Annotated[str, Query(description="Test", min_length=1, max_length=10)]
|
||||
- param: str = Query(..., description="Test", min_length=1, max_length=10),
|
||||
55 + param: Annotated[str, Query(description="Test", min_length=1, max_length=10)],
|
||||
56 | ) -> str:
|
||||
57 | return param
|
||||
58 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:65:5
|
||||
|
|
||||
63 | async def test_with_default_value(
|
||||
64 | # This should become: param: Annotated[str, Query(description="Test")] = "default"
|
||||
65 | param: str = Query("default", description="Test"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
66 | ) -> str:
|
||||
67 | return param
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
63 | @app.get("/test7")
|
||||
64 | async def test_with_default_value(
|
||||
65 | # This should become: param: Annotated[str, Query(description="Test")] = "default"
|
||||
- param: str = Query("default", description="Test"),
|
||||
66 + param: Annotated[str, Query(description="Test")] = "default",
|
||||
67 | ) -> str:
|
||||
68 | return param
|
||||
69 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:73:5
|
||||
|
|
||||
71 | async def test_with_default_none(
|
||||
72 | # This should become: param: Annotated[str | None, Query(description="Test")] = None
|
||||
73 | param: str | None = Query(None, description="Test"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
74 | ) -> str:
|
||||
75 | return param or "empty"
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
71 | @app.get("/test8")
|
||||
72 | async def test_with_default_none(
|
||||
73 | # This should become: param: Annotated[str | None, Query(description="Test")] = None
|
||||
- param: str | None = Query(None, description="Test"),
|
||||
74 + param: Annotated[str | None, Query(description="Test")] = None,
|
||||
75 | ) -> str:
|
||||
76 | return param or "empty"
|
||||
77 |
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:81:5
|
||||
|
|
||||
79 | async def test_mixed_parameters(
|
||||
80 | # First param should be fixed with default preserved
|
||||
81 | optional_param: str = Query("default", description="Optional"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
82 | # Second param should not be fixed because of the preceding default
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
79 | @app.get("/test9")
|
||||
80 | async def test_mixed_parameters(
|
||||
81 | # First param should be fixed with default preserved
|
||||
- optional_param: str = Query("default", description="Optional"),
|
||||
82 + optional_param: Annotated[str, Query(description="Optional")] = "default",
|
||||
83 | # Second param should not be fixed because of the preceding default
|
||||
84 | required_param: str = Query(..., description="Required"),
|
||||
85 | # Third param should be fixed with default preserved
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST002 FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:83:5
|
||||
|
|
||||
81 | optional_param: str = Query("default", description="Optional"),
|
||||
82 | # Second param should not be fixed because of the preceding default
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
84 | # Third param should be fixed with default preserved
|
||||
85 | another_optional_param: int = Query(42, description="Another optional"),
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
|
||||
FAST002 [*] FastAPI dependency without `Annotated`
|
||||
--> FAST002_2.py:85:5
|
||||
|
|
||||
83 | required_param: str = Query(..., description="Required"),
|
||||
84 | # Third param should be fixed with default preserved
|
||||
85 | another_optional_param: int = Query(42, description="Another optional"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
86 | ) -> str:
|
||||
87 | return f"{required_param}-{optional_param}-{another_optional_param}"
|
||||
|
|
||||
help: Replace with `typing_extensions.Annotated`
|
||||
1 | """Test FAST002 ellipsis handling."""
|
||||
2 |
|
||||
3 | from fastapi import Body, Cookie, FastAPI, Header, Query
|
||||
4 + from typing_extensions import Annotated
|
||||
5 |
|
||||
6 | app = FastAPI()
|
||||
7 |
|
||||
--------------------------------------------------------------------------------
|
||||
83 | # Second param should not be fixed because of the preceding default
|
||||
84 | required_param: str = Query(..., description="Required"),
|
||||
85 | # Third param should be fixed with default preserved
|
||||
- another_optional_param: int = Query(42, description="Another optional"),
|
||||
86 + another_optional_param: Annotated[int, Query(description="Another optional")] = 42,
|
||||
87 | ) -> str:
|
||||
88 | return f"{required_param}-{optional_param}-{another_optional_param}"
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
@@ -363,3 +363,26 @@ help: Add `id` to function signature
|
||||
206 |
|
||||
207 | # No errors
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
FAST003 Parameter `import` appears in route path, but not in `get_import` signature
|
||||
--> FAST003.py:261:20
|
||||
|
|
||||
260 | # https://github.com/astral-sh/ruff/issues/20941
|
||||
261 | @app.get("/imports/{import}")
|
||||
| ^^^^^^^^
|
||||
262 | async def get_import():
|
||||
263 | ...
|
||||
|
|
||||
help: Add `import` to function signature
|
||||
|
||||
FAST003 Parameter `__debug__` appears in route path, but not in `get_debug` signature
|
||||
--> FAST003.py:265:18
|
||||
|
|
||||
263 | ...
|
||||
264 |
|
||||
265 | @app.get("/debug/{__debug__}")
|
||||
| ^^^^^^^^^^^
|
||||
266 | async def get_debug():
|
||||
267 | ...
|
||||
|
|
||||
help: Add `__debug__` to function signature
|
||||
|
||||
@@ -41,6 +41,7 @@ use crate::rules::flake8_2020::helpers::is_sys;
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionCmpStr3;
|
||||
|
||||
impl Violation for SysVersionCmpStr3 {
|
||||
@@ -91,6 +92,7 @@ impl Violation for SysVersionCmpStr3 {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionInfo0Eq3 {
|
||||
eq: bool,
|
||||
}
|
||||
@@ -137,6 +139,7 @@ impl Violation for SysVersionInfo0Eq3 {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionInfo1CmpInt;
|
||||
|
||||
impl Violation for SysVersionInfo1CmpInt {
|
||||
@@ -179,6 +182,7 @@ impl Violation for SysVersionInfo1CmpInt {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionInfoMinorCmpInt;
|
||||
|
||||
impl Violation for SysVersionInfoMinorCmpInt {
|
||||
@@ -222,6 +226,7 @@ impl Violation for SysVersionInfoMinorCmpInt {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionCmpStr10;
|
||||
|
||||
impl Violation for SysVersionCmpStr10 {
|
||||
|
||||
@@ -36,6 +36,7 @@ use crate::checkers::ast::Checker;
|
||||
/// - [Six documentation: `six.PY2`](https://six.readthedocs.io/#six.PY2)
|
||||
/// - [Six documentation: `six.PY3`](https://six.readthedocs.io/#six.PY3)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SixPY3;
|
||||
|
||||
impl Violation for SixPY3 {
|
||||
|
||||
@@ -38,6 +38,7 @@ use crate::rules::flake8_2020::helpers::is_sys;
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionSlice3;
|
||||
|
||||
impl Violation for SysVersionSlice3 {
|
||||
@@ -78,6 +79,7 @@ impl Violation for SysVersionSlice3 {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersion2;
|
||||
|
||||
impl Violation for SysVersion2 {
|
||||
@@ -118,6 +120,7 @@ impl Violation for SysVersion2 {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersion0;
|
||||
|
||||
impl Violation for SysVersion0 {
|
||||
@@ -158,6 +161,7 @@ impl Violation for SysVersion0 {
|
||||
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
|
||||
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.113")]
|
||||
pub(crate) struct SysVersionSlice1;
|
||||
|
||||
impl Violation for SysVersionSlice1 {
|
||||
|
||||
@@ -38,6 +38,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
|
||||
/// ## Options
|
||||
/// - `lint.flake8-annotations.suppress-dummy-args`
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingTypeFunctionArgument {
|
||||
name: String,
|
||||
}
|
||||
@@ -73,6 +74,7 @@ impl Violation for MissingTypeFunctionArgument {
|
||||
/// ## Options
|
||||
/// - `lint.flake8-annotations.suppress-dummy-args`
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingTypeArgs {
|
||||
name: String,
|
||||
}
|
||||
@@ -108,6 +110,7 @@ impl Violation for MissingTypeArgs {
|
||||
/// ## Options
|
||||
/// - `lint.flake8-annotations.suppress-dummy-args`
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingTypeKwargs {
|
||||
name: String,
|
||||
}
|
||||
@@ -149,6 +152,7 @@ impl Violation for MissingTypeKwargs {
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[deprecated(note = "ANN101 has been removed")]
|
||||
#[violation_metadata(removed_since = "0.8.0")]
|
||||
pub(crate) struct MissingTypeSelf;
|
||||
|
||||
#[expect(deprecated)]
|
||||
@@ -193,6 +197,7 @@ impl Violation for MissingTypeSelf {
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[deprecated(note = "ANN102 has been removed")]
|
||||
#[violation_metadata(removed_since = "0.8.0")]
|
||||
pub(crate) struct MissingTypeCls;
|
||||
|
||||
#[expect(deprecated)]
|
||||
@@ -236,6 +241,7 @@ impl Violation for MissingTypeCls {
|
||||
///
|
||||
/// - `lint.typing-extensions`
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingReturnTypeUndocumentedPublicFunction {
|
||||
name: String,
|
||||
annotation: Option<String>,
|
||||
@@ -289,6 +295,7 @@ impl Violation for MissingReturnTypeUndocumentedPublicFunction {
|
||||
///
|
||||
/// - `lint.typing-extensions`
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingReturnTypePrivateFunction {
|
||||
name: String,
|
||||
annotation: Option<String>,
|
||||
@@ -345,6 +352,7 @@ impl Violation for MissingReturnTypePrivateFunction {
|
||||
/// self.x = x
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingReturnTypeSpecialMethod {
|
||||
name: String,
|
||||
annotation: Option<String>,
|
||||
@@ -392,6 +400,7 @@ impl Violation for MissingReturnTypeSpecialMethod {
|
||||
/// return 1
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingReturnTypeStaticMethod {
|
||||
name: String,
|
||||
annotation: Option<String>,
|
||||
@@ -439,6 +448,7 @@ impl Violation for MissingReturnTypeStaticMethod {
|
||||
/// return 1
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.105")]
|
||||
pub(crate) struct MissingReturnTypeClassMethod {
|
||||
name: String,
|
||||
annotation: Option<String>,
|
||||
@@ -508,6 +518,7 @@ impl Violation for MissingReturnTypeClassMethod {
|
||||
/// - [Python documentation: `typing.Any`](https://docs.python.org/3/library/typing.html#typing.Any)
|
||||
/// - [Mypy documentation: The Any type](https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-any-type)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "v0.0.108")]
|
||||
pub(crate) struct AnyType {
|
||||
name: String,
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ use crate::rules::flake8_async::helpers::AsyncModule;
|
||||
/// - [`anyio` events](https://anyio.readthedocs.io/en/latest/api.html#anyio.Event)
|
||||
/// - [`trio` events](https://trio.readthedocs.io/en/latest/reference-core.html#trio.Event)
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct AsyncBusyWait {
|
||||
module: AsyncModule,
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ use ruff_python_ast::PythonVersion;
|
||||
///
|
||||
/// ["structured concurrency"]: https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/#timeouts-and-cancellation
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct AsyncFunctionWithTimeout {
|
||||
module: AsyncModule,
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
|
||||
/// )
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct AsyncZeroSleep {
|
||||
module: AsyncModule,
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ use crate::checkers::ast::Checker;
|
||||
/// ...
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct BlockingHttpCallInAsyncFunction;
|
||||
|
||||
impl Violation for BlockingHttpCallInAsyncFunction {
|
||||
|
||||
@@ -37,6 +37,7 @@ use crate::checkers::ast::Checker;
|
||||
/// response = await client.get(...)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(preview_since = "0.12.11")]
|
||||
pub(crate) struct BlockingHttpCallHttpxInAsyncFunction {
|
||||
name: String,
|
||||
call: String,
|
||||
|
||||
@@ -33,6 +33,7 @@ use crate::checkers::ast::Checker;
|
||||
/// username = await loop.run_in_executor(None, input, "Username:")
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(preview_since = "0.12.12")]
|
||||
pub(crate) struct BlockingInputInAsyncFunction;
|
||||
|
||||
impl Violation for BlockingInputInAsyncFunction {
|
||||
|
||||
@@ -34,6 +34,7 @@ use crate::checkers::ast::Checker;
|
||||
/// contents = await f.read()
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct BlockingOpenCallInAsyncFunction;
|
||||
|
||||
impl Violation for BlockingOpenCallInAsyncFunction {
|
||||
|
||||
@@ -47,6 +47,7 @@ use ruff_text_size::Ranged;
|
||||
/// new_path = os.path.join("/tmp/src/", path)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(preview_since = "0.13.2")]
|
||||
pub(crate) struct BlockingPathMethodInAsyncFunction {
|
||||
path_library: String,
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ use crate::checkers::ast::Checker;
|
||||
/// asyncio.create_subprocess_shell(cmd)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct CreateSubprocessInAsyncFunction;
|
||||
|
||||
impl Violation for CreateSubprocessInAsyncFunction {
|
||||
@@ -76,6 +77,7 @@ impl Violation for CreateSubprocessInAsyncFunction {
|
||||
/// asyncio.create_subprocess_shell(cmd)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct RunProcessInAsyncFunction;
|
||||
|
||||
impl Violation for RunProcessInAsyncFunction {
|
||||
@@ -120,6 +122,7 @@ impl Violation for RunProcessInAsyncFunction {
|
||||
/// await asyncio.loop.run_in_executor(None, wait_for_process)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
#[violation_metadata(stable_since = "0.5.0")]
|
||||
pub(crate) struct WaitForProcessInAsyncFunction;
|
||||
|
||||
impl Violation for WaitForProcessInAsyncFunction {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user