mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
Implement configuration options for pep8-naming (#505)
This commit is contained in:
@@ -8,9 +8,9 @@ use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::checks_gen::CheckCodePrefix;
|
||||
use crate::flake8_quotes;
|
||||
use crate::settings::pyproject::load_options;
|
||||
use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion};
|
||||
use crate::{flake8_quotes, pep8_naming};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Configuration {
|
||||
@@ -26,6 +26,7 @@ pub struct Configuration {
|
||||
pub target_version: PythonVersion,
|
||||
// Plugins
|
||||
pub flake8_quotes: flake8_quotes::settings::Settings,
|
||||
pub pep8_naming: pep8_naming::settings::Settings,
|
||||
}
|
||||
|
||||
static DEFAULT_EXCLUDE: Lazy<Vec<FilePattern>> = Lazy::new(|| {
|
||||
@@ -98,7 +99,11 @@ impl Configuration {
|
||||
// Plugins
|
||||
flake8_quotes: options
|
||||
.flake8_quotes
|
||||
.map(flake8_quotes::settings::Settings::from_config)
|
||||
.map(flake8_quotes::settings::Settings::from_options)
|
||||
.unwrap_or_default(),
|
||||
pep8_naming: options
|
||||
.pep8_naming
|
||||
.map(pep8_naming::settings::Settings::from_options)
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ use regex::Regex;
|
||||
|
||||
use crate::checks::CheckCode;
|
||||
use crate::checks_gen::{CheckCodePrefix, PrefixSpecificity};
|
||||
use crate::flake8_quotes;
|
||||
use crate::settings::configuration::Configuration;
|
||||
use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion};
|
||||
use crate::{flake8_quotes, pep8_naming};
|
||||
|
||||
pub mod configuration;
|
||||
pub mod options;
|
||||
@@ -29,6 +29,7 @@ pub struct Settings {
|
||||
pub target_version: PythonVersion,
|
||||
// Plugins
|
||||
pub flake8_quotes: flake8_quotes::settings::Settings,
|
||||
pub pep8_naming: pep8_naming::settings::Settings,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
@@ -45,6 +46,7 @@ impl Settings {
|
||||
extend_exclude: config.extend_exclude,
|
||||
flake8_quotes: config.flake8_quotes,
|
||||
line_length: config.line_length,
|
||||
pep8_naming: config.pep8_naming,
|
||||
per_file_ignores: config.per_file_ignores,
|
||||
target_version: config.target_version,
|
||||
}
|
||||
@@ -60,6 +62,7 @@ impl Settings {
|
||||
per_file_ignores: vec![],
|
||||
target_version: PythonVersion::Py310,
|
||||
flake8_quotes: Default::default(),
|
||||
pep8_naming: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +76,7 @@ impl Settings {
|
||||
per_file_ignores: vec![],
|
||||
target_version: PythonVersion::Py310,
|
||||
flake8_quotes: Default::default(),
|
||||
pep8_naming: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::checks_gen::CheckCodePrefix;
|
||||
use crate::flake8_quotes;
|
||||
use crate::settings::types::{PythonVersion, StrCheckCodePair};
|
||||
use crate::{flake8_quotes, pep8_naming};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Deserialize, Default)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
@@ -24,5 +24,7 @@ pub struct Options {
|
||||
pub per_file_ignores: Vec<StrCheckCodePair>,
|
||||
pub dummy_variable_rgx: Option<String>,
|
||||
pub target_version: Option<PythonVersion>,
|
||||
// Plugins
|
||||
pub flake8_quotes: Option<flake8_quotes::settings::Options>,
|
||||
pub pep8_naming: Option<pep8_naming::settings::Options>,
|
||||
}
|
||||
|
||||
@@ -94,12 +94,12 @@ mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::checks_gen::CheckCodePrefix;
|
||||
use crate::flake8_quotes;
|
||||
use crate::flake8_quotes::settings::Quote;
|
||||
use crate::settings::pyproject::{
|
||||
find_project_root, find_pyproject_toml, parse_pyproject_toml, Options, Pyproject, Tools,
|
||||
};
|
||||
use crate::settings::types::StrCheckCodePair;
|
||||
use crate::{flake8_quotes, pep8_naming};
|
||||
|
||||
#[test]
|
||||
fn deserialize() -> Result<()> {
|
||||
@@ -133,7 +133,8 @@ mod tests {
|
||||
per_file_ignores: vec![],
|
||||
dummy_variable_rgx: None,
|
||||
target_version: None,
|
||||
flake8_quotes: None
|
||||
flake8_quotes: None,
|
||||
pep8_naming: None,
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -159,7 +160,8 @@ line-length = 79
|
||||
per_file_ignores: vec![],
|
||||
dummy_variable_rgx: None,
|
||||
target_version: None,
|
||||
flake8_quotes: None
|
||||
flake8_quotes: None,
|
||||
pep8_naming: None,
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -185,7 +187,8 @@ exclude = ["foo.py"]
|
||||
per_file_ignores: vec![],
|
||||
dummy_variable_rgx: None,
|
||||
target_version: None,
|
||||
flake8_quotes: None
|
||||
flake8_quotes: None,
|
||||
pep8_naming: None,
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -211,7 +214,8 @@ select = ["E501"]
|
||||
per_file_ignores: vec![],
|
||||
dummy_variable_rgx: None,
|
||||
target_version: None,
|
||||
flake8_quotes: None
|
||||
flake8_quotes: None,
|
||||
pep8_naming: None,
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -238,7 +242,8 @@ ignore = ["E501"]
|
||||
per_file_ignores: vec![],
|
||||
dummy_variable_rgx: None,
|
||||
target_version: None,
|
||||
flake8_quotes: None
|
||||
flake8_quotes: None,
|
||||
pep8_naming: None,
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -316,7 +321,25 @@ other-attribute = 1
|
||||
multiline_quotes: Some(Quote::Double),
|
||||
docstring_quotes: Some(Quote::Double),
|
||||
avoid_escape: Some(true),
|
||||
})
|
||||
}),
|
||||
pep8_naming: Some(pep8_naming::settings::Options {
|
||||
ignore_names: Some(vec![
|
||||
"setUp".to_string(),
|
||||
"tearDown".to_string(),
|
||||
"setUpClass".to_string(),
|
||||
"tearDownClass".to_string(),
|
||||
"setUpModule".to_string(),
|
||||
"tearDownModule".to_string(),
|
||||
"asyncSetUp".to_string(),
|
||||
"asyncTearDown".to_string(),
|
||||
"setUpTestData".to_string(),
|
||||
"failureException".to_string(),
|
||||
"longMessage".to_string(),
|
||||
"maxDiff".to_string(),
|
||||
]),
|
||||
classmethod_decorators: Some(vec!["classmethod".to_string()]),
|
||||
staticmethod_decorators: Some(vec!["staticmethod".to_string()]),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use regex::Regex;
|
||||
|
||||
use crate::checks_gen::CheckCodePrefix;
|
||||
use crate::settings::types::{FilePattern, PerFileIgnore, PythonVersion};
|
||||
use crate::{flake8_quotes, Configuration};
|
||||
use crate::{flake8_quotes, pep8_naming, Configuration};
|
||||
|
||||
/// Struct to render user-facing exclusion patterns.
|
||||
#[derive(Debug)]
|
||||
@@ -46,6 +46,7 @@ pub struct UserConfiguration {
|
||||
pub target_version: PythonVersion,
|
||||
// Plugins
|
||||
pub flake8_quotes: flake8_quotes::settings::Settings,
|
||||
pub pep8_naming: pep8_naming::settings::Settings,
|
||||
// Non-settings exposed to the user
|
||||
pub project_root: Option<PathBuf>,
|
||||
pub pyproject: Option<PathBuf>,
|
||||
@@ -53,30 +54,31 @@ pub struct UserConfiguration {
|
||||
|
||||
impl UserConfiguration {
|
||||
pub fn from_configuration(
|
||||
settings: Configuration,
|
||||
configuration: Configuration,
|
||||
project_root: Option<PathBuf>,
|
||||
pyproject: Option<PathBuf>,
|
||||
) -> Self {
|
||||
Self {
|
||||
dummy_variable_rgx: settings.dummy_variable_rgx,
|
||||
exclude: settings
|
||||
dummy_variable_rgx: configuration.dummy_variable_rgx,
|
||||
exclude: configuration
|
||||
.exclude
|
||||
.into_iter()
|
||||
.map(Exclusion::from_file_pattern)
|
||||
.collect(),
|
||||
extend_exclude: settings
|
||||
extend_exclude: configuration
|
||||
.extend_exclude
|
||||
.into_iter()
|
||||
.map(Exclusion::from_file_pattern)
|
||||
.collect(),
|
||||
extend_ignore: settings.extend_ignore,
|
||||
extend_select: settings.extend_select,
|
||||
ignore: settings.ignore,
|
||||
line_length: settings.line_length,
|
||||
per_file_ignores: settings.per_file_ignores,
|
||||
select: settings.select,
|
||||
target_version: settings.target_version,
|
||||
flake8_quotes: settings.flake8_quotes,
|
||||
extend_ignore: configuration.extend_ignore,
|
||||
extend_select: configuration.extend_select,
|
||||
ignore: configuration.ignore,
|
||||
line_length: configuration.line_length,
|
||||
per_file_ignores: configuration.per_file_ignores,
|
||||
select: configuration.select,
|
||||
target_version: configuration.target_version,
|
||||
flake8_quotes: configuration.flake8_quotes,
|
||||
pep8_naming: configuration.pep8_naming,
|
||||
project_root,
|
||||
pyproject,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user