-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruff 0.5 #12005
Ruff 0.5 #12005
Commits on Jun 27, 2024
-
Remove deprecated configuration '--show-source` (#9814)
Co-authored-by: Micha Reiser <micha@reiser.io> Fixes parts of #7650
Configuration menu - View commit details
-
Copy full SHA for dd0b8f6 - Browse repository at this point
Copy the full SHA dd0b8f6View commit details -
Use rule name rather than message in
--statistics
(#11697)Co-authored-by: Micha Reiser <micha@reiser.io> Closes #11097.
Configuration menu - View commit details
-
Copy full SHA for 9b99d81 - Browse repository at this point
Copy the full SHA 9b99d81View commit details -
Update Rust crate unicode-width to v0.1.13 (#11194)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Micha Reiser <micha@reiser.io>
Configuration menu - View commit details
-
Copy full SHA for 647a879 - Browse repository at this point
Copy the full SHA 647a879View commit details -
Read user configuration from
~/.config/ruff/ruff.toml
on macOS (#11115) Co-authored-by: Micha Reiser <micha@reiser.io> Closes #10739.
Configuration menu - View commit details
-
Copy full SHA for 3ce9d6a - Browse repository at this point
Copy the full SHA 3ce9d6aView commit details -
Drop deprecated
nursery
rule group (#10172)Co-authored-by: Micha Reiser <micha@reiser.io> Resolves #7992
Configuration menu - View commit details
-
Copy full SHA for 7d4ffcf - Browse repository at this point
Copy the full SHA 7d4ffcfView commit details -
Configuration menu - View commit details
-
Copy full SHA for b62b73b - Browse repository at this point
Copy the full SHA b62b73bView commit details -
Configuration menu - View commit details
-
Copy full SHA for a37ff12 - Browse repository at this point
Copy the full SHA a37ff12View commit details -
Added ignoring deprecated rules for --select=ALL (#10497)
Co-authored-by: Micha Reiser <micha@reiser.io>
Configuration menu - View commit details
-
Copy full SHA for 1126d45 - Browse repository at this point
Copy the full SHA 1126d45View commit details -
Configuration menu - View commit details
-
Copy full SHA for c1c7642 - Browse repository at this point
Copy the full SHA c1c7642View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4a5e927 - Browse repository at this point
Copy the full SHA 4a5e927View commit details -
Redirect
PLR1701
toSIM101
(#12021)## Summary This rule removes `PLR1701` and redirects it to `SIM101`. In addition to that, the `SIM101` autofix has been fixed to add padding if required. ### `PLR1701` has bugs It also seems that the implementation of `PLR1701` is incorrect in multiple scenarios. For example, the following code snippet: ```py # There are two _different_ variables `a` and `b` if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float): pass # There's another condition `or 1` if isinstance(self.k, int) or isinstance(self.k, float) or 1: pass ``` is fixed to: ```py # Fixed to only considering variable `a` if isinstance(a, (float, int)): pass # The additional condition is not present in the fix if isinstance(self.k, (float, int)): pass ``` Playground: https://play.ruff.rs/6cfbdfb7-f183-43b0-b59e-31e728b34190 ## Documentation Preview ### `PLR1701` <img width="1397" alt="Screenshot 2024-06-25 at 11 14 40" src="https://github.com/astral-sh/ruff/assets/67177269/779ee84d-7c4d-4bb8-a3a4-c2b23a313eba"> ## Test Plan Remove the test cases for `PLR1701`, port the padding test case to `SIM101` and update the snapshot.
Configuration menu - View commit details
-
Copy full SHA for c5209b6 - Browse repository at this point
Copy the full SHA c5209b6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3c7a51f - Browse repository at this point
Copy the full SHA 3c7a51fView commit details -
[
pycodestyle
] Remove deprecated functionality from `type-comparison……` (`E721`) (#11220) ## Summary Stabilizes `E721` behavior implemented in #7905. The functionality change in `E721` was implemented in #7905, released in [v0.1.2](https://github.com/astral-sh/ruff/releases/tag/v0.1.2). And seems functionally stable since #9676, without an explicit release but would correspond to [v0.2.0](https://github.com/astral-sh/ruff/releases/tag/v0.2.0). So the deprecated functionally should be removable in the next minor release. resolves: #6465
Configuration menu - View commit details
-
Copy full SHA for 7b61bc5 - Browse repository at this point
Copy the full SHA 7b61bc5View commit details -
Migrate release workflow to
cargo-dist
(#9559)## Summary This PR migrates our release workflow to [`cargo-dist`](https://github.com/axodotdev/cargo-dist). The primary motivation here is that we want to ship dedicated installers for Ruff that work across platforms, and `cargo-dist` gives us those installers out-of-the-box. The secondary motivation is that `cargo-dist` formalizes some of the patterns that we've built up over time in our own release process. At a high level: - The `release.yml` file is generated by `cargo-dist` with `cargo dist generate`. It doesn't contain any modifications vis-a-vis the generated file. (If it's edited out of band from generation, the release fails.) - Our customizations are inserted as custom steps within the `cargo-dist` workflow. Specifically, `build-binaries` builds the wheels and packages them into binaries (as on `main`), while `build-docker.yml` builds the Docker image. `publish-pypi.yml` publishes the wheels to PyPI. This is effectively our `release.yaml` (on `main`), broken down into individual workflows rather than steps within a single workflow. ### Changes from `main` The workflow is _nearly_ unchanged. We kick off a release manually via the GitHub Action by providing a tag. If the tag doesn't match the `Cargo.toml`, the release fails. If the tag matches an already-existing release, the release fails. The release proceeds by (in order): 0. Doing some upfront validation via `cargo-dist`. 1. Creating the wheels and archives. 2. Building and pushing the Docker image. 3. Publishing to PyPI (if it's not a "dry run"). 4. Creating the GitHub Release (if it's not a "dry run"). 5. Notifying `ruff-pre-commit` (if it's not a "dry run"). There are a few changes in the workflow as compared to `main`: - **We no longer validate the SHA** (just the tag). It's not an input to the job. The Axo team is considering whether / how to support this. - **Releases are now published directly** (rather than as draft). Again, the Axo team is considering whether / how to support this. The downside of drafts is that the URLs aren't stable, so the installers don't work _as long as the release is in draft_. This is fine for our workflow. It seems like the Axo team will add it. - Releases already contain the latest entry from the changelog (we don't need to copy it over). This "Just Works", which is nice, though we'll still want to edit them to add contributors. There are also a few **breaking changes** for consumers of the binaries: - **We no longer include the version tag in the file name**. This enables users to install via `/latest` URLs on GitHub, and is part of the cargo-dist paradigm. - **Archives now include an extra level of nesting,** which you can remove with `--strip-components=1` when untarring. Here's an example release that I created -- I omitted all the artifacts since I was just testing a workflow, so none of the installers or links work, but it gives you a sense for what the release looks like: https://github.com/charliermarsh/cargodisttest/releases/tag/0.1.13. ### Test Plan I ran a successful release to completion last night, and installed Ruff via the installer: ![Screenshot 2024-01-17 at 12 12 53 AM](https://github.com/astral-sh/ruff/assets/1309177/a5334466-2ca3-4279-a453-e912a0805df2) ![Screenshot 2024-01-17 at 12 12 48 AM](https://github.com/astral-sh/ruff/assets/1309177/63ac969e-69a1-488c-8367-4cb783526ca7) The piece I'm least confident about is the Docker push. We build the image, but the push fails in my test repo since I haven't wired up the credentials.
Configuration menu - View commit details
-
Copy full SHA for 701b62a - Browse repository at this point
Copy the full SHA 701b62aView commit details -
Stabilise
django-extra
(S610
) for release 0.5 (#12029)The motivation for this rule is solid; it's been in preview for a long time; the implementation and tests seem sound; there are no open issues regarding it, and as far as I can tell there never have been any. The only issue I see is that the docs don't really describe the rule accurately right now; I fix that in this PR.
Configuration menu - View commit details
-
Copy full SHA for e9b7d75 - Browse repository at this point
Copy the full SHA e9b7d75View commit details -
Configuration menu - View commit details
-
Copy full SHA for 78ffe79 - Browse repository at this point
Copy the full SHA 78ffe79View commit details -
refactor: Compile time enforcement that all top level lint options ar…
…e checked for deprecation (#12037)
Configuration menu - View commit details
-
Copy full SHA for 8f996f6 - Browse repository at this point
Copy the full SHA 8f996f6View commit details -
Re-code flake8-trio and flake8-async rules to match upstream (#10416)
Co-authored-by: Micha Reiser <micha@reiser.io>
Configuration menu - View commit details
-
Copy full SHA for 3ff580a - Browse repository at this point
Copy the full SHA 3ff580aView commit details -
Configuration menu - View commit details
-
Copy full SHA for d13eb40 - Browse repository at this point
Copy the full SHA d13eb40View commit details -
Configuration menu - View commit details
-
Copy full SHA for d72fb7e - Browse repository at this point
Copy the full SHA d72fb7eView commit details -
Configuration menu - View commit details
-
Copy full SHA for fc69b59 - Browse repository at this point
Copy the full SHA fc69b59View commit details -
[
flake8-simplify
] Stabilize implicit-else
simplifications in `nee…Configuration menu - View commit details
-
Copy full SHA for 82f09ce - Browse repository at this point
Copy the full SHA 82f09ceView commit details -
Configuration menu - View commit details
-
Copy full SHA for d0fe904 - Browse repository at this point
Copy the full SHA d0fe904View commit details -
Remove
E999
as a rule, disallow any disablement methods for syntax ……error (#11901) ## Summary This PR updates the way syntax errors are handled throughout the linter. The main change is that it's now not considered as a rule which involves the following changes: * Update `Message` to be an enum with two variants - one for diagnostic message and the other for syntax error message * Provide methods on the new message enum to query information required by downstream usages This means that the syntax errors cannot be hidden / disabled via any disablement methods. These are: 1. Configuration via `select`, `ignore`, `per-file-ignores`, and their `extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` 3. Command-line flags via `--select`, `--ignore`, `--per-file-ignores`, and their `--extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --no-cache --config=~/playground/ruff/pyproject.toml Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --no-cache --config=/Users/dhruv/playground/ruff/pyproject.toml` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` This also means that the **output format** needs to be updated: 1. The `code`, `noqa_row`, `url` fields in the JSON output is optional (`null` for syntax errors) 2. Other formats are changed accordingly For each format, a new test case specific to syntax errors have been added. Please refer to the snapshot output for the exact format for syntax error message. The output of the `--statistics` flag will have a blank entry for syntax errors: ``` 315 F821 [ ] undefined-name 119 [ ] syntax-error 103 F811 [ ] redefined-while-unused ``` The **language server** is updated to consider the syntax errors by convert them into LSP diagnostic format separately. ### Preview There are no quick fixes provided to disable syntax errors. This will automatically work for `ruff-lsp` because the `noqa_row` field will be `null` in that case. <img width="772" alt="Screenshot 2024-06-26 at 14 57 08" src="https://github.com/astral-sh/ruff/assets/67177269/aaac827e-4777-4ac8-8c68-eaf9f2c36774"> Even with `noqa` comment, the syntax error is displayed: <img width="763" alt="Screenshot 2024-06-26 at 14 59 51" src="https://github.com/astral-sh/ruff/assets/67177269/ba1afb68-7eaf-4b44-91af-6d93246475e2"> Rule documentation page: <img width="1371" alt="Screenshot 2024-06-26 at 16 48 07" src="https://github.com/astral-sh/ruff/assets/67177269/524f01df-d91f-4ac0-86cc-40e76b318b24"> ## Test Plan - [x] Disablement methods via config shows a warning - [x] `select`, `extend-select` - [ ] ~`ignore`~ _doesn't show any message_ - [ ] ~`per-file-ignores`, `extend-per-file-ignores`~ _doesn't show any message_ - [x] Disablement methods via command-line flag shows a warning - [x] `--select`, `--extend-select` - [ ] ~`--ignore`~ _doesn't show any message_ - [ ] ~`--per-file-ignores`, `--extend-per-file-ignores`~ _doesn't show any message_ - [x] File with syntax errors should exit with code 1 - [x] Language server - [x] Should show diagnostics for syntax errors - [x] Should not recommend a quick fix edit for adding `noqa` comment - [x] Same for `ruff-lsp` resolves: #8447
Configuration menu - View commit details
-
Copy full SHA for 3396703 - Browse repository at this point
Copy the full SHA 3396703View commit details -
Avoid displaying syntax error as log message (#11902)
## Summary Follow-up to #11901 This PR avoids displaying the syntax errors as log message now that the `E999` diagnostic cannot be disabled. For context on why this was added, refer to #2505. Basically, we would allow ignoring the syntax error diagnostic because certain syntax feature weren't supported back then like `match` statement. And, if a user ignored `E999`, Ruff would give no feedback if the source code contained any syntax error. So, this log message was a way to indicate to the user even if `E999` was disabled. The current state of the parser is such that (a) it matches with the latest grammar and (b) it's easy to add support for any new syntax. **Note:** This PR doesn't remove the `DisplayParseError` struct because it's still being used by the formatter. ## Test Plan Update existing snapshots from the integration tests.
Configuration menu - View commit details
-
Copy full SHA for a6d047f - Browse repository at this point
Copy the full SHA a6d047fView commit details -
Simplify
LinterResult
, avoid cloningParseError
(#11903)## Summary Follow-up to #11902 This PR simplifies the `LinterResult` struct by avoiding the generic and not store the `ParseError`. This is possible because the callers already have access to the `ParseError` via the `Parsed` output. This also means that we can simplify the return type of `check_path` and avoid the generic `T` on `LinterResult`. ## Test Plan `cargo insta test`
Configuration menu - View commit details
-
Copy full SHA for 9351c5c - Browse repository at this point
Copy the full SHA 9351c5cView commit details -
Add server config to filter out syntax error diagnostics (#12059)
## Summary Follow-up from #11901 This PR adds a new server setting to show / hide syntax errors. ## Test Plan ### VS Code Using astral-sh/ruff-vscode#504 with the following config: ```json { "ruff.nativeServer": true, "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], "ruff.showSyntaxErrors": true } ``` First, set `ruff.showSyntaxErrors` to `true`: <img width="1177" alt="Screenshot 2024-06-27 at 08 34 58" src="https://github.com/astral-sh/ruff/assets/67177269/5d77547a-a908-4a00-8714-7c00784e8679"> And then set it to `false`: <img width="1185" alt="Screenshot 2024-06-27 at 08 35 19" src="https://github.com/astral-sh/ruff/assets/67177269/9720f089-f10c-420b-a2c1-2bbb2245be35"> ### Neovim Using the following Ruff server config: ```lua require('lspconfig').ruff.setup { init_options = { settings = { showSyntaxErrors = false, }, }, } ``` First, set `showSyntaxErrors` to `true`: <img width="1279" alt="Screenshot 2024-06-27 at 08 28 03" src="https://github.com/astral-sh/ruff/assets/67177269/e694e231-91ba-47f8-8e8a-ad2e82b85a45"> And then set it to `false`: <img width="1284" alt="Screenshot 2024-06-27 at 08 28 20" src="https://github.com/astral-sh/ruff/assets/67177269/25b86a57-02b1-44f7-9f65-cf5fdde93b0c">
Configuration menu - View commit details
-
Copy full SHA for 7362c1a - Browse repository at this point
Copy the full SHA 7362c1aView commit details -
Update documentation to mention
etcetera
crate instead ofdirs
fo……r user configuration discovery (#12064)
Configuration menu - View commit details
-
Copy full SHA for 0a894c6 - Browse repository at this point
Copy the full SHA 0a894c6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7f6da08 - Browse repository at this point
Copy the full SHA 7f6da08View commit details -
[
flake8-simplify
] Stabilize detection of Yoda conditions for "const……ant" collections (`SIM300`) (#12050) Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 8ccbf1a - Browse repository at this point
Copy the full SHA 8ccbf1aView commit details