Make columns indices 1-based in the text output format (#539)

This commit is contained in:
fsouza 2022-11-01 19:06:08 -04:00 committed by GitHub
parent bad5723d80
commit c68c6b5424
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 17 deletions

View file

@ -141,13 +141,7 @@ pub fn lint_stdin(
// Convert to messages.
Ok(checks
.into_iter()
.map(|check| Message {
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(),
})
.map(|check| Message::from_check(path.to_string_lossy().to_string(), check))
.collect())
}
@ -189,13 +183,7 @@ pub fn lint_path(
// Convert to messages.
let messages: Vec<Message> = checks
.into_iter()
.map(|check| Message {
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(),
})
.map(|check| Message::from_check(path.to_string_lossy().to_string(), check))
.collect();
#[cfg(not(target_family = "wasm"))]
cache::set(path, &metadata, settings, autofix, &messages, mode);

View file

@ -6,7 +6,7 @@ use colored::Colorize;
use rustpython_parser::ast::Location;
use serde::{Deserialize, Serialize};
use crate::checks::CheckKind;
use crate::checks::{Check, CheckKind};
use crate::fs::relativize_path;
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
@ -18,6 +18,18 @@ pub struct Message {
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 {
fn cmp(&self, other: &Self) -> Ordering {
(&self.filename, self.location.row(), self.location.column()).cmp(&(

View file

@ -18,7 +18,7 @@ fn test_stdin_error() -> Result<()> {
.write_stdin("import os\n")
.assert()
.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(())
}
@ -30,7 +30,7 @@ fn test_stdin_filename() -> Result<()> {
.write_stdin("import os\n")
.assert()
.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(())
}