Expose autofix mode in public API (#551)

This commit is contained in:
Charlie Marsh 2022-11-02 09:44:46 -04:00 committed by GitHub
parent 017fec2bc5
commit f50ff61056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -6,6 +6,8 @@ use rustpython_parser::ast::Location;
use crate::autofix::{Fix, Patch};
use crate::checks::Check;
// TODO(charlie): The model here is awkward because `Apply` is only relevant at
// higher levels in the execution flow.
#[derive(Hash)]
pub enum Mode {
Generate,

View File

@ -45,8 +45,8 @@ pub mod settings;
pub mod source_code_locator;
pub mod visibility;
/// Run ruff over Python source code directly.
pub fn check(path: &Path, contents: &str) -> Result<Vec<Check>> {
/// Run Ruff over Python source code directly.
pub fn check(path: &Path, contents: &str, autofix: bool) -> Result<Vec<Check>> {
// Find the project root and pyproject.toml.
let project_root = pyproject::find_project_root(&[path.to_path_buf()]);
match &project_root {
@ -75,7 +75,7 @@ pub fn check(path: &Path, contents: &str) -> Result<Vec<Check>> {
tokens,
&noqa_line_for,
&settings,
&Mode::None,
&if autofix { Mode::Generate } else { Mode::None },
)?;
Ok(checks)