mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
Remove public Rust API (#2709)
This commit is contained in:
parent
9a018c1650
commit
ac6c3affdd
3 changed files with 16 additions and 78 deletions
|
@ -1,5 +1,13 @@
|
||||||
# Breaking Changes
|
# Breaking Changes
|
||||||
|
|
||||||
|
## 0.0.245
|
||||||
|
|
||||||
|
### Ruff's public `check` method was removed ([#2709](https://github.com/charliermarsh/ruff/pull/2709))
|
||||||
|
|
||||||
|
Previously, Ruff exposed a `check` method as a public Rust API. This method was used by few,
|
||||||
|
if any clients, and was not well documented or supported. As such, it has been removed, with
|
||||||
|
the intention of adding a stable public API in the future.
|
||||||
|
|
||||||
## 0.0.238
|
## 0.0.238
|
||||||
|
|
||||||
### `select`, `extend-select`, `ignore`, and `extend-ignore` have new semantics ([#2312](https://github.com/charliermarsh/ruff/pull/2312))
|
### `select`, `extend-select`, `ignore`, and `extend-ignore` have new semantics ([#2312](https://github.com/charliermarsh/ruff/pull/2312))
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
//!
|
//!
|
||||||
//! [Ruff]: https://github.com/charliermarsh/ruff
|
//! [Ruff]: https://github.com/charliermarsh/ruff
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
pub use rule_selector::RuleSelector;
|
||||||
|
pub use rules::pycodestyle::rules::IOError;
|
||||||
|
pub use violation::{AutofixKind, Availability as AutofixAvailability};
|
||||||
|
|
||||||
mod assert_yaml_snapshot;
|
mod assert_yaml_snapshot;
|
||||||
mod ast;
|
mod ast;
|
||||||
mod autofix;
|
mod autofix;
|
||||||
|
@ -34,20 +39,12 @@ mod vendor;
|
||||||
mod violation;
|
mod violation;
|
||||||
mod visibility;
|
mod visibility;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
pub use rule_selector::RuleSelector;
|
|
||||||
pub use rules::pycodestyle::rules::IOError;
|
|
||||||
pub use violation::{AutofixKind, Availability as AutofixAvailability};
|
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(not(target_family = "wasm"))] {
|
if #[cfg(target_family = "wasm")] {
|
||||||
pub mod packaging;
|
|
||||||
|
|
||||||
mod lib_native;
|
|
||||||
pub use lib_native::check;
|
|
||||||
} else {
|
|
||||||
mod lib_wasm;
|
mod lib_wasm;
|
||||||
pub use lib_wasm::check;
|
pub use lib_wasm::check;
|
||||||
|
} else {
|
||||||
|
pub mod packaging;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use path_absolutize::path_dedot;
|
|
||||||
use rustpython_parser::lexer::LexResult;
|
|
||||||
|
|
||||||
use crate::linter::check_path;
|
|
||||||
use crate::registry::Diagnostic;
|
|
||||||
use crate::resolver::Relativity;
|
|
||||||
use crate::rustpython_helpers::tokenize;
|
|
||||||
use crate::settings::configuration::Configuration;
|
|
||||||
use crate::settings::{flags, pyproject, Settings};
|
|
||||||
use crate::source_code::{Indexer, Locator, Stylist};
|
|
||||||
use crate::{directives, packaging, resolver};
|
|
||||||
|
|
||||||
/// Load the relevant `Settings` for a given `Path`.
|
|
||||||
fn resolve(path: &Path) -> Result<Settings> {
|
|
||||||
if let Some(pyproject) = pyproject::find_settings_toml(path)? {
|
|
||||||
// First priority: `pyproject.toml` in the current `Path`.
|
|
||||||
Ok(resolver::resolve_settings(&pyproject, &Relativity::Parent)?.lib)
|
|
||||||
} else if let Some(pyproject) = pyproject::find_user_settings_toml() {
|
|
||||||
// Second priority: user-specific `pyproject.toml`.
|
|
||||||
Ok(resolver::resolve_settings(&pyproject, &Relativity::Cwd)?.lib)
|
|
||||||
} else {
|
|
||||||
// Fallback: default settings.
|
|
||||||
Settings::from_configuration(Configuration::default(), &path_dedot::CWD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run Ruff over Python source code directly.
|
|
||||||
pub fn check(path: &Path, contents: &str, autofix: bool) -> Result<Vec<Diagnostic>> {
|
|
||||||
// Load the relevant `Settings` for the given `Path`.
|
|
||||||
let settings = resolve(path)?;
|
|
||||||
|
|
||||||
// Tokenize once.
|
|
||||||
let tokens: Vec<LexResult> = tokenize(contents);
|
|
||||||
|
|
||||||
// Map row and column locations to byte slices (lazily).
|
|
||||||
let locator = Locator::new(contents);
|
|
||||||
|
|
||||||
// Detect the current code style (lazily).
|
|
||||||
let stylist = Stylist::from_contents(contents, &locator);
|
|
||||||
|
|
||||||
// Extra indices from the code.
|
|
||||||
let indexer: Indexer = tokens.as_slice().into();
|
|
||||||
|
|
||||||
// Extract the `# noqa` and `# isort: skip` directives from the source.
|
|
||||||
let directives =
|
|
||||||
directives::extract_directives(&tokens, directives::Flags::from_settings(&settings));
|
|
||||||
|
|
||||||
// Generate diagnostics.
|
|
||||||
let result = check_path(
|
|
||||||
path,
|
|
||||||
packaging::detect_package_root(path, &settings.namespace_packages),
|
|
||||||
contents,
|
|
||||||
tokens,
|
|
||||||
&locator,
|
|
||||||
&stylist,
|
|
||||||
&indexer,
|
|
||||||
&directives,
|
|
||||||
&settings,
|
|
||||||
autofix.into(),
|
|
||||||
flags::Noqa::Enabled,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(result.data)
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue