ruff/crates/ruff_python_formatter/src
Brent Westbrook 97d0659ce3
Pass `ParserOptions` to the parser (#16220)
## Summary

This is part of the preparation for detecting syntax errors in the
parser from https://github.com/astral-sh/ruff/pull/16090/. As suggested
in [this
comment](https://github.com/astral-sh/ruff/pull/16090/#discussion_r1953084509),
I started working on a `ParseOptions` struct that could be stored in the
parser. For this initial refactor, I only made it hold the existing
`Mode` option, but for syntax errors, we will also need it to have a
`PythonVersion`. For that use case, I'm picturing something like a
`ParseOptions::with_python_version` method, so you can extend the
current calls to something like

```rust
ParseOptions::from(mode).with_python_version(settings.target_version)
```

But I thought it was worth adding `ParseOptions` alone without changing
any other behavior first.

Most of the diff is just updating call sites taking `Mode` to take
`ParseOptions::from(Mode)` or those taking `PySourceType`s to take
`ParseOptions::from(PySourceType)`. The interesting changes are in the
new `parser/options.rs` file and smaller parts of `parser/mod.rs` and
`ruff_python_parser/src/lib.rs`.

## Test Plan

Existing tests, this should not change any behavior.
2025-02-19 10:50:50 -05:00
..
comments Pass `ParserOptions` to the parser (#16220) 2025-02-19 10:50:50 -05:00
expression Fix unstable formatting of trailing end-of-line comments of parenthesized attribute values (#16187) 2025-02-18 08:43:51 +01:00
module Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
other Remove `AstNode` and `AnyNode` (#15479) 2025-01-17 17:11:00 -05:00
pattern Remove `AstNode` and `AnyNode` (#15479) 2025-01-17 17:11:00 -05:00
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
statement Use `ast::PythonVersion` internally in the formatter and linter (#16170) 2025-02-18 12:03:13 -05:00
string Pass `ParserOptions` to the parser (#16220) 2025-02-19 10:50:50 -05:00
type_param Remove `AstNode` and `AnyNode` (#15479) 2025-01-17 17:11:00 -05:00
builders.rs Fix unstable f-string formatting for expressions containing a trailing comma (#15545) 2025-01-17 10:08:09 +01:00
cli.rs Pass `ParserOptions` to the parser (#16220) 2025-02-19 10:50:50 -05:00
context.rs Fix unstable f-string formatting for expressions containing a trailing comma (#15545) 2025-01-17 10:08:09 +01:00
generated.rs Auto-generate AST boilerplate (#15544) 2025-01-17 14:23:02 -05:00
lib.rs Pass `ParserOptions` to the parser (#16220) 2025-02-19 10:50:50 -05:00
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Use `ast::PythonVersion` internally in the formatter and linter (#16170) 2025-02-18 12:03:13 -05:00
prelude.rs Accept any `Into<AnyNodeRef>` as `Comments` arguments (#5205) 2023-06-20 16:49:21 +00:00
preview.rs Ruff 2025 style guide (#13906) 2025-01-09 10:20:06 +01:00
range.rs Pass `ParserOptions` to the parser (#16220) 2025-02-19 10:50:50 -05:00
shared_traits.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
verbatim.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00