mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-03 05:13:00 +00:00
Refactor diagnostic start|end location helpers (#20309)
- Renames functions to drop `expect_` from names. - Make functions return `Option<LineColumn>` to appropriately signal when range is not available. - Update existing consumers to use `unwrap_or_default()`. Uncertain if there are better fallback behaviors for individual consumers.
This commit is contained in:
parent
bf66178959
commit
d7524ea6d4
4 changed files with 23 additions and 21 deletions
|
|
@ -19,7 +19,7 @@ impl Emitter for GithubEmitter {
|
|||
context: &EmitterContext,
|
||||
) -> anyhow::Result<()> {
|
||||
for diagnostic in diagnostics {
|
||||
let source_location = diagnostic.expect_ruff_start_location();
|
||||
let source_location = diagnostic.ruff_start_location().unwrap_or_default();
|
||||
let filename = diagnostic.expect_ruff_filename();
|
||||
let location = if context.is_notebook(&filename) {
|
||||
// We can't give a reasonable location for the structured formats,
|
||||
|
|
@ -29,7 +29,7 @@ impl Emitter for GithubEmitter {
|
|||
source_location
|
||||
};
|
||||
|
||||
let end_location = diagnostic.expect_ruff_end_location();
|
||||
let end_location = diagnostic.ruff_end_location().unwrap_or_default();
|
||||
|
||||
write!(
|
||||
writer,
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ fn group_diagnostics_by_filename(
|
|||
.or_insert_with(Vec::new)
|
||||
.push(MessageWithLocation {
|
||||
message: diagnostic,
|
||||
start_location: diagnostic.expect_ruff_start_location(),
|
||||
start_location: diagnostic.ruff_start_location().unwrap_or_default(),
|
||||
});
|
||||
}
|
||||
grouped_messages
|
||||
|
|
|
|||
|
|
@ -158,8 +158,8 @@ struct SarifResult<'a> {
|
|||
impl<'a> SarifResult<'a> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn from_message(message: &'a Diagnostic) -> Result<Self> {
|
||||
let start_location = message.expect_ruff_start_location();
|
||||
let end_location = message.expect_ruff_end_location();
|
||||
let start_location = message.ruff_start_location().unwrap_or_default();
|
||||
let end_location = message.ruff_end_location().unwrap_or_default();
|
||||
let path = normalize_path(&*message.expect_ruff_filename());
|
||||
Ok(Self {
|
||||
code: RuleCode::from(message),
|
||||
|
|
@ -178,8 +178,8 @@ impl<'a> SarifResult<'a> {
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
#[expect(clippy::unnecessary_wraps)]
|
||||
fn from_message(message: &'a Diagnostic) -> Result<Self> {
|
||||
let start_location = message.expect_ruff_start_location();
|
||||
let end_location = message.expect_ruff_end_location();
|
||||
let start_location = message.ruff_start_location().unwrap_or_default();
|
||||
let end_location = message.ruff_end_location().unwrap_or_default();
|
||||
let path = normalize_path(&*message.expect_ruff_filename());
|
||||
Ok(Self {
|
||||
code: RuleCode::from(message),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue