mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Allow diagnostics to generate multi-edit fixes (#3709)
This commit is contained in:
parent
32be63fd1e
commit
e603382cf0
731 changed files with 17319 additions and 13447 deletions
|
@ -17,6 +17,7 @@ use ruff::rules::{
|
|||
use ruff::settings::configuration::Configuration;
|
||||
use ruff::settings::options::Options;
|
||||
use ruff::settings::{defaults, flags, Settings};
|
||||
use ruff_diagnostics::Edit;
|
||||
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
||||
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
@ -35,20 +36,28 @@ export interface Diagnostic {
|
|||
column: number;
|
||||
};
|
||||
fix: {
|
||||
content: string;
|
||||
message: string | null;
|
||||
location: {
|
||||
row: number;
|
||||
column: number;
|
||||
};
|
||||
end_location: {
|
||||
row: number;
|
||||
column: number;
|
||||
};
|
||||
edits: {
|
||||
content: string;
|
||||
location: {
|
||||
row: number;
|
||||
column: number;
|
||||
};
|
||||
end_location: {
|
||||
row: number;
|
||||
column: number;
|
||||
};
|
||||
}[];
|
||||
} | null;
|
||||
};
|
||||
"#;
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedFix {
|
||||
message: Option<String>,
|
||||
edits: Vec<Edit>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedMessage {
|
||||
pub code: String,
|
||||
|
@ -58,14 +67,6 @@ pub struct ExpandedMessage {
|
|||
pub fix: Option<ExpandedFix>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedFix {
|
||||
content: String,
|
||||
message: Option<String>,
|
||||
location: Location,
|
||||
end_location: Location,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn run() {
|
||||
use log::Level;
|
||||
|
@ -204,12 +205,14 @@ pub fn check(contents: &str, options: JsValue) -> Result<JsValue, JsValue> {
|
|||
message: message.kind.body,
|
||||
location: message.location,
|
||||
end_location: message.end_location,
|
||||
fix: message.fix.map(|fix| ExpandedFix {
|
||||
content: fix.content,
|
||||
message: message.kind.suggestion,
|
||||
location: fix.location,
|
||||
end_location: fix.end_location,
|
||||
}),
|
||||
fix: if message.fix.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(ExpandedFix {
|
||||
message: message.kind.suggestion,
|
||||
edits: message.fix.edits().to_vec(),
|
||||
})
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue