konstin
6bd83d36ee
Replace num_bigint with malachite
...
[malachite](https://www.malachite.rs/ ) is an arbitrary precision crate that unlike num_bigint implement as small integer optimization. This avoids allocating a `Vec` for every single number parse and instead only allocates for rare unusually large numbers.
This is also a correctness improvement since we'd previously just ignore the higher parts of unreasonably large numbers.
The disadvantage is that malachite is slow to compile.
2023-09-19 12:02:32 +02:00
konsti
94b68f201b
Fix stylist indentation with a formfeed ( #7489 )
...
**Summary** In python, a formfeed is technically undefined behaviour
(https://docs.python.org/3/reference/lexical_analysis.html#indentation ):
> A formfeed character may be present at the start of the line; it will
be ignored for
> the indentation calculations above. Formfeed characters occurring
elsewhere in the
> leading whitespace have an undefined effect (for instance, they may
reset the space
> count to zero).
In practice, they just reset the indentation:
df8b3a46a7/Parser/tokenizer.c (L1819-L1821)
a41bb2733f/crates/ruff_python_parser/src/lexer.rs (L664-L667)
The stylist didn't handle formfeeds previously and would produce invalid
indents. The remedy is to cut everything before a form feed.
Checks box for
https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722458825
**Test Plan** Unit test for the stylist and a regression test for the
rule
2023-09-19 12:01:16 +02:00
konsti
ef34c5cbec
Update itertools to 0.11 ( #7513 )
...
Preparation for #7469 .
Changelog:
https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0110
2023-09-19 09:53:14 +00:00
dependabot[bot]
fdbefd777c
Bump syn from 2.0.33 to 2.0.37 ( #7512 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-19 11:08:56 +02:00
dependabot[bot]
078547adbb
Bump clap from 4.4.3 to 4.4.4 ( #7511 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-19 11:08:39 +02:00
dependabot[bot]
42a0bec146
Bump schemars from 0.8.13 to 0.8.15 ( #7510 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-19 11:08:22 +02:00
Micha Reiser
37b7d0f921
fix: Compiler warning about unused `map_or` ( #7508 )
2023-09-19 08:10:01 +00:00
Micha Reiser
6a4dbd622b
Add optimized `best_fit_parenthesize` IR ( #7475 )
2023-09-19 06:29:05 +00:00
Charlie Marsh
28b48ab902
Avoid flagging starred expressions in UP007 ( #7505 )
...
## Summary
These can't be fixed, because fixing them would lead to invalid syntax.
So flagging them also feels misleading.
Closes https://github.com/astral-sh/ruff/issues/7452 .
2023-09-19 03:37:38 +00:00
Valeriy Savchenko
4123d074bd
[refurb] Implement `reimplemented-starmap` rule (`FURB140`) ( #7253 )
...
## Summary
This PR is part of a bigger effort of re-implementing `refurb` rules
#1348 . It adds support for
[FURB140](https://github.com/dosisod/refurb/blob/master/refurb/checks/itertools/use_starmap.py )
## Test Plan
I included a new test + checked that all other tests pass.
2023-09-19 02:18:54 +00:00
Mathieu Kniewallner
c6ba7dfbc6
feat(rules): implement `flake8-bandit` `S201` (`flask_debug_true`) ( #7503 )
...
Part of #1646 .
## Summary
Implement `S201`
([`flask_debug_true`](https://bandit.readthedocs.io/en/latest/plugins/b201_flask_debug_true.html ))
rule from `bandit`.
I am fairly new to Rust and Ruff's codebase, so there might be better
ways to implement the rule or write the code.
## Test Plan
Snapshot test from
https://github.com/PyCQA/bandit/blob/1.7.5/examples/flask_debug.py , with
a few additions in the "unrelated" part to test a bit more cases.
2023-09-19 00:43:28 +00:00
Micael Jarniac
40f6456add
Use MkDocs' `not_in_nav` ( #5498 )
...
Closes #5497
Needs MkDocs 1.5 to be released.
- [x] https://github.com/mkdocs/mkdocs/milestone/15
## Summary
Uses MkDocs' `not_in_nav` config to hide spam about files in
`docs/rules/` not being in nav.
2023-09-19 00:01:43 +00:00
Micha Reiser
3e1dffab20
refactor: Use `OnceCell` in `Memoized` ( #7500 )
2023-09-18 19:58:55 +00:00
Micha Reiser
3336d23f48
perf: Reduce best fitting allocations ( #7411 )
2023-09-18 19:49:44 +00:00
Jonathan Plasse
2421805033
Avoid N802 violations for @overload methods ( #7498 )
...
Close #7479
The `@override` was already implemented
## Test Plan
Tested the code in the issue. After removing all the noqa's, only one
occurrence of `BadName()` raised a violation.
Added a fixture
2023-09-18 14:32:40 -04:00
Tom Kuson
359f50e6dc
Ignore `pass-statement-stub-body` documentation formatting ( #7497 )
...
## Summary
Fix CI (broken in #7496 ).
The code snippet was formatted as Black would format a stub file, but
the CI script doesn't know that (it assumes all code snippets are
non-stub files). Easier to ignore.
Sorry for breaking CI!
## Test Plan
`python scripts/check_docs_formatted.py`
2023-09-18 14:27:20 -04:00
qdegraaf
bccba5d73f
[`flake8-logging`] Implement `LOG007`: `ExceptionWithoutExcInfo` ( #7410 )
...
## Summary
This PR implements a new rule for `flake8-logging` plugin that checks
for uses of `logging.exception()` with `exc_info` set to `False` or a
falsy value. It suggests using `logging.error` in these cases instead.
I am unsure about the name. Open to suggestions there, went with the
most explicit name I could think of in the meantime.
Refer https://github.com/astral-sh/ruff/issues/7248
## Test Plan
Added a new fixture cases and ran `cargo test`
2023-09-18 17:46:12 +00:00
Tom Kuson
0bfdb15ecf
Add documentation to `pass-statement-stub-body` ( #7496 )
...
## Summary
Add documentation to `pass-statement-stub-body` (`PYI009`) rule. Related
to #2646 .
## Test Plan
`python scripts/check_docs_formatted.py`
2023-09-18 17:33:15 +00:00
dependabot[bot]
a902d14c31
Bump chrono from 0.4.30 to 0.4.31 ( #7481 )
2023-09-18 13:11:51 -04:00
Charlie Marsh
728539291f
Move `FormatExprDict` to top of `expr_dict.rs` ( #7494 )
...
Put the node itself up top, and internal structs down below.
2023-09-18 11:55:18 -04:00
Dhruv Manilawala
c2bd8af59a
Remove triple-quoted string ranges computation ( #7476 )
...
## Summary
This is a follow-up PR for #7435 to remove the now unused triple-quoted
string ranges from the indexer.
2023-09-18 20:57:49 +05:30
Jaap Roes
c946bf157e
Extend `bad-dunder-method-name` to permit `__html__` ( #7492 )
...
## Summary
Fixes #7478
## Test Plan
`cargo test`
2023-09-18 15:16:22 +00:00
Charlie Marsh
8ab2519717
Respect parentheses for precedence in `await` ( #7468 )
...
## Summary
We were using `Parenthesize::IfBreaks` universally for `await`, but
dropping parentheses can change the AST due to precedence. It turns out
that Black's rules aren't _exactly_ the same as operator precedence
(e.g., they leave parentheses around `await ([1, 2, 3])`, although they
aren't strictly required).
Closes https://github.com/astral-sh/ruff/issues/7467 .
## Test Plan
`cargo test`
No change in similarity.
Before:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 398 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99929 | 648 | 16 |
| zulip | 0.99962 | 1437 | 22 |
After:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 398 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99929 | 648 | 16 |
| zulip | 0.99962 | 1437 | 22 |
2023-09-18 09:56:41 -04:00
konsti
c4d85d6fb6
Fix `''' ""'''` formatting ( #7485 )
...
## Summary
`''' ""'''` is an edge case that was previously incorrectly formatted as
`""" """""`.
Fixes #7460
## Test Plan
Added regression test
2023-09-18 10:28:15 +00:00
dependabot[bot]
70ea49bf72
Bump test-case from 3.1.0 to 3.2.1 ( #7484 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 11:31:41 +02:00
dependabot[bot]
8e255974bc
Bump unicode-ident from 1.0.11 to 1.0.12 ( #7482 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 11:31:06 +02:00
dependabot[bot]
d358604464
Bump serde_json from 1.0.106 to 1.0.107 ( #7480 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 11:30:06 +02:00
dependabot[bot]
8243db74fe
Bump indoc from 2.0.3 to 2.0.4 ( #7483 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 11:29:50 +02:00
Micha Reiser
0346e781d4
Fix handling of newlines in empty files ( #7473 )
2023-09-18 06:08:10 +00:00
Tom Kuson
b66bfa6570
Extend `bad-dunder-method-name` to permit `attrs` dunders ( #7472 )
...
## Summary
Closes #7451 .
## Test Plan
`cargo test`
2023-09-17 16:13:33 -04:00
Charlie Marsh
28273eb00b
Avoid flagging starred elements in C402 ( #7466 )
...
## Summary
Rewriting these is not valid syntax.
Part of https://github.com/astral-sh/ruff/issues/7455 .
2023-09-17 15:23:27 +00:00
Charlie Marsh
12acd191e1
Remove parentheses when rewriting assert calls to statements ( #7464 )
2023-09-17 15:18:56 +00:00
Charlie Marsh
64b929bc29
Add padding to prevent some autofix errors ( #7461 )
...
## Summary
We should really be doing this anywhere we _replace_ an expression.
See: https://github.com/astral-sh/ruff/issues/7455 .
2023-09-17 15:14:16 +00:00
Micha Reiser
26ae0a6e8d
Fix dangling module comments ( #7456 )
2023-09-17 14:56:41 +00:00
Dhruv Manilawala
959338d39d
Refactor `tab-indentation` as a token-based rule ( #7435 )
...
## Summary
This PR updates the `W191` (`tab-indentation`) rule from a line-based to
a token-based rule.
Earlier, the rule used the `triple_quoted_string_ranges` from the
indexer to skip over any lines _inside_ a triple-quoted string. This was the only
use of the ranges. These ranges were extracted through the tokens, so instead
we can directly use the newline tokens to perform the check.
This would also mean that we can remove the `triple_quoted_string_ranges` from
the indexer but I'll hold that off until we have a better idea on #7326
but I don't think it would be a problem to remove it.
This will also fix #7379 once PEP 701 changes are merged.
## Test Plan
`cargo test`
2023-09-16 20:25:20 +00:00
Charlie Marsh
422ff82f4a
Avoid extra parentheses in `yield` expressions ( #7444 )
...
## Summary
This is equivalent to https://github.com/astral-sh/ruff/pull/7424 , but
for `yield` and `yield from` expressions. Specifically, we want to avoid
adding unnecessary extra parentheses for `yield expr` when `expr` itself
does not require parentheses.
## Test Plan
`cargo test`
No change in any of the similarity metrics.
Before:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99929 | 648 | 16 |
| zulip | 0.99962 | 1437 | 22 |
After:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99929 | 648 | 16 |
| zulip | 0.99962 | 1437 | 22 |
2023-09-16 14:46:56 -04:00
Charlie Marsh
8d0a5e01bd
Modify `comment_ranges` slice in `BackwardsTokenizer` ( #7432 )
...
## Summary
I was kinda curious to understand this issue
(https://github.com/astral-sh/ruff/issues/7426 ) and just ended up
attempting to address it.
## Test Plan
`cargo test`
2023-09-16 14:04:45 -04:00
Charlie Marsh
aae02cf275
Fix broken `is_expression_parenthesized` call from rebase ( #7442 )
2023-09-16 17:22:16 +00:00
Charlie Marsh
7e2eba2592
Avoiding grouping comprehension targets separately from conditions ( #7429 )
...
## Summary
Black seems to treat comprehension targets and conditions as if they're
in a single group -- so if the comprehension expands, all conditions are
rendered on their own line, etc.
Closes https://github.com/astral-sh/ruff/issues/7421 .
## Test Plan
`cargo test`
No change in any of the similarity metrics.
Before:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
After:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
2023-09-16 17:19:34 +00:00
Charlie Marsh
22770fb4be
Avoid extra parentheses in `await` expressions ( #7424 )
...
## Summary
This PR aligns the await parenthesizing with the unary case, which is:
if the value is already parenthesized, avoid parenthesizing; otherwise,
only parenthesize if the _value_ needs parenthesizing.
Closes https://github.com/astral-sh/ruff/issues/7420 .
## Test Plan
`cargo test`
No change in similarity.
Before:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
After:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
2023-09-16 13:10:35 -04:00
Charlie Marsh
1880cceac1
Avoid extra parentheses in unary expressions ( #7428 )
...
## Summary
This PR applies a similar fix to unary expressions as in
https://github.com/astral-sh/ruff/pull/7424 . Specifically, we only need
to parenthesize the entire operator if the operand itself doesn't have
parentheses, and requires parentheses.
Closes https://github.com/astral-sh/ruff/issues/7423 .
## Test Plan
`cargo test`
No change in similarity.
Before:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
After:
| project | similarity index | total files | changed files |
|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1632 |
| django | 0.99982 | 2760 | 37 |
| transformers | 0.99957 | 2587 | 399 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99983 | 3496 | 18 |
| warehouse | 0.99923 | 648 | 18 |
| zulip | 0.99962 | 1437 | 22 |
2023-09-16 13:07:38 -04:00
Dhruv Manilawala
0d1fb823d6
[`flake8-logging`] Implement `LOG002`: `invalid-get-logger-argument` ( #7399 )
...
## Summary
This PR implements a new rule for `flake8-logging` plugin that checks
for
`logging.getLogger` calls with either `__file__` or `__cached__` as the
first
argument and generates a suggested fix to use `__name__` instead.
Refer: #7248
## Test Plan
Add test cases and `cargo test`
2023-09-16 12:21:30 -04:00
Micha Reiser
c907317199
Fix build ( #7437 )
2023-09-16 14:50:36 +00:00
Micha Reiser
916dd5b7fa
fix: Use BestFit layout for subscript ( #7409 )
2023-09-16 16:21:45 +02:00
konsti
2cbe1733c8
Use CommentRanges in backwards lexing ( #7360 )
...
## Summary
The tokenizer was split into a forward and a backwards tokenizer. The
backwards tokenizer uses the same names as the forwards ones (e.g.
`next_token`). The backwards tokenizer gets the comment ranges that we
already built to skip comments.
---------
Co-authored-by: Micha Reiser <micha@reiser.io>
2023-09-16 03:21:45 +00:00
Charlie Marsh
1f6e1485f9
Change playground to use `pages deploy` ( #7430 )
...
Fixes a deprecation warning.
2023-09-16 03:11:34 +00:00
Charlie Marsh
9b43162cc4
Move documentation to docs.astral.sh/ruff ( #7419 )
...
## Summary
We're planning to move the documentation from
[https://beta.ruff.rs/docs ](https://beta.ruff.rs/docs ) to
[https://docs.astral.sh/ruff ](https://docs.astral.sh/ruff ), for a few
reasons:
1. We want to remove the `beta` from the domain, as Ruff is no longer
considered beta software.
2. We want to migrate to a structure that could accommodate multiple
future tools living under one domain.
The docs are actually already live at
[https://docs.astral.sh/ruff ](https://docs.astral.sh/ruff ), but later
today, I'll add a permanent redirect from the previous to the new
domain. **All existing links will continue to work, now and in
perpetuity.**
This PR contains the code changes necessary for the updated
documentation. As part of this effort, I moved the playground and
documentation from my personal Cloudflare account to our team Cloudflare
account (hence the new `--project-name` references). After merging, I'll
also update the secrets on this repo.
2023-09-15 22:49:42 -04:00
Charlie Marsh
cc9e84c144
Format trailing operator comments as dangling ( #7427 )
...
## Summary
Given a trailing operator comment in a unary expression, like:
```python
if (
not # comment
a):
...
```
We were attaching these to the operand (`a`), but formatting them in the
unary operator via special handling. Parents shouldn't format the
comments of their children, so this instead attaches them as dangling
comments on the unary expression. (No intended change in formatting.)
2023-09-15 20:34:09 -04:00
Zanie Blue
f4d50a2aec
Fix release validation step ( #7417 )
...
Proof of concept at #7416
Fixes `main` branch check added in #7279 (see
[failure](https://github.com/astral-sh/ruff/actions/runs/6201772425/job/16839150669 ))
Removes the meaningless "SHA consistency" check (since we literally
check out the SHA now)
2023-09-15 20:18:25 +00:00
Zanie Blue
0c030b5bf3
Bump version to 0.0.290 ( #7413 )
...
See also:
- https://github.com/astral-sh/astral-sh/pull/41
- https://github.com/astral-sh/ruff-pre-commit/pull/51
2023-09-15 13:51:46 -05:00