mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:26 +00:00

## Stack Summary This stack splits `Settings` into `FormatterSettings` and `LinterSettings` and moves it into `ruff_workspace`. This change is necessary to add the `FormatterSettings` to `Settings` without adding `ruff_python_formatter` as a dependency to `ruff_linter` (and the linter should not contain the formatter settings). A quick overview of our settings struct at play: * `Options`: 1:1 representation of the options in the `pyproject.toml` or `ruff.toml`. Used for deserialization. * `Configuration`: Resolved `Options`, potentially merged from multiple configurations (when using `extend`). The representation is very close if not identical to the `Options`. * `Settings`: The resolved configuration that uses a data format optimized for reading. Optional fields are initialized with their default values. Initialized by `Configuration::into_settings` . The goal of this stack is to split `Settings` into tool-specific resolved `Settings` that are independent of each other. This comes at the advantage that the individual crates don't need to know anything about the other tools. The downside is that information gets duplicated between `Settings`. Right now the duplication is minimal (`line-length`, `tab-width`) but we may need to come up with a solution if more expensive data needs sharing. This stack focuses on `Settings`. Splitting `Configuration` into some smaller structs is something I'll follow up on later. ## PR Summary This PR extracts the linter-specific settings into a new `LinterSettings` struct and adds it as a `linter` field to the `Settings` struct. This is in preparation for moving `Settings` from `ruff_linter` to `ruff_workspace` ## Test Plan `cargo test`
29 lines
1,015 B
Rust
29 lines
1,015 B
Rust
//! Fuzzer harness which actively tries to find testcases that cause Ruff to introduce errors into
|
|
//! the resulting file.
|
|
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::{fuzz_target, Corpus};
|
|
use ruff_linter::settings::LinterSettings;
|
|
use std::sync::OnceLock;
|
|
|
|
static SETTINGS: OnceLock<LinterSettings> = OnceLock::new();
|
|
|
|
fn do_fuzz(case: &[u8]) -> Corpus {
|
|
// throw away inputs which aren't utf-8
|
|
let Ok(code) = std::str::from_utf8(case) else {
|
|
return Corpus::Reject;
|
|
};
|
|
|
|
// the settings are immutable to test_snippet, so we avoid re-initialising here
|
|
let settings = SETTINGS.get_or_init(LinterSettings::default);
|
|
ruff_linter::test::set_max_iterations(usize::MAX);
|
|
|
|
// unlike in the test framework, where the number of iterations is well-defined, we are only
|
|
// looking for situations where a fix is bad; thus, we set the iterations to "infinite"
|
|
let _ = ruff_linter::test::test_snippet(code, settings);
|
|
|
|
Corpus::Keep
|
|
}
|
|
|
|
fuzz_target!(|case: &[u8]| -> Corpus { do_fuzz(case) });
|