From badade3ccc2c1fcff4313d16a2f9309cdb11a796 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Tue, 16 May 2023 16:03:43 +0900 Subject: [PATCH] Impl `Default` for `SourceLocation` (#4328) Co-authored-by: Micha Reiser --- crates/ruff/src/message/azure.rs | 7 ++----- crates/ruff/src/message/github.rs | 7 ++----- crates/ruff/src/message/junit.rs | 7 ++----- crates/ruff_python_ast/src/source_code/mod.rs | 9 +++++++++ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/ruff/src/message/azure.rs b/crates/ruff/src/message/azure.rs index f29a89ce9c..2f2fd019db 100644 --- a/crates/ruff/src/message/azure.rs +++ b/crates/ruff/src/message/azure.rs @@ -1,6 +1,6 @@ use crate::message::{Emitter, EmitterContext, Message}; use crate::registry::AsRule; -use ruff_python_ast::source_code::{OneIndexed, SourceLocation}; +use ruff_python_ast::source_code::SourceLocation; use std::io::Write; /// 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()) { // We can't give a reasonable location for the structured formats, // so we show one that's clearly a fallback - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(0), - } + SourceLocation::default() } else { message.compute_start_location() }; diff --git a/crates/ruff/src/message/github.rs b/crates/ruff/src/message/github.rs index 5b3552473d..ad7b064f27 100644 --- a/crates/ruff/src/message/github.rs +++ b/crates/ruff/src/message/github.rs @@ -1,7 +1,7 @@ use crate::fs::relativize_path; use crate::message::{Emitter, EmitterContext, Message}; use crate::registry::AsRule; -use ruff_python_ast::source_code::{OneIndexed, SourceLocation}; +use ruff_python_ast::source_code::SourceLocation; use std::io::Write; /// 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()) { // We can't give a reasonable location for the structured formats, // so we show one that's clearly a fallback - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(0), - } + SourceLocation::default() } else { source_location.clone() }; diff --git a/crates/ruff/src/message/junit.rs b/crates/ruff/src/message/junit.rs index 2ed8e6dd7f..745e6c6f06 100644 --- a/crates/ruff/src/message/junit.rs +++ b/crates/ruff/src/message/junit.rs @@ -3,7 +3,7 @@ use crate::message::{ }; use crate::registry::AsRule; 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::path::Path; @@ -35,10 +35,7 @@ impl Emitter for JunitEmitter { let location = if context.is_jupyter_notebook(message.filename()) { // We can't give a reasonable location for the structured formats, // so we show one that's clearly a fallback - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(0), - } + SourceLocation::default() } else { start_location }; diff --git a/crates/ruff_python_ast/src/source_code/mod.rs b/crates/ruff_python_ast/src/source_code/mod.rs index 591162f491..3a33274137 100644 --- a/crates/ruff_python_ast/src/source_code/mod.rs +++ b/crates/ruff_python_ast/src/source_code/mod.rs @@ -225,6 +225,15 @@ pub struct SourceLocation { pub column: OneIndexed, } +impl Default for SourceLocation { + fn default() -> Self { + Self { + row: OneIndexed::MIN, + column: OneIndexed::MIN, + } + } +} + impl Debug for SourceLocation { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_struct("SourceLocation")