Modify public API to return Check rather than Message (#524)

This commit is contained in:
Charlie Marsh 2022-10-31 09:20:14 -04:00 committed by GitHub
parent 97fc281779
commit 78889efa37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,12 +10,12 @@ use settings::pyproject;
use settings::Settings; use settings::Settings;
use crate::autofix::fixer::Mode; use crate::autofix::fixer::Mode;
use crate::checks::Check;
use crate::linter::{check_path, tokenize}; use crate::linter::{check_path, tokenize};
use crate::message::Message;
use crate::settings::configuration::Configuration; use crate::settings::configuration::Configuration;
mod ast; mod ast;
mod autofix; pub mod autofix;
pub mod cache; pub mod cache;
pub mod check_ast; pub mod check_ast;
mod check_lines; mod check_lines;
@ -48,7 +48,7 @@ pub mod source_code_locator;
pub mod visibility; pub mod visibility;
/// Run ruff over Python source code directly. /// Run ruff over Python source code directly.
pub fn check(path: &Path, contents: &str) -> Result<Vec<Message>> { pub fn check(path: &Path, contents: &str) -> Result<Vec<Check>> {
// Find the project root and pyproject.toml. // Find the project root and pyproject.toml.
let project_root = pyproject::find_project_root(&[path.to_path_buf()]); let project_root = pyproject::find_project_root(&[path.to_path_buf()]);
match &project_root { match &project_root {
@ -80,17 +80,5 @@ pub fn check(path: &Path, contents: &str) -> Result<Vec<Message>> {
&Mode::None, &Mode::None,
)?; )?;
// Convert to messages. Ok(checks)
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(),
})
.collect();
Ok(messages)
} }