mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 10:01:15 +00:00
Impl Default
for SourceLocation
(#4328)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
fa26860296
commit
badade3ccc
4 changed files with 15 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::message::{Emitter, EmitterContext, Message};
|
use crate::message::{Emitter, EmitterContext, Message};
|
||||||
use crate::registry::AsRule;
|
use crate::registry::AsRule;
|
||||||
use ruff_python_ast::source_code::{OneIndexed, SourceLocation};
|
use ruff_python_ast::source_code::SourceLocation;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
/// Generate error logging commands for Azure Pipelines format.
|
/// Generate error logging commands for Azure Pipelines format.
|
||||||
|
@ -19,10 +19,7 @@ impl Emitter for AzureEmitter {
|
||||||
let location = if context.is_jupyter_notebook(message.filename()) {
|
let location = if context.is_jupyter_notebook(message.filename()) {
|
||||||
// We can't give a reasonable location for the structured formats,
|
// We can't give a reasonable location for the structured formats,
|
||||||
// so we show one that's clearly a fallback
|
// so we show one that's clearly a fallback
|
||||||
SourceLocation {
|
SourceLocation::default()
|
||||||
row: OneIndexed::from_zero_indexed(0),
|
|
||||||
column: OneIndexed::from_zero_indexed(0),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
message.compute_start_location()
|
message.compute_start_location()
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::fs::relativize_path;
|
use crate::fs::relativize_path;
|
||||||
use crate::message::{Emitter, EmitterContext, Message};
|
use crate::message::{Emitter, EmitterContext, Message};
|
||||||
use crate::registry::AsRule;
|
use crate::registry::AsRule;
|
||||||
use ruff_python_ast::source_code::{OneIndexed, SourceLocation};
|
use ruff_python_ast::source_code::SourceLocation;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
/// Generate error workflow command in GitHub Actions format.
|
/// Generate error workflow command in GitHub Actions format.
|
||||||
|
@ -21,10 +21,7 @@ impl Emitter for GithubEmitter {
|
||||||
let location = if context.is_jupyter_notebook(message.filename()) {
|
let location = if context.is_jupyter_notebook(message.filename()) {
|
||||||
// We can't give a reasonable location for the structured formats,
|
// We can't give a reasonable location for the structured formats,
|
||||||
// so we show one that's clearly a fallback
|
// so we show one that's clearly a fallback
|
||||||
SourceLocation {
|
SourceLocation::default()
|
||||||
row: OneIndexed::from_zero_indexed(0),
|
|
||||||
column: OneIndexed::from_zero_indexed(0),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
source_location.clone()
|
source_location.clone()
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::message::{
|
||||||
};
|
};
|
||||||
use crate::registry::AsRule;
|
use crate::registry::AsRule;
|
||||||
use quick_junit::{NonSuccessKind, Report, TestCase, TestCaseStatus, TestSuite};
|
use quick_junit::{NonSuccessKind, Report, TestCase, TestCaseStatus, TestSuite};
|
||||||
use ruff_python_ast::source_code::{OneIndexed, SourceLocation};
|
use ruff_python_ast::source_code::SourceLocation;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -35,10 +35,7 @@ impl Emitter for JunitEmitter {
|
||||||
let location = if context.is_jupyter_notebook(message.filename()) {
|
let location = if context.is_jupyter_notebook(message.filename()) {
|
||||||
// We can't give a reasonable location for the structured formats,
|
// We can't give a reasonable location for the structured formats,
|
||||||
// so we show one that's clearly a fallback
|
// so we show one that's clearly a fallback
|
||||||
SourceLocation {
|
SourceLocation::default()
|
||||||
row: OneIndexed::from_zero_indexed(0),
|
|
||||||
column: OneIndexed::from_zero_indexed(0),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
start_location
|
start_location
|
||||||
};
|
};
|
||||||
|
|
|
@ -225,6 +225,15 @@ pub struct SourceLocation {
|
||||||
pub column: OneIndexed,
|
pub column: OneIndexed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for SourceLocation {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
row: OneIndexed::MIN,
|
||||||
|
column: OneIndexed::MIN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Debug for SourceLocation {
|
impl Debug for SourceLocation {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("SourceLocation")
|
f.debug_struct("SourceLocation")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue