mirror of https://github.com/astral-sh/ruff
Make ruff::rules private
This commit is contained in:
parent
c7f0f3b237
commit
cfa25ea4b0
|
|
@ -13,18 +13,12 @@
|
|||
)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
mod black;
|
||||
mod converter;
|
||||
mod parser;
|
||||
mod plugin;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use black::parse_black_options;
|
||||
use clap::Parser;
|
||||
use configparser::ini::Ini;
|
||||
use plugin::Plugin;
|
||||
use ruff::flake8_to_ruff;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
|
|
@ -42,7 +36,7 @@ struct Cli {
|
|||
pyproject: Option<PathBuf>,
|
||||
/// List of plugins to enable.
|
||||
#[arg(long, value_delimiter = ',')]
|
||||
plugin: Option<Vec<Plugin>>,
|
||||
plugin: Option<Vec<flake8_to_ruff::Plugin>>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
|
|
@ -56,12 +50,12 @@ fn main() -> Result<()> {
|
|||
// Read the pyproject.toml file.
|
||||
let black = cli
|
||||
.pyproject
|
||||
.map(parse_black_options)
|
||||
.map(flake8_to_ruff::parse_black_options)
|
||||
.transpose()?
|
||||
.flatten();
|
||||
|
||||
// Create Ruff's pyproject.toml section.
|
||||
let pyproject = converter::convert(&config, black.as_ref(), cli.plugin)?;
|
||||
let pyproject = flake8_to_ruff::convert(&config, black.as_ref(), cli.plugin)?;
|
||||
println!("{}", toml_edit::easy::to_string_pretty(&pyproject)?);
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use ruff::fs;
|
|||
use ruff::logging::LogLevel;
|
||||
use ruff::registry::{RuleCode, RuleCodePrefix};
|
||||
use ruff::resolver::ConfigProcessor;
|
||||
use ruff::rules::mccabe;
|
||||
use ruff::settings::types::{
|
||||
FilePattern, PatternPrefixPair, PerFileIgnore, PythonVersion, SerializationFormat,
|
||||
};
|
||||
|
|
@ -385,9 +384,7 @@ impl ConfigProcessor for &Overrides {
|
|||
config.line_length = Some(*line_length);
|
||||
}
|
||||
if let Some(max_complexity) = &self.max_complexity {
|
||||
config.mccabe = Some(mccabe::settings::Options {
|
||||
max_complexity: Some(*max_complexity),
|
||||
});
|
||||
config.set_max_complexity(Some(*max_complexity));
|
||||
}
|
||||
if let Some(per_file_ignores) = &self.per_file_ignores {
|
||||
config.per_file_ignores = Some(collect_per_file_ignores(per_file_ignores.clone()));
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use ruff::settings::types::PythonVersion;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::settings::types::PythonVersion;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
pub struct Black {
|
||||
#[serde(alias = "line-length", alias = "line_length")]
|
||||
|
|
@ -2,24 +2,24 @@ use std::collections::{BTreeSet, HashMap};
|
|||
|
||||
use anyhow::Result;
|
||||
use colored::Colorize;
|
||||
use ruff::registry::RuleCodePrefix;
|
||||
use ruff::rules::flake8_pytest_style::types::{
|
||||
|
||||
use super::black::Black;
|
||||
use super::plugin::Plugin;
|
||||
use super::{parser, plugin};
|
||||
use crate::registry::RuleCodePrefix;
|
||||
use crate::rules::flake8_pytest_style::types::{
|
||||
ParametrizeNameType, ParametrizeValuesRowType, ParametrizeValuesType,
|
||||
};
|
||||
use ruff::rules::flake8_quotes::settings::Quote;
|
||||
use ruff::rules::flake8_tidy_imports::settings::Strictness;
|
||||
use ruff::rules::pydocstyle::settings::Convention;
|
||||
use ruff::rules::{
|
||||
use crate::rules::flake8_quotes::settings::Quote;
|
||||
use crate::rules::flake8_tidy_imports::settings::Strictness;
|
||||
use crate::rules::pydocstyle::settings::Convention;
|
||||
use crate::rules::{
|
||||
flake8_annotations, flake8_bugbear, flake8_errmsg, flake8_pytest_style, flake8_quotes,
|
||||
flake8_tidy_imports, mccabe, pep8_naming, pydocstyle,
|
||||
};
|
||||
use ruff::settings::options::Options;
|
||||
use ruff::settings::pyproject::Pyproject;
|
||||
use ruff::warn_user;
|
||||
|
||||
use crate::black::Black;
|
||||
use crate::plugin::Plugin;
|
||||
use crate::{parser, plugin};
|
||||
use crate::settings::options::Options;
|
||||
use crate::settings::pyproject::Pyproject;
|
||||
use crate::warn_user;
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub fn convert(
|
||||
|
|
@ -390,14 +390,14 @@ mod tests {
|
|||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use ruff::registry::RuleCodePrefix;
|
||||
use ruff::rules::pydocstyle::settings::Convention;
|
||||
use ruff::rules::{flake8_quotes, pydocstyle};
|
||||
use ruff::settings::options::Options;
|
||||
use ruff::settings::pyproject::Pyproject;
|
||||
|
||||
use crate::converter::convert;
|
||||
use crate::plugin::Plugin;
|
||||
use super::super::plugin::Plugin;
|
||||
use super::convert;
|
||||
use crate::registry::RuleCodePrefix;
|
||||
use crate::rules::pydocstyle::settings::Convention;
|
||||
use crate::rules::{flake8_quotes, pydocstyle};
|
||||
use crate::settings::options::Options;
|
||||
use crate::settings::pyproject::Pyproject;
|
||||
|
||||
#[test]
|
||||
fn it_converts_empty() -> Result<()> {
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
mod black;
|
||||
mod converter;
|
||||
mod parser;
|
||||
mod plugin;
|
||||
|
||||
pub use black::parse_black_options;
|
||||
pub use converter::convert;
|
||||
pub use plugin::Plugin;
|
||||
|
|
@ -4,11 +4,12 @@ use anyhow::{bail, Result};
|
|||
use colored::Colorize;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use ruff::registry::{RuleCodePrefix, PREFIX_REDIRECTS};
|
||||
use ruff::settings::types::PatternPrefixPair;
|
||||
use ruff::warn_user;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::registry::{RuleCodePrefix, PREFIX_REDIRECTS};
|
||||
use crate::settings::types::PatternPrefixPair;
|
||||
use crate::warn_user;
|
||||
|
||||
static COMMA_SEPARATED_LIST_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").unwrap());
|
||||
|
||||
/// Parse a comma-separated list of `RuleCodePrefix` values (e.g.,
|
||||
|
|
@ -203,10 +204,10 @@ pub fn collect_per_file_ignores(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
use ruff::registry::RuleCodePrefix;
|
||||
use ruff::settings::types::PatternPrefixPair;
|
||||
|
||||
use crate::parser::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings};
|
||||
use super::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings};
|
||||
use crate::registry::RuleCodePrefix;
|
||||
use crate::settings::types::PatternPrefixPair;
|
||||
|
||||
#[test]
|
||||
fn it_parses_prefix_codes() {
|
||||
|
|
@ -3,7 +3,8 @@ use std::fmt;
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use ruff::registry::RuleCodePrefix;
|
||||
|
||||
use crate::registry::RuleCodePrefix;
|
||||
|
||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum Plugin {
|
||||
|
|
@ -298,7 +299,7 @@ pub fn resolve_select(plugins: &[Plugin]) -> BTreeSet<RuleCodePrefix> {
|
|||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::plugin::{infer_plugins_from_options, Plugin};
|
||||
use super::{infer_plugins_from_options, Plugin};
|
||||
|
||||
#[test]
|
||||
fn it_infers_plugins() {
|
||||
|
|
@ -29,6 +29,7 @@ pub mod directives;
|
|||
mod doc_lines;
|
||||
mod docstrings;
|
||||
pub mod fix;
|
||||
pub mod flake8_to_ruff;
|
||||
pub mod fs;
|
||||
mod lex;
|
||||
pub mod linter;
|
||||
|
|
@ -38,7 +39,7 @@ mod noqa;
|
|||
mod python;
|
||||
pub mod registry;
|
||||
pub mod resolver;
|
||||
pub mod rules;
|
||||
mod rules;
|
||||
pub mod rustpython_helpers;
|
||||
pub mod settings;
|
||||
pub mod source_code;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use schemars::JsonSchema;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub enum ParametrizeNameType {
|
||||
#[serde(rename = "csv")]
|
||||
CSV,
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
pub(crate) mod eradicate;
|
||||
pub(crate) mod flake8_2020;
|
||||
pub mod eradicate;
|
||||
pub mod flake8_2020;
|
||||
pub mod flake8_annotations;
|
||||
pub mod flake8_bandit;
|
||||
pub(crate) mod flake8_blind_except;
|
||||
pub mod flake8_blind_except;
|
||||
pub mod flake8_boolean_trap;
|
||||
pub mod flake8_bugbear;
|
||||
pub(crate) mod flake8_builtins;
|
||||
pub(crate) mod flake8_comprehensions;
|
||||
pub(crate) mod flake8_datetimez;
|
||||
pub(crate) mod flake8_debugger;
|
||||
pub mod flake8_builtins;
|
||||
pub mod flake8_comprehensions;
|
||||
pub mod flake8_datetimez;
|
||||
pub mod flake8_debugger;
|
||||
pub mod flake8_errmsg;
|
||||
pub(crate) mod flake8_implicit_str_concat;
|
||||
pub(crate) mod flake8_import_conventions;
|
||||
pub mod flake8_implicit_str_concat;
|
||||
pub mod flake8_import_conventions;
|
||||
pub mod flake8_pie;
|
||||
pub(crate) mod flake8_print;
|
||||
pub mod flake8_print;
|
||||
pub mod flake8_pytest_style;
|
||||
pub mod flake8_quotes;
|
||||
pub(crate) mod flake8_return;
|
||||
pub(crate) mod flake8_simplify;
|
||||
pub mod flake8_return;
|
||||
pub mod flake8_simplify;
|
||||
pub mod flake8_tidy_imports;
|
||||
pub(crate) mod flake8_unused_arguments;
|
||||
pub(crate) mod isort;
|
||||
pub mod flake8_unused_arguments;
|
||||
pub mod isort;
|
||||
pub mod mccabe;
|
||||
pub(crate) mod pandas_vet;
|
||||
pub mod pandas_vet;
|
||||
pub mod pep8_naming;
|
||||
pub(crate) mod pycodestyle;
|
||||
pub mod pycodestyle;
|
||||
pub mod pydocstyle;
|
||||
pub(crate) mod pyflakes;
|
||||
pub(crate) mod pygrep_hooks;
|
||||
pub(crate) mod pylint;
|
||||
pub(crate) mod pyupgrade;
|
||||
pub(crate) mod ruff;
|
||||
pub mod pyflakes;
|
||||
pub mod pygrep_hooks;
|
||||
pub mod pylint;
|
||||
pub mod pyupgrade;
|
||||
pub mod ruff;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub enum Convention {
|
|||
}
|
||||
|
||||
impl Convention {
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
pub fn codes(&self) -> &'static [RuleCodePrefix] {
|
||||
match self {
|
||||
Convention::Google => &[
|
||||
|
|
|
|||
|
|
@ -251,6 +251,12 @@ impl Configuration {
|
|||
pyupgrade: self.pyupgrade.or(config.pyupgrade),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_max_complexity(&mut self, max_complexity: Option<usize>) {
|
||||
let mut mccabe = self.mccabe.take().unwrap_or_default();
|
||||
mccabe.max_complexity = max_complexity;
|
||||
self.mccabe = Some(mccabe);
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a list of source paths, which could include glob patterns, resolve the
|
||||
|
|
|
|||
Loading…
Reference in New Issue