ruff/crates/ruff_dev/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
..
format_dev.rs Alternate quotes for strings inside f-strings in preview (#13860) 2024-10-23 07:57:53 +02:00
generate_all.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
generate_cli_help.rs help: enable auto-wrapping of help output (#9633) 2024-01-24 10:51:07 -05:00
generate_docs.rs DOCS: navigate back to rule overview linter (#13368) 2024-09-16 16:21:26 +00:00
generate_json_schema.rs Move Configuration to ruff_workspace crate (#6920) 2023-08-28 06:21:35 +00:00
generate_knot_schema.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
generate_options.rs Promote lint. settings over top-level settings (#9476) 2024-02-01 13:35:02 -06:00
generate_rules_table.rs Improve Docs: Pylint subcategories' codes (#15909) 2025-02-03 13:53:36 +01:00
main.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
print_ast.rs Pass ParserOptions to the parser (#16220) 2025-02-19 10:50:50 -05:00
print_cst.rs
print_tokens.rs Manual impl of Debug on Token (#11958) 2024-06-22 04:18:24 +00:00
round_trip.rs Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00