mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:48 +00:00
Make columns indices 1-based in the text output format (#539)
This commit is contained in:
parent
bad5723d80
commit
c68c6b5424
3 changed files with 17 additions and 17 deletions
|
@ -141,13 +141,7 @@ pub fn lint_stdin(
|
||||||
// Convert to messages.
|
// Convert to messages.
|
||||||
Ok(checks
|
Ok(checks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|check| Message {
|
.map(|check| Message::from_check(path.to_string_lossy().to_string(), check))
|
||||||
kind: check.kind,
|
|
||||||
fixed: check.fix.map(|fix| fix.applied).unwrap_or_default(),
|
|
||||||
location: check.location,
|
|
||||||
end_location: check.end_location,
|
|
||||||
filename: path.to_string_lossy().to_string(),
|
|
||||||
})
|
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,13 +183,7 @@ pub fn lint_path(
|
||||||
// Convert to messages.
|
// Convert to messages.
|
||||||
let messages: Vec<Message> = checks
|
let messages: Vec<Message> = checks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|check| Message {
|
.map(|check| Message::from_check(path.to_string_lossy().to_string(), check))
|
||||||
kind: check.kind,
|
|
||||||
fixed: check.fix.map(|fix| fix.applied).unwrap_or_default(),
|
|
||||||
location: check.location,
|
|
||||||
end_location: check.end_location,
|
|
||||||
filename: path.to_string_lossy().to_string(),
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
cache::set(path, &metadata, settings, autofix, &messages, mode);
|
cache::set(path, &metadata, settings, autofix, &messages, mode);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use colored::Colorize;
|
||||||
use rustpython_parser::ast::Location;
|
use rustpython_parser::ast::Location;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::checks::CheckKind;
|
use crate::checks::{Check, CheckKind};
|
||||||
use crate::fs::relativize_path;
|
use crate::fs::relativize_path;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
@ -18,6 +18,18 @@ pub struct Message {
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Message {
|
||||||
|
pub fn from_check(filename: String, check: Check) -> Self {
|
||||||
|
Self {
|
||||||
|
kind: check.kind,
|
||||||
|
fixed: check.fix.map(|fix| fix.applied).unwrap_or_default(),
|
||||||
|
location: Location::new(check.location.row(), check.location.column() + 1),
|
||||||
|
end_location: Location::new(check.end_location.row(), check.end_location.column() + 1),
|
||||||
|
filename,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Ord for Message {
|
impl Ord for Message {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
(&self.filename, self.location.row(), self.location.column()).cmp(&(
|
(&self.filename, self.location.row(), self.location.column()).cmp(&(
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test_stdin_error() -> Result<()> {
|
||||||
.write_stdin("import os\n")
|
.write_stdin("import os\n")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.failure();
|
||||||
assert!(str::from_utf8(&output.get_output().stdout)?.contains("-:1:0: F401"));
|
assert!(str::from_utf8(&output.get_output().stdout)?.contains("-:1:1: F401"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ fn test_stdin_filename() -> Result<()> {
|
||||||
.write_stdin("import os\n")
|
.write_stdin("import os\n")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.failure();
|
||||||
assert!(str::from_utf8(&output.get_output().stdout)?.contains("F401.py:1:0: F401"));
|
assert!(str::from_utf8(&output.get_output().stdout)?.contains("F401.py:1:1: F401"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue