Commit Graph

482 Commits

Author SHA1 Message Date
Micha Reiser 154439728a
Add `AnyNode` and `AnyNodeRef` unions (#4578) 2023-05-23 08:53:22 +02:00
Micha Reiser daadd24bde
Include decorators in `Function` and `Class` definition ranges (#4467) 2023-05-22 17:50:42 +02:00
Charlie Marsh 19c4b7bee6
Rename ruff_python_semantic's `Context` struct to `SemanticModel` (#4565) 2023-05-22 02:35:03 +00:00
Micha Reiser 2f35099f81
Remove `regex` dependency from `ruff_python_ast` (#4518) 2023-05-19 06:44:18 +00:00
Ville Skyttä 2e2ba2cb16
Avoid some false positives in dunder variable assigments (#4508) 2023-05-19 02:11:20 +00:00
Charlie Marsh e9c6f16c56
Move unparse utility methods onto Generator (#4497) 2023-05-18 15:00:46 +00:00
Charlie Marsh d3b18345c5
Move triple-quoted string detection into `Indexer` method (#4495) 2023-05-18 14:42:05 +00:00
Charlie Marsh 73efbeb581
Invert quote-style when generating code within f-strings (#4487) 2023-05-18 14:33:33 +00:00
Charlie Marsh e8e66f3824
Remove unnecessary path prefixes (#4492) 2023-05-18 10:19:09 -04:00
Charlie Marsh 14c6419bc1
Bring pycodestyle rules into full compatibility (on SciPy) (#4472) 2023-05-17 16:51:55 +00:00
Charlie Marsh d9c3f8e249
Avoid flagging missing whitespace for decorators (#4454) 2023-05-16 13:15:01 -04:00
Charlie Marsh 7e0d018b35
Avoid emitting empty logical lines (#4452) 2023-05-16 16:33:33 +00:00
Jeong, YunWon 4b05ca1198
Specialize ConversionFlag (#4450) 2023-05-16 18:00:13 +02:00
Charlie Marsh f0465bf106
Emit non-logical newlines for "empty" lines (#4444) 2023-05-16 14:58:56 +00:00
Jeong, YunWon badade3ccc
Impl `Default` for `SourceLocation` (#4328)
Co-authored-by: Micha Reiser <micha@reiser.io>
2023-05-16 07:03:43 +00:00
Micha Reiser fa26860296
Refactor range from `Attributed` to `Node`s (#4422) 2023-05-16 06:36:32 +00:00
Jonathan Plasse c10a4535b9
Disallow `unreachable_pub` (#4314) 2023-05-11 18:00:00 -04:00
Jeong, YunWon be6e00ef6e
Re-integrate RustPython parser repository (#4359)
Co-authored-by: Micha Reiser <micha@reiser.io>
2023-05-11 07:47:17 +00:00
Charlie Marsh fd34797d0f
Add a specialized `StatementVisitor` (#4349) 2023-05-10 12:42:20 -04:00
Micha Reiser 99a755f936
Add `schemars` feature (#4305) 2023-05-09 16:15:18 +02:00
Charlie Marsh c1f0661225
Replace `parents` statement stack with a `Nodes` abstraction (#4233) 2023-05-06 16:12:41 +00:00
Micha Reiser e93f378635
Refactor whitespace around operator (#4223) 2023-05-05 09:37:56 +02:00
Jonathan Plasse 8c97e7922b
Fix F811 false positive with match (#4161) 2023-04-30 14:39:45 -04:00
Micha Reiser e04ef42334
Use `memchr` to speedup newline search on x86 (#3985) 2023-04-26 20:15:47 +01:00
Micha Reiser f3e6ddda62
perf(logical-lines): Various small perf improvements (#4022) 2023-04-26 20:10:35 +01:00
Micha Reiser cab65b25da
Replace row/column based `Location` with byte-offsets. (#3931) 2023-04-26 18:11:02 +00:00
Jonathan Plasse df77595426
Move `Truthiness` into `ruff_python_ast` (#4071) 2023-04-24 04:54:31 +00:00
Micha Reiser ba4f4f4672
Upgrade dependencies (#4064) 2023-04-22 18:04:01 +01:00
Charlie Marsh 7fa1da20fb
Support relative imports in `banned-api` enforcement (#4025) 2023-04-19 14:30:13 -04:00
Charlie Marsh eb0dd74040
Avoid adding required imports to stub files (#3940) 2023-04-11 22:31:20 -04:00
Micha Reiser e8aebee3f6
Pretty print `Diagnostic`s in snapshot tests (#3906) 2023-04-11 09:03:00 +00:00
Micha Reiser c33c9dc585
Introduce SourceFile to avoid cloning the message filename (#3904) 2023-04-11 08:28:55 +00:00
Micha Reiser 056c212975
Render code frame with context (#3901) 2023-04-11 10:22:11 +02:00
Micha Reiser 381203c084
Store source code on message (#3897) 2023-04-11 07:57:36 +00:00
Micha Reiser 76c47a9a43
Cheap cloneable LineIndex (#3896) 2023-04-11 07:33:40 +00:00
Evan Rittenhouse abaf0a198d
Ensure that tab characters aren't in multi-line strings before throwing a violation (#3837) 2023-04-06 22:25:40 -04:00
Charlie Marsh d919adc13c
Introduce a `ruff_python_semantic` crate (#3865) 2023-04-04 16:50:47 +00:00
Chris Chan 10504eb9ed
Generate `ImportMap` from module path to imported dependencies (#3243) 2023-04-04 03:31:37 +00:00
Charlie Marsh f4173b2a93
Move shadow tracking into `Scope` directly (#3854) 2023-04-03 15:33:44 -04:00
Charlie Marsh 5625410936
Remove `uses_magic_variable_access` dependence on `Checker` (#3864) 2023-04-03 12:22:06 -04:00
Charlie Marsh 3744e9ab3f
Remove `contains_effect`'s dependency on `Context` (#3855) 2023-04-03 12:08:13 -04:00
Nazia Povey 849091d846
When checking module visibility, don't check entire ancestry (#3835) 2023-04-03 11:38:41 -04:00
Charlie Marsh 25771cd4b9
Use references for `Export` binding type (#3853) 2023-04-03 15:26:42 +00:00
Charlie Marsh 924bebbb4a
Change "indexes" to "indices" in various contexts (#3856) 2023-04-02 23:08:03 +00:00
Charlie Marsh 08e5b3fa61
Make `collect_call_path` return an `Option` (#3849) 2023-04-01 22:29:32 -04:00
Charlie Marsh d822e08111
Move `CallPath` into its own module (#3847) 2023-04-01 11:25:04 -04:00
Charlie Marsh 2f90157ce2
Move logging resolver into `logging.rs` (#3843) 2023-04-01 03:50:44 +00:00
Charlie Marsh 88308ef9cc
Move `Binding` structs out of `scope.rs` (#3842) 2023-03-31 23:49:48 -04:00
Charlie Marsh 6d80c79bac
Combine `operations.rs` and `helpers.rs` (#3841) 2023-04-01 03:40:34 +00:00
Charlie Marsh 2fbc620ad3
Move `__all__` utilities to `all.rs` (#3840) 2023-04-01 03:31:15 +00:00
Charlie Marsh 27e40e9b31
Remove `helpers.rs` dependency on `Binding` (#3839) 2023-04-01 03:19:45 +00:00
Charlie Marsh b6276e2d95
Move f-string identification into rule module (#3838) 2023-03-31 23:10:11 -04:00
Charlie Marsh dfc872c9a0
Track star imports on `Scope` directly (#3822) 2023-03-31 15:01:12 +00:00
Charlie Marsh cf7e1ddd08
Remove some `usize` references (#3819) 2023-03-30 17:35:42 -04:00
Charlie Marsh 01357f62e5
Add import insertion support to autofix capabilities (#3787) 2023-03-30 15:33:46 +00:00
Charlie Marsh f79506f5a4
Move some generic structs out of `isort` (#3788) 2023-03-30 08:58:01 -04:00
Charlie Marsh 8601dcc09b
Add import name resolution to `Context` (#3777) 2023-03-29 21:47:50 +00:00
Micha Reiser 595cd065f3
Reduce explcit clones (#3793) 2023-03-29 15:15:14 +02:00
Charlie Marsh 22d5b0071d
Rename `end_of_statement` to `end_of_last_statement` (#3775) 2023-03-28 12:31:06 -04:00
Micha Reiser f68c26a506
perf(pycodestyle): Initialize Stylist from tokens (#3757) 2023-03-28 11:53:35 +02:00
Micha Reiser 000394f428
perf(pycodestyle): Introduce TokenKind (#3745) 2023-03-28 11:22:39 +02:00
Dhruv Manilawala 63adf9f5e8
Allow aliased `logging` module as a logger candidate (#3718) 2023-03-24 17:19:09 -04:00
Charlie Marsh 0f95056f13
Avoid panics for implicitly concatenated forward references (#3700) 2023-03-23 19:13:50 -04:00
Charlie Marsh 028329854b
Avoid parsing f-strings in type annotations (#3699) 2023-03-23 18:51:44 -04:00
Charlie Marsh ba43d6bd0b
Avoid parsing `ForwardRef` contents as type references (#3698) 2023-03-23 18:44:02 -04:00
Charlie Marsh e8d17d23cb
Expand the scope of useless-expression (B018) (#3455) 2023-03-23 18:33:58 -04:00
Charlie Marsh 189c9d4683
Add dedicated structs for `BindingKind` variants (#3672) 2023-03-22 19:08:48 -04:00
Charlie Marsh 1b3e54231c
Flag, but don't fix, unused imports in `ModuleNotFoundError` blocks (#3658) 2023-03-22 13:03:30 -04:00
Charlie Marsh 3a8e98341b
Enable autofix for annotations within 'simple' string literals (#3657) 2023-03-22 12:45:51 -04:00
Charlie Marsh 7c0f17279c
Flag PEP 585 and PEP 604 violations in quoted annotations (#3593) 2023-03-20 11:15:44 -04:00
Charlie Marsh 4892167217
Avoid panics for implicitly-concatenated docstrings (#3584)
## Summary

In the rare event that a docstring contains an implicit string concatenation, we currently have the potential to panic, because we assume that if a string starts with triple quotes, it _ends_ with triple quotes. But with implicit concatenation, that's not the case: a single `Expr` could start and end with different quote styles, because it can contain multiple string tokens.

Supporting these "properly" is pretty hard. In some cases it's hard to even know what the "right" behavior is. So for now, I'm just detecting and warning, which is better than a panic.

Closes #3543.

Closes #3585.
2023-03-19 14:16:50 -04:00
Micha Reiser dedf4cbdeb
refactor: Move scope and binding types to `scope.rs` (#3573) 2023-03-17 17:31:33 +01:00
Micha Reiser 92179e6369
Scope and Binding IDs (#3572) 2023-03-17 17:12:27 +01:00
Charlie Marsh 373a77e8c2
Avoid C1901 violations within subscripts (#3517) 2023-03-17 02:52:05 +00:00
Micha Reiser 685c242761
refactor(ruff_python_ast): Split `get_argument` (#3478) 2023-03-13 18:18:25 +01:00
Charlie Marsh 3a5fbd6d74
Upgrade RustPython to fix Serde dependency (#3481) 2023-03-13 12:29:31 -04:00
Charlie Marsh c2750a59ab
Implement an iterator for universal newlines (#3454)
# Summary

We need to support CR line endings (as opposed to LF and CRLF line endings, which are already supported). They're rare, but they do appear in Python code, and we tend to panic on any file that uses them.

Our `Locator` abstraction now supports CR line endings. However, Rust's `str#lines` implementation does _not_.

This PR adds a `UniversalNewlineIterator` implementation that respects all of CR, LF, and CRLF line endings, and plugs it into most of the `.lines()` call sites.

As an alternative design, it could be nice if we could leverage `Locator` for this. We've already computed all of the line endings, so we could probably iterate much more efficiently?

# Test Plan

Largely relying on automated testing, however, also ran over some known failure cases, like #3404.
2023-03-13 00:01:29 -04:00
Micha Reiser d2988043af
perf: Optimize UTF8/ASCII byte offset index (#3439) 2023-03-11 13:12:10 +01:00
Charlie Marsh 0a9d259f9c
Remove copied `core` modules from `ruff_python_formatter` (#3371) 2023-03-08 19:03:40 +00:00
Charlie Marsh 130e733023
Implement `From<Located>` for `Range` (#3377) 2023-03-08 18:50:20 +00:00
Charlie Marsh ff2c0dd491
Use shared `leading_quote` implementation in ruff_python_formatter (#3396) 2023-03-08 18:21:59 +00:00
Charlie Marsh bad6bdda1f
Create a `rust_python_ast` crate (#3370)
This PR productionizes @MichaReiser's suggestion in https://github.com/charliermarsh/ruff/issues/1820#issuecomment-1440204423, by creating a separate crate for the `ast` module (`rust_python_ast`). This will enable us to further split up the `ruff` crate, as we'll be able to create (e.g.) separate sub-linter crates that have access to these common AST utilities.

This was mostly a straightforward copy (with adjustments to module imports), as the few dependencies that _did_ require modifications were handled in #3366, #3367, and #3368.
2023-03-07 15:18:40 +00:00