mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Introduce LinterSettings
## Stack Summary This stack splits `Settings` into `FormatterSettings` and `LinterSettings` and moves it into `ruff_workspace`. This change is necessary to add the `FormatterSettings` to `Settings` without adding `ruff_python_formatter` as a dependency to `ruff_linter` (and the linter should not contain the formatter settings). A quick overview of our settings struct at play: * `Options`: 1:1 representation of the options in the `pyproject.toml` or `ruff.toml`. Used for deserialization. * `Configuration`: Resolved `Options`, potentially merged from multiple configurations (when using `extend`). The representation is very close if not identical to the `Options`. * `Settings`: The resolved configuration that uses a data format optimized for reading. Optional fields are initialized with their default values. Initialized by `Configuration::into_settings` . The goal of this stack is to split `Settings` into tool-specific resolved `Settings` that are independent of each other. This comes at the advantage that the individual crates don't need to know anything about the other tools. The downside is that information gets duplicated between `Settings`. Right now the duplication is minimal (`line-length`, `tab-width`) but we may need to come up with a solution if more expensive data needs sharing. This stack focuses on `Settings`. Splitting `Configuration` into some smaller structs is something I'll follow up on later. ## PR Summary This PR extracts the linter-specific settings into a new `LinterSettings` struct and adds it as a `linter` field to the `Settings` struct. This is in preparation for moving `Settings` from `ruff_linter` to `ruff_workspace` ## Test Plan `cargo test`
This commit is contained in:
parent
222f1c37b8
commit
b34278e0cd
101 changed files with 753 additions and 716 deletions
|
@ -4,7 +4,7 @@ use ruff_benchmark::criterion::{
|
|||
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
|
||||
use ruff_linter::linter::lint_only;
|
||||
use ruff_linter::settings::rule_table::RuleTable;
|
||||
use ruff_linter::settings::{flags, Settings};
|
||||
use ruff_linter::settings::{flags, LinterSettings};
|
||||
use ruff_linter::source_kind::SourceKind;
|
||||
use ruff_linter::{registry::Rule, RuleSelector};
|
||||
use ruff_python_ast::PySourceType;
|
||||
|
@ -41,7 +41,7 @@ fn create_test_cases() -> Result<Vec<TestCase>, TestFileDownloadError> {
|
|||
])
|
||||
}
|
||||
|
||||
fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) {
|
||||
fn benchmark_linter(mut group: BenchmarkGroup, settings: &LinterSettings) {
|
||||
let test_cases = create_test_cases().unwrap();
|
||||
|
||||
for case in test_cases {
|
||||
|
@ -75,7 +75,7 @@ fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) {
|
|||
|
||||
fn benchmark_default_rules(criterion: &mut Criterion) {
|
||||
let group = criterion.benchmark_group("linter/default-rules");
|
||||
benchmark_linter(group, &Settings::default());
|
||||
benchmark_linter(group, &LinterSettings::default());
|
||||
}
|
||||
|
||||
fn benchmark_all_rules(criterion: &mut Criterion) {
|
||||
|
@ -85,9 +85,9 @@ fn benchmark_all_rules(criterion: &mut Criterion) {
|
|||
rules.disable(Rule::ShebangMissingExecutableFile);
|
||||
rules.disable(Rule::ShebangNotExecutable);
|
||||
|
||||
let settings = Settings {
|
||||
let settings = LinterSettings {
|
||||
rules,
|
||||
..Settings::default()
|
||||
..LinterSettings::default()
|
||||
};
|
||||
|
||||
let group = criterion.benchmark_group("linter/all-rules");
|
||||
|
|
|
@ -405,7 +405,7 @@ mod tests {
|
|||
let diagnostics = lint_path(
|
||||
&path,
|
||||
Some(&package_root),
|
||||
&settings,
|
||||
&settings.linter,
|
||||
Some(&cache),
|
||||
flags::Noqa::Enabled,
|
||||
flags::FixMode::Generate,
|
||||
|
@ -450,7 +450,7 @@ mod tests {
|
|||
got_diagnostics += lint_path(
|
||||
&path,
|
||||
Some(&package_root),
|
||||
&settings,
|
||||
&settings.linter,
|
||||
Some(&cache),
|
||||
flags::Noqa::Enabled,
|
||||
flags::FixMode::Generate,
|
||||
|
@ -707,7 +707,7 @@ mod tests {
|
|||
lint_path(
|
||||
&self.package_root.join(path),
|
||||
Some(&self.package_root),
|
||||
&self.settings,
|
||||
&self.settings.linter,
|
||||
Some(cache),
|
||||
flags::Noqa::Enabled,
|
||||
flags::FixMode::Generate,
|
||||
|
|
|
@ -65,7 +65,7 @@ pub(crate) fn add_noqa(
|
|||
return None;
|
||||
}
|
||||
};
|
||||
match add_noqa_to_path(path, package, &source_kind, source_type, settings) {
|
||||
match add_noqa_to_path(path, package, &source_kind, source_type, &settings.linter) {
|
||||
Ok(count) => Some(count),
|
||||
Err(e) => {
|
||||
error!("Failed to add noqa to {}: {e}", path.display());
|
||||
|
|
|
@ -16,7 +16,7 @@ use rustc_hash::FxHashMap;
|
|||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_linter::message::Message;
|
||||
use ruff_linter::registry::Rule;
|
||||
use ruff_linter::settings::{flags, Settings};
|
||||
use ruff_linter::settings::{flags, LinterSettings};
|
||||
use ruff_linter::{fs, warn_user_once, IOError};
|
||||
use ruff_python_ast::imports::ImportMap;
|
||||
use ruff_source_file::SourceFileBuilder;
|
||||
|
@ -119,7 +119,7 @@ pub(crate) fn check(
|
|||
}
|
||||
});
|
||||
|
||||
lint_path(path, package, settings, cache, noqa, autofix).map_err(|e| {
|
||||
lint_path(path, package, &settings.linter, cache, noqa, autofix).map_err(|e| {
|
||||
(Some(path.to_owned()), {
|
||||
let mut error = e.to_string();
|
||||
for cause in e.chain() {
|
||||
|
@ -142,7 +142,7 @@ pub(crate) fn check(
|
|||
.unwrap_or_else(|(path, message)| {
|
||||
if let Some(path) = &path {
|
||||
let settings = resolver.resolve(path, pyproject_config);
|
||||
if settings.rules.enabled(Rule::IOError) {
|
||||
if settings.linter.rules.enabled(Rule::IOError) {
|
||||
let dummy =
|
||||
SourceFileBuilder::new(path.to_string_lossy().as_ref(), "").finish();
|
||||
|
||||
|
@ -195,7 +195,7 @@ pub(crate) fn check(
|
|||
fn lint_path(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
cache: Option<&Cache>,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
|
@ -238,7 +238,7 @@ mod test {
|
|||
|
||||
use ruff_linter::message::{Emitter, EmitterContext, TextEmitter};
|
||||
use ruff_linter::registry::Rule;
|
||||
use ruff_linter::settings::{flags, Settings};
|
||||
use ruff_linter::settings::{flags, LinterSettings, Settings};
|
||||
use ruff_workspace::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
|
||||
use crate::args::CliOverrides;
|
||||
|
@ -268,7 +268,10 @@ mod test {
|
|||
// Configure
|
||||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path);
|
||||
// invalid pyproject.toml is not active by default
|
||||
let settings = Settings::for_rules(vec![rule_code, Rule::InvalidPyprojectToml]);
|
||||
let settings = Settings {
|
||||
linter: LinterSettings::for_rules(vec![rule_code, Rule::InvalidPyprojectToml]),
|
||||
..Settings::default()
|
||||
};
|
||||
let pyproject_config =
|
||||
PyprojectConfig::new(PyprojectDiscoveryStrategy::Fixed, settings, None);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ pub(crate) fn check_stdin(
|
|||
}
|
||||
}
|
||||
let package_root = filename.and_then(Path::parent).and_then(|path| {
|
||||
packaging::detect_package_root(path, &pyproject_config.settings.namespace_packages)
|
||||
packaging::detect_package_root(path, &pyproject_config.settings.linter.namespace_packages)
|
||||
});
|
||||
let stdin = read_from_stdin()?;
|
||||
let mut diagnostics = lint_stdin(
|
||||
|
|
|
@ -77,11 +77,12 @@ pub(crate) fn format(
|
|||
|
||||
let resolved_settings = resolver.resolve(path, &pyproject_config);
|
||||
|
||||
let preview = match resolved_settings.preview {
|
||||
// TODO(micha): Use `formatter` settings instead
|
||||
let preview = match resolved_settings.linter.preview {
|
||||
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
|
||||
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
|
||||
};
|
||||
let line_length = resolved_settings.line_length;
|
||||
let line_length = resolved_settings.linter.line_length;
|
||||
|
||||
let options = PyFormatOptions::from_source_type(source_type)
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
|
||||
|
|
|
@ -39,11 +39,12 @@ pub(crate) fn format_stdin(cli: &FormatArguments, overrides: &CliOverrides) -> R
|
|||
// Format the file.
|
||||
let path = cli.stdin_filename.as_deref();
|
||||
|
||||
let preview = match pyproject_config.settings.preview {
|
||||
// TODO(micha): Use Formatter settings
|
||||
let preview = match pyproject_config.settings.linter.preview {
|
||||
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
|
||||
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
|
||||
};
|
||||
let line_length = pyproject_config.settings.line_length;
|
||||
let line_length = pyproject_config.settings.linter.line_length;
|
||||
|
||||
let options = path
|
||||
.map(PyFormatOptions::from_extension)
|
||||
|
|
|
@ -22,7 +22,7 @@ use ruff_linter::logging::DisplayParseError;
|
|||
use ruff_linter::message::Message;
|
||||
use ruff_linter::pyproject_toml::lint_pyproject_toml;
|
||||
use ruff_linter::registry::AsRule;
|
||||
use ruff_linter::settings::{flags, Settings};
|
||||
use ruff_linter::settings::{flags, LinterSettings, Settings};
|
||||
use ruff_linter::source_kind::SourceKind;
|
||||
use ruff_linter::{fs, IOError, SyntaxError};
|
||||
use ruff_macros::CacheKey;
|
||||
|
@ -85,7 +85,7 @@ impl Diagnostics {
|
|||
pub(crate) fn from_source_error(
|
||||
err: &SourceExtractionError,
|
||||
path: Option<&Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Self {
|
||||
let diagnostic = Diagnostic::from(err);
|
||||
if settings.rules.enabled(diagnostic.kind.rule()) {
|
||||
|
@ -143,7 +143,7 @@ impl AddAssign for Diagnostics {
|
|||
pub(crate) fn lint_path(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
cache: Option<&Cache>,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
|
@ -381,7 +381,7 @@ pub(crate) fn lint_stdin(
|
|||
Ok(Some(sources)) => sources,
|
||||
Ok(None) => return Ok(Diagnostics::default()),
|
||||
Err(err) => {
|
||||
return Ok(Diagnostics::from_source_error(&err, path, settings));
|
||||
return Ok(Diagnostics::from_source_error(&err, path, &settings.linter));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -401,7 +401,7 @@ pub(crate) fn lint_stdin(
|
|||
path.unwrap_or_else(|| Path::new("-")),
|
||||
package,
|
||||
noqa,
|
||||
settings,
|
||||
&settings.linter,
|
||||
&source_kind,
|
||||
source_type,
|
||||
) {
|
||||
|
@ -438,7 +438,7 @@ pub(crate) fn lint_stdin(
|
|||
let result = lint_only(
|
||||
path.unwrap_or_else(|| Path::new("-")),
|
||||
package,
|
||||
settings,
|
||||
&settings.linter,
|
||||
noqa,
|
||||
&source_kind,
|
||||
source_type,
|
||||
|
@ -456,7 +456,7 @@ pub(crate) fn lint_stdin(
|
|||
let result = lint_only(
|
||||
path.unwrap_or_else(|| Path::new("-")),
|
||||
package,
|
||||
settings,
|
||||
&settings.linter,
|
||||
noqa,
|
||||
&source_kind,
|
||||
source_type,
|
||||
|
|
|
@ -550,8 +550,11 @@ fn format_dir_entry(
|
|||
|
||||
let settings = resolver.resolve(&path, pyproject_config);
|
||||
// That's a bad way of doing this but it's not worth doing something better for format_dev
|
||||
if settings.line_length != LineLength::default() {
|
||||
options = options.with_line_width(LineWidth::from(NonZeroU16::from(settings.line_length)));
|
||||
// TODO(micha) use formatter settings instead
|
||||
if settings.linter.line_length != LineLength::default() {
|
||||
options = options.with_line_width(LineWidth::from(NonZeroU16::from(
|
||||
settings.linter.line_length,
|
||||
)));
|
||||
}
|
||||
|
||||
// Handle panics (mostly in `debug_assert!`)
|
||||
|
|
|
@ -116,7 +116,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
|
|||
if checker.enabled(Rule::InvalidIndexType) {
|
||||
ruff::rules::invalid_index_type(checker, subscript);
|
||||
}
|
||||
if checker.settings.rules.enabled(Rule::SliceCopy) {
|
||||
if checker.enabled(Rule::SliceCopy) {
|
||||
refurb::rules::slice_copy(checker, subscript);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ use crate::importer::Importer;
|
|||
use crate::noqa::NoqaMapping;
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::{flake8_pyi, flake8_type_checking, pyflakes, pyupgrade};
|
||||
use crate::settings::{flags, Settings};
|
||||
use crate::settings::{flags, LinterSettings};
|
||||
use crate::{docstrings, noqa};
|
||||
|
||||
mod analyze;
|
||||
|
@ -85,8 +85,8 @@ pub(crate) struct Checker<'a> {
|
|||
/// The [`NoqaMapping`] for the current analysis (i.e., the mapping from line number to
|
||||
/// suppression commented line number).
|
||||
noqa_line_for: &'a NoqaMapping,
|
||||
/// The [`Settings`] for the current analysis, including the enabled rules.
|
||||
pub(crate) settings: &'a Settings,
|
||||
/// The [`LinterSettings`] for the current analysis, including the enabled rules.
|
||||
pub(crate) settings: &'a LinterSettings,
|
||||
/// The [`Locator`] for the current file, which enables extraction of source code from byte
|
||||
/// offsets.
|
||||
locator: &'a Locator<'a>,
|
||||
|
@ -110,7 +110,7 @@ pub(crate) struct Checker<'a> {
|
|||
impl<'a> Checker<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new(
|
||||
settings: &'a Settings,
|
||||
settings: &'a LinterSettings,
|
||||
noqa_line_for: &'a NoqaMapping,
|
||||
noqa: flags::Noqa,
|
||||
path: &'a Path,
|
||||
|
@ -1929,7 +1929,7 @@ pub(crate) fn check_ast(
|
|||
stylist: &Stylist,
|
||||
indexer: &Indexer,
|
||||
noqa_line_for: &NoqaMapping,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
noqa: flags::Noqa,
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
|
|
|
@ -5,23 +5,20 @@ use ruff_diagnostics::Diagnostic;
|
|||
use crate::registry::Rule;
|
||||
use crate::rules::flake8_no_pep420::rules::implicit_namespace_package;
|
||||
use crate::rules::pep8_naming::rules::invalid_module_name;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
pub(crate) fn check_file_path(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut diagnostics: Vec<Diagnostic> = vec![];
|
||||
|
||||
// flake8-no-pep420
|
||||
if settings.rules.enabled(Rule::ImplicitNamespacePackage) {
|
||||
if let Some(diagnostic) = implicit_namespace_package(
|
||||
path,
|
||||
package,
|
||||
&settings.file_resolver.project_root,
|
||||
&settings.src,
|
||||
) {
|
||||
if let Some(diagnostic) =
|
||||
implicit_namespace_package(path, package, &settings.project_root, &settings.src)
|
||||
{
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::directives::IsortDirectives;
|
|||
use crate::registry::Rule;
|
||||
use crate::rules::isort;
|
||||
use crate::rules::isort::block::{Block, BlockBuilder};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::source_kind::SourceKind;
|
||||
|
||||
fn extract_import_map(path: &Path, package: Option<&Path>, blocks: &[&Block]) -> Option<ImportMap> {
|
||||
|
@ -81,7 +81,7 @@ pub(crate) fn check_imports(
|
|||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
directives: &IsortDirectives,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
stylist: &Stylist,
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::rules::pycodestyle::rules::logical_lines::{
|
|||
whitespace_around_keywords, whitespace_around_named_parameter_equals,
|
||||
whitespace_before_comment, whitespace_before_parameters, LogicalLines, TokenFlags,
|
||||
};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// Return the amount of indentation, expanding tabs to the next multiple of 8.
|
||||
fn expand_indent(line: &str) -> usize {
|
||||
|
@ -34,7 +34,7 @@ pub(crate) fn check_logical_lines(
|
|||
tokens: &[LexResult],
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut context = LogicalLinesContext::new(settings);
|
||||
|
||||
|
@ -132,12 +132,12 @@ pub(crate) fn check_logical_lines(
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct LogicalLinesContext<'a> {
|
||||
settings: &'a Settings,
|
||||
settings: &'a LinterSettings,
|
||||
diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
impl<'a> LogicalLinesContext<'a> {
|
||||
fn new(settings: &'a Settings) -> Self {
|
||||
fn new(settings: &'a LinterSettings) -> Self {
|
||||
Self {
|
||||
settings,
|
||||
diagnostics: Vec::new(),
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::noqa::{Directive, FileExemption, NoqaDirectives, NoqaMapping};
|
|||
use crate::registry::{AsRule, Rule};
|
||||
use crate::rule_redirects::get_redirect_target;
|
||||
use crate::rules::ruff::rules::{UnusedCodes, UnusedNOQA};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
pub(crate) fn check_noqa(
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
|
@ -23,7 +23,7 @@ pub(crate) fn check_noqa(
|
|||
comment_ranges: &CommentRanges,
|
||||
noqa_line_for: &NoqaMapping,
|
||||
analyze_directives: bool,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Vec<usize> {
|
||||
// Identify any codes that are globally exempted (within the current file).
|
||||
let exemption = FileExemption::try_extract(locator.contents(), comment_ranges, path, locator);
|
||||
|
|
|
@ -12,14 +12,14 @@ use crate::rules::pycodestyle::rules::{
|
|||
trailing_whitespace,
|
||||
};
|
||||
use crate::rules::pylint;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
pub(crate) fn check_physical_lines(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
indexer: &Indexer,
|
||||
doc_lines: &[TextSize],
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut diagnostics: Vec<Diagnostic> = vec![];
|
||||
|
||||
|
@ -99,7 +99,7 @@ mod tests {
|
|||
|
||||
use crate::line_width::LineLength;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use super::check_physical_lines;
|
||||
|
||||
|
@ -117,9 +117,9 @@ mod tests {
|
|||
&stylist,
|
||||
&indexer,
|
||||
&[],
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
line_length,
|
||||
..Settings::for_rule(Rule::LineTooLong)
|
||||
..LinterSettings::for_rule(Rule::LineTooLong)
|
||||
},
|
||||
)
|
||||
};
|
||||
|
|
|
@ -17,14 +17,14 @@ use crate::rules::{
|
|||
eradicate, flake8_commas, flake8_executable, flake8_fixme, flake8_implicit_str_concat,
|
||||
flake8_pyi, flake8_quotes, flake8_todos, pycodestyle, pygrep_hooks, pylint, pyupgrade, ruff,
|
||||
};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
pub(crate) fn check_tokens(
|
||||
tokens: &[LexResult],
|
||||
path: &Path,
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
is_stub: bool,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut diagnostics: Vec<Diagnostic> = vec![];
|
||||
|
|
|
@ -11,7 +11,7 @@ use ruff_python_index::Indexer;
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::noqa::NoqaMapping;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
@ -22,7 +22,7 @@ bitflags! {
|
|||
}
|
||||
|
||||
impl Flags {
|
||||
pub fn from_settings(settings: &Settings) -> Self {
|
||||
pub fn from_settings(settings: &LinterSettings) -> Self {
|
||||
if settings
|
||||
.rules
|
||||
.iter_enabled()
|
||||
|
|
|
@ -32,7 +32,7 @@ use crate::message::Message;
|
|||
use crate::noqa::add_noqa;
|
||||
use crate::registry::{AsRule, Rule};
|
||||
use crate::rules::pycodestyle;
|
||||
use crate::settings::{flags, Settings};
|
||||
use crate::settings::{flags, LinterSettings};
|
||||
use crate::source_kind::SourceKind;
|
||||
use crate::{directives, fs};
|
||||
|
||||
|
@ -76,7 +76,7 @@ pub fn check_path(
|
|||
stylist: &Stylist,
|
||||
indexer: &Indexer,
|
||||
directives: &Directives,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
noqa: flags::Noqa,
|
||||
source_kind: &SourceKind,
|
||||
source_type: PySourceType,
|
||||
|
@ -269,7 +269,7 @@ pub fn add_noqa_to_path(
|
|||
package: Option<&Path>,
|
||||
source_kind: &SourceKind,
|
||||
source_type: PySourceType,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Result<usize> {
|
||||
let contents = source_kind.source_code();
|
||||
|
||||
|
@ -336,7 +336,7 @@ pub fn add_noqa_to_path(
|
|||
pub fn lint_only(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
noqa: flags::Noqa,
|
||||
source_kind: &SourceKind,
|
||||
source_type: PySourceType,
|
||||
|
@ -418,7 +418,7 @@ pub fn lint_fix<'a>(
|
|||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
noqa: flags::Noqa,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
source_kind: &'a SourceKind,
|
||||
source_type: PySourceType,
|
||||
) -> Result<FixerResult<'a>> {
|
||||
|
@ -635,7 +635,7 @@ mod tests {
|
|||
} = test_notebook_path(
|
||||
&actual,
|
||||
expected,
|
||||
&settings::Settings::for_rule(Rule::UnsortedImports),
|
||||
&settings::LinterSettings::for_rule(Rule::UnsortedImports),
|
||||
)?;
|
||||
assert_messages!(messages, actual, source_notebook);
|
||||
Ok(())
|
||||
|
@ -652,7 +652,7 @@ mod tests {
|
|||
} = test_notebook_path(
|
||||
&actual,
|
||||
expected,
|
||||
&settings::Settings::for_rule(Rule::UnusedImport),
|
||||
&settings::LinterSettings::for_rule(Rule::UnusedImport),
|
||||
)?;
|
||||
assert_messages!(messages, actual, source_notebook);
|
||||
Ok(())
|
||||
|
@ -669,7 +669,7 @@ mod tests {
|
|||
} = test_notebook_path(
|
||||
&actual,
|
||||
expected,
|
||||
&settings::Settings::for_rule(Rule::UnusedVariable),
|
||||
&settings::LinterSettings::for_rule(Rule::UnusedVariable),
|
||||
)?;
|
||||
assert_messages!(messages, actual, source_notebook);
|
||||
Ok(())
|
||||
|
@ -686,7 +686,7 @@ mod tests {
|
|||
} = test_notebook_path(
|
||||
actual_path,
|
||||
&expected_path,
|
||||
&settings::Settings::for_rule(Rule::UnusedImport),
|
||||
&settings::LinterSettings::for_rule(Rule::UnusedImport),
|
||||
)?;
|
||||
let mut writer = Vec::new();
|
||||
fixed_notebook.write(&mut writer)?;
|
||||
|
@ -720,7 +720,7 @@ mod tests {
|
|||
let (_, transformed) = test_contents(
|
||||
&source_kind,
|
||||
path,
|
||||
&settings::Settings::for_rule(Rule::UnusedImport),
|
||||
&settings::LinterSettings::for_rule(Rule::UnusedImport),
|
||||
);
|
||||
let linted_notebook = transformed.into_owned().expect_ipy_notebook();
|
||||
let mut writer = Vec::new();
|
||||
|
|
|
@ -10,7 +10,7 @@ use ruff_source_file::SourceFile;
|
|||
use crate::message::Message;
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::ruff::rules::InvalidPyprojectToml;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::IOError;
|
||||
|
||||
/// Unlike [`pyproject_toml::PyProjectToml`], in our case `build_system` is also optional
|
||||
|
@ -23,7 +23,7 @@ struct PyProjectToml {
|
|||
project: Option<Project>,
|
||||
}
|
||||
|
||||
pub fn lint_pyproject_toml(source_file: SourceFile, settings: &Settings) -> Vec<Message> {
|
||||
pub fn lint_pyproject_toml(source_file: SourceFile, settings: &LinterSettings) -> Vec<Message> {
|
||||
let Some(err) = toml::from_str::<PyProjectToml>(source_file.source_text()).err() else {
|
||||
return Vec::default();
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("airflow").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("eradicate").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruff_python_index::Indexer;
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use super::super::detection::comment_contains_code;
|
||||
|
||||
|
@ -52,7 +52,7 @@ pub(crate) fn commented_out_code(
|
|||
diagnostics: &mut Vec<Diagnostic>,
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
for range in indexer.comment_ranges() {
|
||||
let line = locator.full_lines(*range);
|
||||
|
|
|
@ -27,7 +27,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_2020").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -11,15 +11,15 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test]
|
||||
fn defaults() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/annotation_presence.py"),
|
||||
&Settings {
|
||||
..Settings::for_rules(vec![
|
||||
&LinterSettings {
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingTypeFunctionArgument,
|
||||
Rule::MissingTypeArgs,
|
||||
Rule::MissingTypeKwargs,
|
||||
|
@ -42,12 +42,12 @@ mod tests {
|
|||
fn ignore_fully_untyped() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/ignore_fully_untyped.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_annotations: super::settings::Settings {
|
||||
ignore_fully_untyped: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingTypeFunctionArgument,
|
||||
Rule::MissingTypeArgs,
|
||||
Rule::MissingTypeKwargs,
|
||||
|
@ -70,12 +70,12 @@ mod tests {
|
|||
fn suppress_dummy_args() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/suppress_dummy_args.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_annotations: super::settings::Settings {
|
||||
suppress_dummy_args: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingTypeFunctionArgument,
|
||||
Rule::MissingTypeArgs,
|
||||
Rule::MissingTypeKwargs,
|
||||
|
@ -92,12 +92,12 @@ mod tests {
|
|||
fn mypy_init_return() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/mypy_init_return.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_annotations: super::settings::Settings {
|
||||
mypy_init_return: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingReturnTypeUndocumentedPublicFunction,
|
||||
Rule::MissingReturnTypePrivateFunction,
|
||||
Rule::MissingReturnTypeSpecialMethod,
|
||||
|
@ -114,12 +114,12 @@ mod tests {
|
|||
fn suppress_none_returning() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/suppress_none_returning.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_annotations: super::settings::Settings {
|
||||
suppress_none_returning: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingTypeFunctionArgument,
|
||||
Rule::MissingTypeArgs,
|
||||
Rule::MissingTypeKwargs,
|
||||
|
@ -142,12 +142,12 @@ mod tests {
|
|||
fn allow_star_arg_any() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/allow_star_arg_any.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_annotations: super::settings::Settings {
|
||||
allow_star_arg_any: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::AnyType])
|
||||
..LinterSettings::for_rules(vec![Rule::AnyType])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -158,8 +158,8 @@ mod tests {
|
|||
fn allow_overload() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/allow_overload.py"),
|
||||
&Settings {
|
||||
..Settings::for_rules(vec![
|
||||
&LinterSettings {
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingReturnTypeUndocumentedPublicFunction,
|
||||
Rule::MissingReturnTypePrivateFunction,
|
||||
Rule::MissingReturnTypeSpecialMethod,
|
||||
|
@ -176,8 +176,8 @@ mod tests {
|
|||
fn allow_nested_overload() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/allow_nested_overload.py"),
|
||||
&Settings {
|
||||
..Settings::for_rules(vec![
|
||||
&LinterSettings {
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::MissingReturnTypeUndocumentedPublicFunction,
|
||||
Rule::MissingReturnTypePrivateFunction,
|
||||
Rule::MissingReturnTypeSpecialMethod,
|
||||
|
@ -194,7 +194,7 @@ mod tests {
|
|||
fn simple_magic_methods() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_annotations/simple_magic_methods.py"),
|
||||
&Settings::for_rule(Rule::MissingReturnTypeSpecialMethod),
|
||||
&LinterSettings::for_rule(Rule::MissingReturnTypeSpecialMethod),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -10,7 +10,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::BlockingHttpCallInAsyncFunction, Path::new("ASYNC100.py"))]
|
||||
|
@ -20,7 +20,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_async").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -12,7 +12,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::Assert, Path::new("S101.py"))]
|
||||
|
@ -51,7 +51,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bandit").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -61,7 +61,7 @@ mod tests {
|
|||
fn check_hardcoded_tmp_additional_dirs() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bandit/S108.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_bandit: super::settings::Settings {
|
||||
hardcoded_tmp_directory: vec![
|
||||
"/tmp".to_string(),
|
||||
|
@ -71,7 +71,7 @@ mod tests {
|
|||
],
|
||||
check_typed_exception: false,
|
||||
},
|
||||
..Settings::for_rule(Rule::HardcodedTempFile)
|
||||
..LinterSettings::for_rule(Rule::HardcodedTempFile)
|
||||
},
|
||||
)?;
|
||||
assert_messages!("S108_extend", diagnostics);
|
||||
|
@ -82,12 +82,12 @@ mod tests {
|
|||
fn check_typed_exception() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bandit/S110.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_bandit: super::settings::Settings {
|
||||
check_typed_exception: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::TryExceptPass)
|
||||
..LinterSettings::for_rule(Rule::TryExceptPass)
|
||||
},
|
||||
)?;
|
||||
assert_messages!("S110_typed", diagnostics);
|
||||
|
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_blind_except").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -20,7 +20,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_boolean_trap").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -11,7 +11,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::AbstractBaseClassWithoutAbstractMethod, Path::new("B024.py"))]
|
||||
|
@ -57,7 +57,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bugbear").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -68,7 +68,7 @@ mod tests {
|
|||
let snapshot = "B905.py";
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bugbear").join(snapshot).as_path(),
|
||||
&Settings::for_rule(Rule::ZipWithoutExplicitStrict),
|
||||
&LinterSettings::for_rule(Rule::ZipWithoutExplicitStrict),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -79,14 +79,14 @@ mod tests {
|
|||
let snapshot = "extend_immutable_calls_arg_annotation".to_string();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bugbear/B006_extended.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_bugbear: super::settings::Settings {
|
||||
extend_immutable_calls: vec![
|
||||
"custom.ImmutableTypeA".to_string(),
|
||||
"custom.ImmutableTypeB".to_string(),
|
||||
],
|
||||
},
|
||||
..Settings::for_rule(Rule::MutableArgumentDefault)
|
||||
..LinterSettings::for_rule(Rule::MutableArgumentDefault)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -98,7 +98,7 @@ mod tests {
|
|||
let snapshot = "extend_immutable_calls_arg_default".to_string();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bugbear/B008_extended.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_bugbear: super::settings::Settings {
|
||||
extend_immutable_calls: vec![
|
||||
"fastapi.Depends".to_string(),
|
||||
|
@ -106,7 +106,7 @@ mod tests {
|
|||
"custom.ImmutableTypeA".to_string(),
|
||||
],
|
||||
},
|
||||
..Settings::for_rule(Rule::FunctionCallInDefaultArgument)
|
||||
..LinterSettings::for_rule(Rule::FunctionCallInDefaultArgument)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -12,7 +12,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::BuiltinVariableShadowing, Path::new("A001.py"))]
|
||||
|
@ -22,7 +22,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_builtins").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -40,11 +40,11 @@ mod tests {
|
|||
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_builtins").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_builtins: super::settings::Settings {
|
||||
builtins_ignorelist: vec!["id".to_string(), "dir".to_string()],
|
||||
},
|
||||
..Settings::for_rules(vec![rule_code])
|
||||
..LinterSettings::for_rules(vec![rule_code])
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
let snapshot = path.to_string_lossy().into_owned();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_commas").join(path).as_path(),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::MissingTrailingComma,
|
||||
Rule::TrailingCommaOnBareTuple,
|
||||
Rule::ProhibitedTrailingComma,
|
||||
|
|
|
@ -9,7 +9,7 @@ use ruff_source_file::Locator;
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// Simplified token type.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
|
@ -225,7 +225,7 @@ pub(crate) fn trailing_commas(
|
|||
diagnostics: &mut Vec<Diagnostic>,
|
||||
tokens: &[LexResult],
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
let tokens = tokens
|
||||
.iter()
|
||||
|
|
|
@ -12,7 +12,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::UnnecessaryCallAroundSorted, Path::new("C413.py"))]
|
||||
|
@ -37,7 +37,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_comprehensions").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -52,11 +52,11 @@ mod tests {
|
|||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_comprehensions").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_comprehensions: super::settings::Settings {
|
||||
allow_dict_calls_with_keyword_arguments: true,
|
||||
},
|
||||
..Settings::for_rule(rule_code)
|
||||
..LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -94,12 +94,12 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -112,12 +112,12 @@ import os
|
|||
import os
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
min_file_size: 256,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -151,7 +151,7 @@ import os
|
|||
# Copyright 2023
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ import os
|
|||
r#"কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক
|
||||
"#
|
||||
.trim(),
|
||||
&settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for the absence of copyright notices within Python files.
|
||||
|
@ -24,7 +24,7 @@ impl Violation for MissingCopyrightNotice {
|
|||
/// CPY001
|
||||
pub(crate) fn missing_copyright_notice(
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Option<Diagnostic> {
|
||||
// Ignore files that are too small to contain a copyright notice.
|
||||
if locator.len() < settings.flake8_copyright.min_file_size {
|
||||
|
|
|
@ -25,7 +25,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_datetimez").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_debugger").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -23,7 +23,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_django").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -16,7 +16,7 @@ mod tests {
|
|||
fn defaults() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_errmsg/EM.py"),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::RawStringInException,
|
||||
Rule::FStringInException,
|
||||
Rule::DotFormatInException,
|
||||
|
@ -30,11 +30,11 @@ mod tests {
|
|||
fn custom() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_errmsg/EM.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_errmsg: super::settings::Settings {
|
||||
max_string_length: 20,
|
||||
},
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::RawStringInException,
|
||||
Rule::FStringInException,
|
||||
Rule::DotFormatInException,
|
||||
|
|
|
@ -32,7 +32,7 @@ mod tests {
|
|||
let snapshot = path.to_string_lossy().into_owned();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_executable").join(path).as_path(),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::ShebangNotExecutable,
|
||||
Rule::ShebangMissingExecutableFile,
|
||||
Rule::ShebangLeadingWhitespace,
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) use shebang_not_executable::*;
|
|||
pub(crate) use shebang_not_first_line::*;
|
||||
|
||||
use crate::comments::shebang::ShebangDirective;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
mod shebang_leading_whitespace;
|
||||
mod shebang_missing_executable_file;
|
||||
|
@ -24,7 +24,7 @@ pub(crate) fn from_tokens(
|
|||
tokens: &[LexResult],
|
||||
path: &Path,
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
let mut has_any_shebang = false;
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruff_python_trivia::is_python_whitespace;
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::registry::AsRule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for whitespace before a shebang directive.
|
||||
|
@ -50,7 +50,7 @@ impl AlwaysAutofixableViolation for ShebangLeadingWhitespace {
|
|||
pub(crate) fn shebang_leading_whitespace(
|
||||
range: TextRange,
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Option<Diagnostic> {
|
||||
// If the shebang is at the beginning of the file, abort.
|
||||
if range.start() == TextSize::from(0) {
|
||||
|
|
|
@ -19,7 +19,7 @@ mod tests {
|
|||
let snapshot = format!("{}_T00.py", rule_code.as_ref());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_fixme/T00.py"),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -29,9 +29,9 @@ mod tests {
|
|||
let snapshot = path.to_string_lossy().into_owned();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_future_annotations").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::FutureRewritableTypeAnnotation)
|
||||
..settings::LinterSettings::for_rule(Rule::FutureRewritableTypeAnnotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -47,9 +47,9 @@ mod tests {
|
|||
let snapshot = format!("fa102_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_future_annotations").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::FutureRequiredTypeAnnotation)
|
||||
..settings::LinterSettings::for_rule(Rule::FutureRequiredTypeAnnotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -31,7 +31,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_gettext").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -20,7 +20,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_implicit_str_concat").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -37,11 +37,11 @@ mod tests {
|
|||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_implicit_str_concat").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_implicit_str_concat: super::settings::Settings {
|
||||
allow_multiline: false,
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -12,14 +12,14 @@ mod tests {
|
|||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::flake8_import_conventions::settings::default_aliases;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test]
|
||||
fn defaults() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/defaults.py"),
|
||||
&Settings::for_rule(Rule::UnconventionalImportAlias),
|
||||
&LinterSettings::for_rule(Rule::UnconventionalImportAlias),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -34,13 +34,13 @@ mod tests {
|
|||
]));
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/custom.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases,
|
||||
banned_aliases: FxHashMap::default(),
|
||||
banned_from: FxHashSet::default(),
|
||||
},
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
..LinterSettings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -51,7 +51,7 @@ mod tests {
|
|||
fn custom_banned() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/custom_banned.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases: default_aliases(),
|
||||
banned_aliases: FxHashMap::from_iter([
|
||||
|
@ -71,7 +71,7 @@ mod tests {
|
|||
]),
|
||||
banned_from: FxHashSet::default(),
|
||||
},
|
||||
..Settings::for_rule(Rule::BannedImportAlias)
|
||||
..LinterSettings::for_rule(Rule::BannedImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -82,7 +82,7 @@ mod tests {
|
|||
fn custom_banned_from() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/custom_banned_from.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases: default_aliases(),
|
||||
banned_aliases: FxHashMap::default(),
|
||||
|
@ -92,7 +92,7 @@ mod tests {
|
|||
"pandas".to_string(),
|
||||
]),
|
||||
},
|
||||
..Settings::for_rule(Rule::BannedImportFrom)
|
||||
..LinterSettings::for_rule(Rule::BannedImportFrom)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -103,7 +103,7 @@ mod tests {
|
|||
fn remove_defaults() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/remove_default.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases: FxHashMap::from_iter([
|
||||
("altair".to_string(), "alt".to_string()),
|
||||
|
@ -114,7 +114,7 @@ mod tests {
|
|||
banned_aliases: FxHashMap::default(),
|
||||
banned_from: FxHashSet::default(),
|
||||
},
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
..LinterSettings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -131,13 +131,13 @@ mod tests {
|
|||
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/override_default.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases,
|
||||
banned_aliases: FxHashMap::default(),
|
||||
banned_from: FxHashSet::default(),
|
||||
},
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
..LinterSettings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -157,13 +157,13 @@ mod tests {
|
|||
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/from_imports.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings {
|
||||
aliases,
|
||||
banned_aliases: FxHashMap::default(),
|
||||
banned_from: FxHashSet::default(),
|
||||
},
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
..LinterSettings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -174,7 +174,7 @@ mod tests {
|
|||
fn tricky() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/tricky.py"),
|
||||
&Settings::for_rule(Rule::UnconventionalImportAlias),
|
||||
&LinterSettings::for_rule(Rule::UnconventionalImportAlias),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -10,7 +10,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::DirectLoggerInstantiation, Path::new("LOG001.py"))]
|
||||
|
@ -21,7 +21,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_logging").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -31,9 +31,9 @@ mod tests {
|
|||
let snapshot = path.to_string_lossy().into_owned();
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_logging_format").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
logger_objects: vec!["logging_setup.logger".to_string()],
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::LoggingStringFormat,
|
||||
Rule::LoggingPercentFormat,
|
||||
Rule::LoggingStringConcat,
|
||||
|
|
|
@ -10,7 +10,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::{test_path, test_resource_path};
|
||||
|
||||
#[test_case(Path::new("test_pass_init"), Path::new("example.py"))]
|
||||
|
@ -30,11 +30,11 @@ mod tests {
|
|||
));
|
||||
let diagnostics = test_path(
|
||||
p.as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
namespace_packages: vec![test_resource_path(
|
||||
"fixtures/flake8_no_pep420/test_pass_namespace_package",
|
||||
)],
|
||||
..Settings::for_rule(Rule::ImplicitNamespacePackage)
|
||||
..LinterSettings::for_rule(Rule::ImplicitNamespacePackage)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -24,7 +24,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_pie").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_print").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -112,7 +112,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_pyi").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -124,9 +124,9 @@ mod tests {
|
|||
let snapshot = format!("py38_{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_pyi").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py38,
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -295,9 +295,9 @@ mod tests {
|
|||
) -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_pytest_style").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_pytest_style: plugin_settings,
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(name, diagnostics);
|
||||
|
|
|
@ -11,7 +11,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
use super::settings::Quote;
|
||||
|
@ -26,14 +26,14 @@ mod tests {
|
|||
let snapshot = format!("require_singles_over_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_quotes").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_quotes: super::settings::Settings {
|
||||
inline_quotes: Quote::Single,
|
||||
multiline_quotes: Quote::Single,
|
||||
docstring_quotes: Quote::Single,
|
||||
avoid_escape: true,
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::BadQuotesInlineString,
|
||||
Rule::BadQuotesMultilineString,
|
||||
Rule::BadQuotesDocstring,
|
||||
|
@ -55,14 +55,14 @@ mod tests {
|
|||
let snapshot = format!("require_doubles_over_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_quotes").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_quotes: super::settings::Settings {
|
||||
inline_quotes: Quote::Double,
|
||||
multiline_quotes: Quote::Double,
|
||||
docstring_quotes: Quote::Double,
|
||||
avoid_escape: true,
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::BadQuotesInlineString,
|
||||
Rule::BadQuotesMultilineString,
|
||||
Rule::BadQuotesDocstring,
|
||||
|
@ -88,14 +88,14 @@ mod tests {
|
|||
let snapshot = format!("require_docstring_doubles_over_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_quotes").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_quotes: super::settings::Settings {
|
||||
inline_quotes: Quote::Single,
|
||||
multiline_quotes: Quote::Single,
|
||||
docstring_quotes: Quote::Double,
|
||||
avoid_escape: true,
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::BadQuotesInlineString,
|
||||
Rule::BadQuotesMultilineString,
|
||||
Rule::BadQuotesDocstring,
|
||||
|
@ -121,14 +121,14 @@ mod tests {
|
|||
let snapshot = format!("require_docstring_singles_over_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_quotes").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_quotes: super::settings::Settings {
|
||||
inline_quotes: Quote::Single,
|
||||
multiline_quotes: Quote::Double,
|
||||
docstring_quotes: Quote::Single,
|
||||
avoid_escape: true,
|
||||
},
|
||||
..Settings::for_rules(vec![
|
||||
..LinterSettings::for_rules(vec![
|
||||
Rule::BadQuotesInlineString,
|
||||
Rule::BadQuotesMultilineString,
|
||||
Rule::BadQuotesDocstring,
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruff_source_file::Locator;
|
|||
|
||||
use crate::lex::docstring_detection::StateMachine;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use super::super::settings::Quote;
|
||||
|
||||
|
@ -255,7 +255,7 @@ impl<'a> From<&'a str> for Trivia<'a> {
|
|||
}
|
||||
|
||||
/// Q003
|
||||
fn docstring(locator: &Locator, range: TextRange, settings: &Settings) -> Option<Diagnostic> {
|
||||
fn docstring(locator: &Locator, range: TextRange, settings: &LinterSettings) -> Option<Diagnostic> {
|
||||
let quotes_settings = &settings.flake8_quotes;
|
||||
|
||||
let text = locator.slice(range);
|
||||
|
@ -293,7 +293,11 @@ fn docstring(locator: &Locator, range: TextRange, settings: &Settings) -> Option
|
|||
}
|
||||
|
||||
/// Q001, Q002
|
||||
fn strings(locator: &Locator, sequence: &[TextRange], settings: &Settings) -> Vec<Diagnostic> {
|
||||
fn strings(
|
||||
locator: &Locator,
|
||||
sequence: &[TextRange],
|
||||
settings: &LinterSettings,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut diagnostics = vec![];
|
||||
|
||||
let quotes_settings = &settings.flake8_quotes;
|
||||
|
@ -467,7 +471,7 @@ pub(crate) fn from_tokens(
|
|||
diagnostics: &mut Vec<Diagnostic>,
|
||||
lxr: &[LexResult],
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
// Keep track of sequences of strings, which represent implicit string
|
||||
// concatenation, and should thus be handled as a single unit.
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_raise").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -13,7 +13,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::UnnecessaryReturnNone, Path::new("RET501.py"))]
|
||||
|
@ -28,7 +28,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_return").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -20,7 +20,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_self").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -30,11 +30,11 @@ mod tests {
|
|||
fn ignore_names() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_self/SLF001_extended.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_self: flake8_self::settings::Settings {
|
||||
ignore_names: vec!["_meta".to_string()],
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::PrivateMemberAccess)
|
||||
..settings::LinterSettings::for_rule(Rule::PrivateMemberAccess)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
|
|
@ -47,7 +47,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_simplify").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -19,7 +19,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_slots").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -14,14 +14,14 @@ mod tests {
|
|||
use crate::registry::Rule;
|
||||
use crate::rules::flake8_tidy_imports;
|
||||
use crate::rules::flake8_tidy_imports::settings::{ApiBan, Strictness};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test]
|
||||
fn banned_api() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID251.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
banned_api: FxHashMap::from_iter([
|
||||
(
|
||||
|
@ -39,7 +39,7 @@ mod tests {
|
|||
]),
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::BannedApi])
|
||||
..LinterSettings::for_rules(vec![Rule::BannedApi])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -50,7 +50,7 @@ mod tests {
|
|||
fn banned_api_package() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
banned_api: FxHashMap::from_iter([
|
||||
(
|
||||
|
@ -69,7 +69,7 @@ mod tests {
|
|||
..Default::default()
|
||||
},
|
||||
namespace_packages: vec![Path::new("my_package").to_path_buf()],
|
||||
..Settings::for_rules(vec![Rule::BannedApi])
|
||||
..LinterSettings::for_rules(vec![Rule::BannedApi])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -80,12 +80,12 @@ mod tests {
|
|||
fn ban_parent_imports() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID252.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
ban_relative_imports: Strictness::Parents,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::RelativeImports])
|
||||
..LinterSettings::for_rules(vec![Rule::RelativeImports])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -96,12 +96,12 @@ mod tests {
|
|||
fn ban_all_imports() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID252.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
ban_relative_imports: Strictness::All,
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::RelativeImports])
|
||||
..LinterSettings::for_rules(vec![Rule::RelativeImports])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -112,13 +112,13 @@ mod tests {
|
|||
fn ban_parent_imports_package() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
ban_relative_imports: Strictness::Parents,
|
||||
..Default::default()
|
||||
},
|
||||
namespace_packages: vec![Path::new("my_package").to_path_buf()],
|
||||
..Settings::for_rules(vec![Rule::RelativeImports])
|
||||
..LinterSettings::for_rules(vec![Rule::RelativeImports])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -129,7 +129,7 @@ mod tests {
|
|||
fn banned_module_level_imports() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_tidy_imports/TID253.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings {
|
||||
banned_module_level_imports: vec![
|
||||
"torch".to_string(),
|
||||
|
@ -137,7 +137,7 @@ mod tests {
|
|||
],
|
||||
..Default::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::BannedModuleLevelImports])
|
||||
..LinterSettings::for_rules(vec![Rule::BannedModuleLevelImports])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
|
|
@ -23,7 +23,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_todos").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -7,10 +7,10 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::{
|
||||
directives::{TodoComment, TodoDirective, TodoDirectiveKind},
|
||||
registry::Rule,
|
||||
settings::Settings,
|
||||
};
|
||||
|
||||
/// ## What it does
|
||||
|
@ -240,7 +240,7 @@ pub(crate) fn todos(
|
|||
todo_comments: &[TodoComment],
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
for todo_comment in todo_comments {
|
||||
let TodoComment {
|
||||
|
@ -303,7 +303,7 @@ pub(crate) fn todos(
|
|||
fn directive_errors(
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
directive: &TodoDirective,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
if directive.content == "TODO" {
|
||||
return;
|
||||
|
|
|
@ -39,7 +39,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -49,12 +49,12 @@ mod tests {
|
|||
fn strict(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_type_checking: super::settings::Settings {
|
||||
strict: true,
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -65,12 +65,12 @@ mod tests {
|
|||
fn exempt_modules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_type_checking: super::settings::Settings {
|
||||
exempt_modules: vec!["pandas".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -97,7 +97,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_type_checking: super::settings::Settings {
|
||||
runtime_evaluated_base_classes: vec![
|
||||
"pydantic.BaseModel".to_string(),
|
||||
|
@ -105,7 +105,7 @@ mod tests {
|
|||
],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -128,7 +128,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_type_checking: super::settings::Settings {
|
||||
runtime_evaluated_decorators: vec![
|
||||
"attrs.define".to_string(),
|
||||
|
@ -136,7 +136,7 @@ mod tests {
|
|||
],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -335,7 +335,7 @@ mod tests {
|
|||
fn contents(contents: &str, snapshot: &str) {
|
||||
let diagnostics = test_snippet(
|
||||
contents,
|
||||
&settings::Settings::for_rules(Linter::Flake8TypeChecking.rules()),
|
||||
&settings::LinterSettings::for_rules(Linter::Flake8TypeChecking.rules()),
|
||||
);
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_unused_arguments").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -33,11 +33,11 @@ mod tests {
|
|||
fn ignore_variadic_names() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_unused_arguments/ignore_variadic_names.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_unused_arguments: super::settings::Settings {
|
||||
ignore_variadic_names: true,
|
||||
},
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedFunctionArgument,
|
||||
Rule::UnusedMethodArgument,
|
||||
Rule::UnusedClassMethodArgument,
|
||||
|
@ -54,11 +54,11 @@ mod tests {
|
|||
fn enforce_variadic_names() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_unused_arguments/ignore_variadic_names.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
flake8_unused_arguments: super::settings::Settings {
|
||||
ignore_variadic_names: false,
|
||||
},
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedFunctionArgument,
|
||||
Rule::UnusedMethodArgument,
|
||||
Rule::UnusedClassMethodArgument,
|
||||
|
|
|
@ -23,7 +23,7 @@ mod tests {
|
|||
let snapshot = format!("{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_use_pathlib").join(path).as_path(),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::OsPathAbspath,
|
||||
Rule::OsChmod,
|
||||
Rule::OsMkdir,
|
||||
|
@ -67,7 +67,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_use_pathlib").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flynt").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -324,7 +324,7 @@ mod tests {
|
|||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::isort::categorize::{ImportSection, KnownModules};
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::{test_path, test_resource_path};
|
||||
|
||||
use super::categorize::ImportType;
|
||||
|
@ -383,9 +383,9 @@ mod tests {
|
|||
let snapshot = format!("{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -401,7 +401,7 @@ mod tests {
|
|||
let snapshot = format!("1_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
vec![pattern("foo.bar"), pattern("baz")],
|
||||
|
@ -413,7 +413,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -425,7 +425,7 @@ mod tests {
|
|||
let snapshot = format!("glob_1_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
vec![pattern("foo.*"), pattern("baz")],
|
||||
|
@ -437,7 +437,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -449,7 +449,7 @@ mod tests {
|
|||
let snapshot = format!("2_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
vec![pattern("foo")],
|
||||
|
@ -461,7 +461,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -477,9 +477,9 @@ mod tests {
|
|||
// Path::new("isort")
|
||||
// .join(path)
|
||||
// .as_path(),
|
||||
// &Settings {
|
||||
// &LinterSettings {
|
||||
// src: vec![test_resource_path("fixtures/isort")],
|
||||
// ..Settings::for_rule(Rule::UnsortedImports)
|
||||
// ..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
// },
|
||||
// )?;
|
||||
// crate::assert_messages!(snapshot, diagnostics);
|
||||
|
@ -491,7 +491,7 @@ mod tests {
|
|||
let snapshot = format!("known_local_folder_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
vec![],
|
||||
|
@ -503,7 +503,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -515,13 +515,13 @@ mod tests {
|
|||
let snapshot = format!("case_sensitive_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
case_sensitive: true,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -533,7 +533,7 @@ mod tests {
|
|||
let snapshot = format!("force_to_top_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
force_to_top: BTreeSet::from([
|
||||
"z".to_string(),
|
||||
|
@ -545,7 +545,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -557,13 +557,13 @@ mod tests {
|
|||
let snapshot = format!("combine_as_imports_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
combine_as_imports: true,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -575,14 +575,14 @@ mod tests {
|
|||
let snapshot = format!("force_wrap_aliases_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
force_wrap_aliases: true,
|
||||
combine_as_imports: true,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -594,13 +594,13 @@ mod tests {
|
|||
let snapshot = format!("split_on_trailing_comma_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
split_on_trailing_comma: false,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -612,7 +612,7 @@ mod tests {
|
|||
let snapshot = format!("force_single_line_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
force_single_line: true,
|
||||
single_line_exclusions: vec!["os".to_string(), "logging.handlers".to_string()]
|
||||
|
@ -621,7 +621,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -633,13 +633,13 @@ mod tests {
|
|||
let snapshot = format!("propagate_inline_comments_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
force_single_line: true,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -651,13 +651,13 @@ mod tests {
|
|||
let snapshot = format!("order_by_type_false_{}", path.to_string_lossy());
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
order_by_type: false,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -673,7 +673,7 @@ mod tests {
|
|||
);
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
order_by_type: true,
|
||||
classes: BTreeSet::from([
|
||||
|
@ -685,7 +685,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -701,7 +701,7 @@ mod tests {
|
|||
);
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
order_by_type: true,
|
||||
constants: BTreeSet::from([
|
||||
|
@ -715,7 +715,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -731,7 +731,7 @@ mod tests {
|
|||
);
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
order_by_type: true,
|
||||
variables: BTreeSet::from([
|
||||
|
@ -743,7 +743,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -756,14 +756,14 @@ mod tests {
|
|||
let snapshot = format!("force_sort_within_sections_{}", path.to_string_lossy());
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
force_sort_within_sections: true,
|
||||
force_to_top: BTreeSet::from(["z".to_string()]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -786,7 +786,7 @@ mod tests {
|
|||
let snapshot = format!("required_import_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/required_imports").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
required_imports: BTreeSet::from([
|
||||
|
@ -794,7 +794,7 @@ mod tests {
|
|||
]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MissingRequiredImport)
|
||||
..LinterSettings::for_rule(Rule::MissingRequiredImport)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -816,7 +816,7 @@ mod tests {
|
|||
let snapshot = format!("required_import_with_alias_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/required_imports").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
required_imports: BTreeSet::from([
|
||||
|
@ -824,7 +824,7 @@ mod tests {
|
|||
]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MissingRequiredImport)
|
||||
..LinterSettings::for_rule(Rule::MissingRequiredImport)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -839,7 +839,7 @@ mod tests {
|
|||
let snapshot = format!("required_imports_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/required_imports").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
required_imports: BTreeSet::from([
|
||||
|
@ -848,7 +848,7 @@ mod tests {
|
|||
]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MissingRequiredImport)
|
||||
..LinterSettings::for_rule(Rule::MissingRequiredImport)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -863,7 +863,7 @@ mod tests {
|
|||
let snapshot = format!("combined_required_imports_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/required_imports").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
required_imports: BTreeSet::from(["from __future__ import annotations, \
|
||||
|
@ -871,7 +871,7 @@ mod tests {
|
|||
.to_string()]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MissingRequiredImport)
|
||||
..LinterSettings::for_rule(Rule::MissingRequiredImport)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -886,13 +886,13 @@ mod tests {
|
|||
let snapshot = format!("straight_required_import_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/required_imports").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
required_imports: BTreeSet::from(["import os".to_string()]),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MissingRequiredImport)
|
||||
..LinterSettings::for_rule(Rule::MissingRequiredImport)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -904,13 +904,13 @@ mod tests {
|
|||
let snapshot = format!("closest_to_furthest_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
relative_imports_order: RelativeImportsOrder::ClosestToFurthest,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -922,7 +922,7 @@ mod tests {
|
|||
let snapshot = format!("no_lines_before.py_{}", path.to_string_lossy());
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
no_lines_before: BTreeSet::from([
|
||||
ImportSection::Known(ImportType::Future),
|
||||
|
@ -934,7 +934,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -950,7 +950,7 @@ mod tests {
|
|||
);
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
no_lines_before: BTreeSet::from([
|
||||
ImportSection::Known(ImportType::StandardLibrary),
|
||||
|
@ -959,7 +959,7 @@ mod tests {
|
|||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -974,13 +974,13 @@ mod tests {
|
|||
let snapshot = format!("lines_after_imports_{}", path.to_string_lossy());
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
lines_after_imports: 3,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -993,13 +993,13 @@ mod tests {
|
|||
let snapshot = format!("lines_between_types{}", path.to_string_lossy());
|
||||
let mut diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
isort: super::settings::Settings {
|
||||
lines_between_types: 2,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
diagnostics.sort_by_key(Ranged::start);
|
||||
|
@ -1012,7 +1012,7 @@ mod tests {
|
|||
let snapshot = format!("{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
forced_separate: vec![
|
||||
|
@ -1023,7 +1023,7 @@ mod tests {
|
|||
],
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -1035,7 +1035,7 @@ mod tests {
|
|||
let snapshot = format!("sections_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
|
@ -1056,7 +1056,7 @@ mod tests {
|
|||
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -1068,7 +1068,7 @@ mod tests {
|
|||
let snapshot = format!("section_order_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort").join(path).as_path(),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![test_resource_path("fixtures/isort")],
|
||||
isort: super::settings::Settings {
|
||||
known_modules: KnownModules::new(
|
||||
|
@ -1088,7 +1088,7 @@ mod tests {
|
|||
],
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -1099,13 +1099,13 @@ mod tests {
|
|||
fn detect_same_package() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/detect_same_package/foo/bar.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![],
|
||||
isort: super::settings::Settings {
|
||||
detect_same_package: true,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -1116,13 +1116,13 @@ mod tests {
|
|||
fn no_detect_same_package() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("isort/detect_same_package/foo/bar.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
src: vec![],
|
||||
isort: super::settings::Settings {
|
||||
detect_same_package: false,
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::UnsortedImports)
|
||||
..LinterSettings::for_rule(Rule::UnsortedImports)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
|
|
@ -12,7 +12,7 @@ use ruff_text_size::{TextRange, TextSize};
|
|||
|
||||
use crate::importer::Importer;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Adds any required imports, as specified by the user, to the top of the
|
||||
|
@ -90,7 +90,7 @@ fn add_required_import(
|
|||
python_ast: &Suite,
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
source_type: PySourceType,
|
||||
) -> Option<Diagnostic> {
|
||||
// Don't add imports to semantically-empty files.
|
||||
|
@ -130,7 +130,7 @@ pub(crate) fn add_required_imports(
|
|||
python_ast: &Suite,
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
source_type: PySourceType,
|
||||
) -> Vec<Diagnostic> {
|
||||
settings
|
||||
|
|
|
@ -14,7 +14,7 @@ use ruff_text_size::{Ranged, TextRange};
|
|||
|
||||
use crate::line_width::LineWidthBuilder;
|
||||
use crate::registry::AsRule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use super::super::block::Block;
|
||||
use super::super::{comments, format_imports};
|
||||
|
@ -85,7 +85,7 @@ pub(crate) fn organize_imports(
|
|||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
package: Option<&Path>,
|
||||
source_type: PySourceType,
|
||||
) -> Option<Diagnostic> {
|
||||
|
|
|
@ -11,7 +11,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(0)]
|
||||
|
@ -21,9 +21,9 @@ mod tests {
|
|||
let snapshot = format!("max_complexity_{max_complexity}");
|
||||
let diagnostics = test_path(
|
||||
Path::new("mccabe/C901.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
mccabe: super::settings::Settings { max_complexity },
|
||||
..Settings::for_rules(vec![Rule::ComplexStructure])
|
||||
..LinterSettings::for_rules(vec![Rule::ComplexStructure])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -20,7 +20,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("numpy").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -351,7 +351,7 @@ mod tests {
|
|||
fn contents(contents: &str, snapshot: &str) {
|
||||
let diagnostics = test_snippet(
|
||||
contents,
|
||||
&settings::Settings::for_rules(Linter::PandasVet.rules()),
|
||||
&settings::LinterSettings::for_rules(Linter::PandasVet.rules()),
|
||||
);
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pandas_vet").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -79,8 +79,8 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pep8_naming").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
&settings::LinterSettings {
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -91,7 +91,7 @@ mod tests {
|
|||
fn classmethod_decorators() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pep8_naming").join("N805.py").as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pep8_naming: pep8_naming::settings::Settings {
|
||||
classmethod_decorators: vec![
|
||||
"classmethod".to_string(),
|
||||
|
@ -99,7 +99,7 @@ mod tests {
|
|||
],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::InvalidFirstArgumentNameForMethod)
|
||||
..settings::LinterSettings::for_rule(Rule::InvalidFirstArgumentNameForMethod)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -126,7 +126,7 @@ mod tests {
|
|||
let snapshot = format!("ignore_names_{}_{path}", rule_code.noqa_code());
|
||||
let diagnostics = test_path(
|
||||
PathBuf::from_iter(["pep8_naming", "ignore_names", path]).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pep8_naming: pep8_naming::settings::Settings {
|
||||
ignore_names: vec![
|
||||
IdentifierPattern::new("*allowed*").unwrap(),
|
||||
|
@ -136,7 +136,7 @@ mod tests {
|
|||
],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -11,7 +11,7 @@ mod tests {
|
|||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::types::PythonVersion;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::UnnecessaryListCast, Path::new("PERF101.py"))]
|
||||
|
@ -24,7 +24,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("perflint").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code).with_target_version(PythonVersion::Py310),
|
||||
&LinterSettings::for_rule(rule_code).with_target_version(PythonVersion::Py310),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -52,7 +52,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -62,7 +62,7 @@ mod tests {
|
|||
fn w292_4() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/W292_4.py"),
|
||||
&settings::Settings::for_rule(Rule::MissingNewlineAtEndOfFile),
|
||||
&settings::LinterSettings::for_rule(Rule::MissingNewlineAtEndOfFile),
|
||||
)?;
|
||||
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -112,7 +112,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -122,7 +122,7 @@ mod tests {
|
|||
fn constant_literals() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/constant_literals.py"),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::NoneComparison,
|
||||
Rule::TrueFalseComparison,
|
||||
Rule::IsLiteral,
|
||||
|
@ -136,7 +136,7 @@ mod tests {
|
|||
fn shebang() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/shebang.py"),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::TooFewSpacesBeforeInlineComment,
|
||||
Rule::NoSpaceAfterInlineComment,
|
||||
Rule::NoSpaceAfterBlockComment,
|
||||
|
@ -153,12 +153,12 @@ mod tests {
|
|||
let snapshot = format!("task_tags_{ignore_overlong_task_comments}");
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/E501_1.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pycodestyle: Settings {
|
||||
ignore_overlong_task_comments,
|
||||
..Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::LineTooLong)
|
||||
..settings::LinterSettings::for_rule(Rule::LineTooLong)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -169,12 +169,12 @@ mod tests {
|
|||
fn max_doc_length() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/W505.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pycodestyle: Settings {
|
||||
max_doc_length: Some(LineLength::try_from(50).unwrap()),
|
||||
..Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::DocLineTooLong)
|
||||
..settings::LinterSettings::for_rule(Rule::DocLineTooLong)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -185,12 +185,12 @@ mod tests {
|
|||
fn max_doc_length_with_utf_8() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/W505_utf_8.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pycodestyle: Settings {
|
||||
max_doc_length: Some(LineLength::try_from(50).unwrap()),
|
||||
..Settings::default()
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::DocLineTooLong)
|
||||
..settings::LinterSettings::for_rule(Rule::DocLineTooLong)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -205,10 +205,10 @@ mod tests {
|
|||
let snapshot = format!("tab_size_{tab_size}");
|
||||
let diagnostics = test_path(
|
||||
Path::new("pycodestyle/E501_2.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
tab_size: NonZeroU8::new(tab_size).unwrap().into(),
|
||||
line_length: LineLength::try_from(6).unwrap(),
|
||||
..settings::Settings::for_rule(Rule::LineTooLong)
|
||||
..settings::LinterSettings::for_rule(Rule::LineTooLong)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
|
|
@ -9,7 +9,7 @@ use ruff_python_index::Indexer;
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for compound statements (multiple statements on the same line).
|
||||
|
@ -104,7 +104,7 @@ pub(crate) fn compound_statements(
|
|||
lxr: &[LexResult],
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
// Track the last seen instance of a variety of tokens.
|
||||
let mut colon = None;
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use ruff_source_file::Line;
|
||||
|
||||
use crate::rules::pycodestyle::helpers::is_overlong;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for doc lines that exceed the specified maximum character length.
|
||||
|
@ -61,7 +61,7 @@ impl Violation for DocLineTooLong {
|
|||
}
|
||||
|
||||
/// W505
|
||||
pub(crate) fn doc_line_too_long(line: &Line, settings: &Settings) -> Option<Diagnostic> {
|
||||
pub(crate) fn doc_line_too_long(line: &Line, settings: &LinterSettings) -> Option<Diagnostic> {
|
||||
let Some(limit) = settings.pycodestyle.max_doc_length else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use ruff_source_file::Line;
|
||||
|
||||
use crate::rules::pycodestyle::helpers::is_overlong;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for lines that exceed the specified maximum character length.
|
||||
|
@ -55,7 +55,7 @@ impl Violation for LineTooLong {
|
|||
}
|
||||
|
||||
/// E501
|
||||
pub(crate) fn line_too_long(line: &Line, settings: &Settings) -> Option<Diagnostic> {
|
||||
pub(crate) fn line_too_long(line: &Line, settings: &LinterSettings) -> Option<Diagnostic> {
|
||||
let limit = settings.line_length;
|
||||
|
||||
is_overlong(
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_source_file::{Line, Locator};
|
|||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for superfluous trailing whitespace.
|
||||
|
@ -76,7 +76,7 @@ pub(crate) fn trailing_whitespace(
|
|||
line: &Line,
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Option<Diagnostic> {
|
||||
let whitespace_len: TextSize = line
|
||||
.chars()
|
||||
|
|
|
@ -90,7 +90,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle").join(path).as_path(),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pydocstyle: Settings {
|
||||
convention: None,
|
||||
ignore_decorators: BTreeSet::from_iter(["functools.wraps".to_string()]),
|
||||
|
@ -98,7 +98,7 @@ mod tests {
|
|||
"gi.repository.GObject.Property".to_string()
|
||||
]),
|
||||
},
|
||||
..settings::Settings::for_rule(rule_code)
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -109,7 +109,7 @@ mod tests {
|
|||
fn bom() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/bom.py"),
|
||||
&settings::Settings::for_rule(Rule::TripleSingleQuotes),
|
||||
&settings::LinterSettings::for_rule(Rule::TripleSingleQuotes),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -119,7 +119,7 @@ mod tests {
|
|||
fn d417_unspecified() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/D417.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
// When inferring the convention, we'll see a few false negatives.
|
||||
// See: https://github.com/PyCQA/pydocstyle/issues/459.
|
||||
pydocstyle: Settings {
|
||||
|
@ -127,7 +127,7 @@ mod tests {
|
|||
ignore_decorators: BTreeSet::new(),
|
||||
property_decorators: BTreeSet::new(),
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::UndocumentedParam)
|
||||
..settings::LinterSettings::for_rule(Rule::UndocumentedParam)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -138,14 +138,14 @@ mod tests {
|
|||
fn d417_google() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/D417.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
// With explicit Google convention, we should flag every function.
|
||||
pydocstyle: Settings {
|
||||
convention: Some(Convention::Google),
|
||||
ignore_decorators: BTreeSet::new(),
|
||||
property_decorators: BTreeSet::new(),
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::UndocumentedParam)
|
||||
..settings::LinterSettings::for_rule(Rule::UndocumentedParam)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -156,14 +156,14 @@ mod tests {
|
|||
fn d417_numpy() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/D417.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
// With explicit Google convention, we shouldn't flag anything.
|
||||
pydocstyle: Settings {
|
||||
convention: Some(Convention::Numpy),
|
||||
ignore_decorators: BTreeSet::new(),
|
||||
property_decorators: BTreeSet::new(),
|
||||
},
|
||||
..settings::Settings::for_rule(Rule::UndocumentedParam)
|
||||
..settings::LinterSettings::for_rule(Rule::UndocumentedParam)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -174,7 +174,10 @@ mod tests {
|
|||
fn d209_d400() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/D209_D400.py"),
|
||||
&settings::Settings::for_rules([Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod]),
|
||||
&settings::LinterSettings::for_rules([
|
||||
Rule::NewLineAfterLastParagraph,
|
||||
Rule::EndsInPeriod,
|
||||
]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -184,7 +187,7 @@ mod tests {
|
|||
fn all() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle/all.py"),
|
||||
&settings::Settings::for_rules([
|
||||
&settings::LinterSettings::for_rules([
|
||||
Rule::UndocumentedPublicModule,
|
||||
Rule::UndocumentedPublicClass,
|
||||
Rule::UndocumentedPublicMethod,
|
||||
|
|
|
@ -26,7 +26,7 @@ mod tests {
|
|||
use crate::linter::{check_path, LinterResult};
|
||||
use crate::registry::{AsRule, Linter, Rule};
|
||||
use crate::rules::pyflakes;
|
||||
use crate::settings::{flags, Settings};
|
||||
use crate::settings::{flags, LinterSettings};
|
||||
use crate::source_kind::SourceKind;
|
||||
use crate::test::{test_path, test_snippet};
|
||||
use crate::{assert_messages, directives};
|
||||
|
@ -147,7 +147,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -157,9 +157,9 @@ mod tests {
|
|||
fn f841_dummy_variable_rgx() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/F841_0.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
dummy_variable_rgx: Regex::new(r"^z$").unwrap(),
|
||||
..Settings::for_rule(Rule::UnusedVariable)
|
||||
..LinterSettings::for_rule(Rule::UnusedVariable)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -170,7 +170,7 @@ mod tests {
|
|||
fn init() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/__init__.py"),
|
||||
&Settings::for_rules(vec![Rule::UndefinedName, Rule::UndefinedExport]),
|
||||
&LinterSettings::for_rules(vec![Rule::UndefinedName, Rule::UndefinedExport]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -180,7 +180,7 @@ mod tests {
|
|||
fn default_builtins() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/builtins.py"),
|
||||
&Settings::for_rules(vec![Rule::UndefinedName]),
|
||||
&LinterSettings::for_rules(vec![Rule::UndefinedName]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -190,9 +190,9 @@ mod tests {
|
|||
fn extra_builtins() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/builtins.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
builtins: vec!["_".to_string()],
|
||||
..Settings::for_rules(vec![Rule::UndefinedName])
|
||||
..LinterSettings::for_rules(vec![Rule::UndefinedName])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -203,7 +203,7 @@ mod tests {
|
|||
fn default_typing_modules() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/typing_modules.py"),
|
||||
&Settings::for_rules(vec![Rule::UndefinedName]),
|
||||
&LinterSettings::for_rules(vec![Rule::UndefinedName]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -213,9 +213,9 @@ mod tests {
|
|||
fn extra_typing_modules() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/typing_modules.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
typing_modules: vec!["airflow.typing_compat".to_string()],
|
||||
..Settings::for_rules(vec![Rule::UndefinedName])
|
||||
..LinterSettings::for_rules(vec![Rule::UndefinedName])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -226,7 +226,7 @@ mod tests {
|
|||
fn future_annotations() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/future_annotations.py"),
|
||||
&Settings::for_rules(vec![Rule::UnusedImport, Rule::UndefinedName]),
|
||||
&LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UndefinedName]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -236,7 +236,7 @@ mod tests {
|
|||
fn multi_statement_lines() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/multi_statement_lines.py"),
|
||||
&Settings::for_rule(Rule::UnusedImport),
|
||||
&LinterSettings::for_rule(Rule::UnusedImport),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -246,9 +246,9 @@ mod tests {
|
|||
fn relative_typing_module() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/project/foo/bar.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
typing_modules: vec!["foo.typical".to_string()],
|
||||
..Settings::for_rules(vec![Rule::UndefinedName])
|
||||
..LinterSettings::for_rules(vec![Rule::UndefinedName])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -259,9 +259,9 @@ mod tests {
|
|||
fn nested_relative_typing_module() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/project/foo/bop/baz.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
typing_modules: vec!["foo.typical".to_string()],
|
||||
..Settings::for_rules(vec![Rule::UndefinedName])
|
||||
..LinterSettings::for_rules(vec![Rule::UndefinedName])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -273,11 +273,11 @@ mod tests {
|
|||
let snapshot = "extend_immutable_calls".to_string();
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyflakes/F401_15.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pyflakes: pyflakes::settings::Settings {
|
||||
extend_generics: vec!["django.db.models.ForeignKey".to_string()],
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::UnusedImport])
|
||||
..LinterSettings::for_rules(vec![Rule::UnusedImport])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -500,7 +500,10 @@ mod tests {
|
|||
"load_after_unbind_from_class_scope"
|
||||
)]
|
||||
fn contents(contents: &str, snapshot: &str) {
|
||||
let diagnostics = test_snippet(contents, &Settings::for_rules(Linter::Pyflakes.rules()));
|
||||
let diagnostics = test_snippet(
|
||||
contents,
|
||||
&LinterSettings::for_rules(Linter::Pyflakes.rules()),
|
||||
);
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
}
|
||||
|
||||
|
@ -510,7 +513,7 @@ mod tests {
|
|||
let contents = dedent(contents);
|
||||
let source_type = PySourceType::default();
|
||||
let source_kind = SourceKind::Python(contents.to_string());
|
||||
let settings = Settings::for_rules(Linter::Pyflakes.rules());
|
||||
let settings = LinterSettings::for_rules(Linter::Pyflakes.rules());
|
||||
let tokens: Vec<LexResult> = ruff_python_parser::tokenize(&contents, source_type.as_mode());
|
||||
let locator = Locator::new(&contents);
|
||||
let stylist = Stylist::from_tokens(&tokens, &locator);
|
||||
|
|
|
@ -24,7 +24,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pygrep_hooks").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_python_ast::{Arguments, CmpOp, Constant, Expr};
|
|||
use ruff_python_semantic::analyze::function_type;
|
||||
use ruff_python_semantic::{ScopeKind, SemanticModel};
|
||||
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// Returns the value of the `name` parameter to, e.g., a `TypeVar` constructor.
|
||||
pub(super) fn type_param_name(arguments: &Arguments) -> Option<&str> {
|
||||
|
@ -22,7 +22,7 @@ pub(super) fn type_param_name(arguments: &Arguments) -> Option<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn in_dunder_init(semantic: &SemanticModel, settings: &Settings) -> bool {
|
||||
pub(super) fn in_dunder_init(semantic: &SemanticModel, settings: &LinterSettings) -> bool {
|
||||
let scope = semantic.current_scope();
|
||||
let ScopeKind::Function(ast::StmtFunctionDef {
|
||||
name,
|
||||
|
|
|
@ -15,7 +15,7 @@ mod tests {
|
|||
use crate::registry::Rule;
|
||||
use crate::rules::pylint;
|
||||
use crate::settings::types::PythonVersion;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
#[test_case(Rule::AssertOnStringLiteral, Path::new("assert_on_string_literal.py"))]
|
||||
|
@ -137,7 +137,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint").join(path).as_path(),
|
||||
&Settings::for_rule(rule_code),
|
||||
&LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -147,7 +147,7 @@ mod tests {
|
|||
fn repeated_isinstance_calls() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/repeated_isinstance_calls.py"),
|
||||
&Settings::for_rule(Rule::RepeatedIsinstanceCalls)
|
||||
&LinterSettings::for_rule(Rule::RepeatedIsinstanceCalls)
|
||||
.with_target_version(PythonVersion::Py39),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -158,7 +158,8 @@ mod tests {
|
|||
fn continue_in_finally() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/continue_in_finally.py"),
|
||||
&Settings::for_rule(Rule::ContinueInFinally).with_target_version(PythonVersion::Py37),
|
||||
&LinterSettings::for_rule(Rule::ContinueInFinally)
|
||||
.with_target_version(PythonVersion::Py37),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -168,12 +169,12 @@ mod tests {
|
|||
fn allow_magic_value_types() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/magic_value_comparison.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
allow_magic_value_types: vec![pylint::settings::ConstantType::Int],
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::MagicValueComparison)
|
||||
..LinterSettings::for_rule(Rule::MagicValueComparison)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -184,12 +185,12 @@ mod tests {
|
|||
fn max_args() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_arguments_params.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
max_args: 4,
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::TooManyArguments)
|
||||
..LinterSettings::for_rule(Rule::TooManyArguments)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -200,9 +201,9 @@ mod tests {
|
|||
fn max_args_with_dummy_variables() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_arguments_params.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
dummy_variable_rgx: Regex::new(r"skip_.*").unwrap(),
|
||||
..Settings::for_rule(Rule::TooManyArguments)
|
||||
..LinterSettings::for_rule(Rule::TooManyArguments)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -213,12 +214,12 @@ mod tests {
|
|||
fn max_branches() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_branches_params.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
max_branches: 1,
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::TooManyBranches)
|
||||
..LinterSettings::for_rule(Rule::TooManyBranches)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -229,12 +230,12 @@ mod tests {
|
|||
fn max_statements() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_statements_params.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
max_statements: 1,
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::TooManyStatements)
|
||||
..LinterSettings::for_rule(Rule::TooManyStatements)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -245,12 +246,12 @@ mod tests {
|
|||
fn max_return_statements() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_return_statements_params.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
max_returns: 1,
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rule(Rule::TooManyReturnStatements)
|
||||
..LinterSettings::for_rule(Rule::TooManyReturnStatements)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -261,12 +262,12 @@ mod tests {
|
|||
fn too_many_public_methods() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint/too_many_public_methods.py"),
|
||||
&Settings {
|
||||
&LinterSettings {
|
||||
pylint: pylint::settings::Settings {
|
||||
max_public_methods: 7,
|
||||
..pylint::settings::Settings::default()
|
||||
},
|
||||
..Settings::for_rules(vec![Rule::TooManyPublicMethods])
|
||||
..LinterSettings::for_rules(vec![Rule::TooManyPublicMethods])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
|
|
@ -87,7 +87,7 @@ mod tests {
|
|||
let snapshot = path.to_string_lossy().to_string();
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -97,9 +97,9 @@ mod tests {
|
|||
fn non_pep695_type_alias_not_applied_py311() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/UP040.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py311,
|
||||
..settings::Settings::for_rule(Rule::NonPEP695TypeAlias)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP695TypeAlias)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -110,12 +110,12 @@ mod tests {
|
|||
fn future_annotations_keep_runtime_typing_p37() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pyupgrade: pyupgrade::settings::Settings {
|
||||
keep_runtime_typing: true,
|
||||
},
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::NonPEP585Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -126,12 +126,12 @@ mod tests {
|
|||
fn future_annotations_keep_runtime_typing_p310() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
pyupgrade: pyupgrade::settings::Settings {
|
||||
keep_runtime_typing: true,
|
||||
},
|
||||
target_version: PythonVersion::Py310,
|
||||
..settings::Settings::for_rule(Rule::NonPEP585Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -142,9 +142,9 @@ mod tests {
|
|||
fn future_annotations_pep_585_p37() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::NonPEP585Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -155,9 +155,9 @@ mod tests {
|
|||
fn future_annotations_pep_585_py310() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py310,
|
||||
..settings::Settings::for_rule(Rule::NonPEP585Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -168,9 +168,9 @@ mod tests {
|
|||
fn future_annotations_pep_604_p37() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::NonPEP604Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP604Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -181,9 +181,9 @@ mod tests {
|
|||
fn future_annotations_pep_604_py310() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py310,
|
||||
..settings::Settings::for_rule(Rule::NonPEP604Annotation)
|
||||
..settings::LinterSettings::for_rule(Rule::NonPEP604Annotation)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
@ -194,9 +194,9 @@ mod tests {
|
|||
fn datetime_utc_alias_py311() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("pyupgrade/UP017.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
target_version: PythonVersion::Py311,
|
||||
..settings::Settings::for_rule(Rule::DatetimeTimezoneUTC)
|
||||
..settings::LinterSettings::for_rule(Rule::DatetimeTimezoneUTC)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
|
|
|
@ -7,7 +7,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for extraneous parentheses.
|
||||
|
@ -137,7 +137,7 @@ pub(crate) fn extraneous_parentheses(
|
|||
diagnostics: &mut Vec<Diagnostic>,
|
||||
tokens: &[LexResult],
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
let mut i = 0;
|
||||
while i < tokens.len() {
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruff_source_file::Locator;
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::registry::AsRule;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary UTF-8 encoding declarations.
|
||||
|
@ -52,7 +52,7 @@ pub(crate) fn unnecessary_coding_comment(
|
|||
diagnostics: &mut Vec<Diagnostic>,
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
// The coding comment must be on one of the first two lines. Since each comment spans at least
|
||||
// one line, we only need to check the first two comments at most.
|
||||
|
|
|
@ -24,7 +24,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("refurb").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -45,7 +45,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
@ -61,7 +61,7 @@ mod tests {
|
|||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff").join(path).as_path(),
|
||||
&settings::Settings::for_rule(Rule::ImplicitOptional)
|
||||
&settings::LinterSettings::for_rule(Rule::ImplicitOptional)
|
||||
.with_target_version(PythonVersion::Py39),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
|
@ -72,9 +72,9 @@ mod tests {
|
|||
fn confusables() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/confusables.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
allowed_confusables: FxHashSet::from_iter(['−', 'ρ', '∗']),
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::AmbiguousUnicodeCharacterString,
|
||||
Rule::AmbiguousUnicodeCharacterDocstring,
|
||||
Rule::AmbiguousUnicodeCharacterComment,
|
||||
|
@ -89,7 +89,10 @@ mod tests {
|
|||
fn noqa() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/noqa.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedVariable, Rule::AmbiguousVariableName]),
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedVariable,
|
||||
Rule::AmbiguousVariableName,
|
||||
]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -99,9 +102,9 @@ mod tests {
|
|||
fn ruf100_0() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_0.py"),
|
||||
&settings::Settings {
|
||||
&settings::LinterSettings {
|
||||
external: FxHashSet::from_iter(vec!["V101".to_string()]),
|
||||
..settings::Settings::for_rules(vec![
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedNOQA,
|
||||
Rule::LineTooLong,
|
||||
Rule::UnusedImport,
|
||||
|
@ -118,7 +121,7 @@ mod tests {
|
|||
fn ruf100_1() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_1.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -127,7 +130,7 @@ mod tests {
|
|||
#[test]
|
||||
fn ruf100_2() -> Result<()> {
|
||||
let mut settings =
|
||||
settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]);
|
||||
settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]);
|
||||
|
||||
settings.per_file_ignores = resolve_per_file_ignores(vec![PerFileIgnore::new(
|
||||
"RUF100_2.py".to_string(),
|
||||
|
@ -145,7 +148,7 @@ mod tests {
|
|||
fn ruf100_3() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_3.py"),
|
||||
&settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedNOQA,
|
||||
Rule::LineTooLong,
|
||||
Rule::UndefinedName,
|
||||
|
@ -159,7 +162,7 @@ mod tests {
|
|||
fn ruf100_4() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_4.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -169,8 +172,8 @@ mod tests {
|
|||
fn ruf100_5() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_5.py"),
|
||||
&settings::Settings {
|
||||
..settings::Settings::for_rules(vec![
|
||||
&settings::LinterSettings {
|
||||
..settings::LinterSettings::for_rules(vec![
|
||||
Rule::UnusedNOQA,
|
||||
Rule::LineTooLong,
|
||||
Rule::CommentedOutCode,
|
||||
|
@ -184,7 +187,7 @@ mod tests {
|
|||
fn flake8_noqa() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/flake8_noqa.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -194,7 +197,7 @@ mod tests {
|
|||
fn ruff_noqa_all() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/ruff_noqa_all.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -204,7 +207,7 @@ mod tests {
|
|||
fn ruff_noqa_codes() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/ruff_noqa_codes.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -214,7 +217,7 @@ mod tests {
|
|||
fn ruff_noqa_invalid() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/ruff_noqa_invalid.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -224,7 +227,7 @@ mod tests {
|
|||
fn redirects() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/redirects.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::NonPEP604Annotation]),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::NonPEP604Annotation]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
|
@ -245,7 +248,7 @@ mod tests {
|
|||
let source_file = SourceFileBuilder::new("pyproject.toml", contents).finish();
|
||||
let messages = lint_pyproject_toml(
|
||||
source_file,
|
||||
&settings::Settings::for_rule(Rule::InvalidPyprojectToml),
|
||||
&settings::LinterSettings::for_rule(Rule::InvalidPyprojectToml),
|
||||
);
|
||||
assert_messages!(snapshot, messages);
|
||||
Ok(())
|
||||
|
|
|
@ -10,7 +10,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
use crate::registry::AsRule;
|
||||
use crate::rules::ruff::rules::confusables::confusable;
|
||||
use crate::rules::ruff::rules::Context;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for ambiguous unicode characters in strings.
|
||||
|
@ -128,7 +128,7 @@ pub(crate) fn ambiguous_unicode_character(
|
|||
locator: &Locator,
|
||||
range: TextRange,
|
||||
context: Context,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) {
|
||||
let text = locator.slice(range);
|
||||
|
||||
|
@ -241,7 +241,7 @@ impl Candidate {
|
|||
}
|
||||
}
|
||||
|
||||
fn into_diagnostic(self, context: Context, settings: &Settings) -> Option<Diagnostic> {
|
||||
fn into_diagnostic(self, context: Context, settings: &LinterSettings) -> Option<Diagnostic> {
|
||||
if !settings.allowed_confusables.contains(&self.confusable) {
|
||||
let char_range = TextRange::at(self.offset, self.confusable.text_len());
|
||||
let diagnostic = Diagnostic::new::<DiagnosticKind>(
|
||||
|
|
|
@ -28,7 +28,7 @@ mod tests {
|
|||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("tryceratops").join(path).as_path(),
|
||||
&settings::Settings::for_rule(rule_code),
|
||||
&settings::LinterSettings::for_rule(rule_code),
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
|
|
|
@ -1,96 +1 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use path_absolutize::path_dedot;
|
||||
use regex::Regex;
|
||||
use ruff_cache::cache_dir;
|
||||
use rustc_hash::FxHashSet;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::types::{PreviewMode, PythonVersion};
|
||||
use super::Settings;
|
||||
use crate::codes::{self, RuleCodePrefix};
|
||||
use crate::line_width::{LineLength, TabSize};
|
||||
use crate::registry::Linter;
|
||||
use crate::rule_selector::RuleSelector;
|
||||
use crate::rules::{
|
||||
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions,
|
||||
flake8_copyright, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat,
|
||||
flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self,
|
||||
flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming,
|
||||
pycodestyle, pydocstyle, pyflakes, pylint, pyupgrade,
|
||||
};
|
||||
use crate::settings::types::SerializationFormat;
|
||||
use crate::settings::FileResolverSettings;
|
||||
|
||||
pub const PREFIXES: &[RuleSelector] = &[
|
||||
RuleSelector::Prefix {
|
||||
prefix: RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E),
|
||||
redirected_from: None,
|
||||
},
|
||||
RuleSelector::Linter(Linter::Pyflakes),
|
||||
];
|
||||
|
||||
pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];
|
||||
|
||||
pub static DUMMY_VARIABLE_RGX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$").unwrap());
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
let project_root = path_dedot::CWD.clone();
|
||||
Self {
|
||||
cache_dir: cache_dir(&project_root),
|
||||
fix: false,
|
||||
fix_only: false,
|
||||
output_format: SerializationFormat::default(),
|
||||
show_fixes: false,
|
||||
show_source: false,
|
||||
|
||||
file_resolver: FileResolverSettings::with_project_root(project_root),
|
||||
|
||||
rules: PREFIXES
|
||||
.iter()
|
||||
.flat_map(|selector| selector.rules(PreviewMode::default()))
|
||||
.collect(),
|
||||
allowed_confusables: FxHashSet::from_iter([]),
|
||||
builtins: vec![],
|
||||
dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone(),
|
||||
external: HashSet::default(),
|
||||
ignore_init_module_imports: false,
|
||||
line_length: LineLength::default(),
|
||||
logger_objects: vec![],
|
||||
namespace_packages: vec![],
|
||||
preview: PreviewMode::default(),
|
||||
per_file_ignores: vec![],
|
||||
|
||||
src: vec![path_dedot::CWD.clone()],
|
||||
tab_size: TabSize::default(),
|
||||
target_version: PythonVersion::default(),
|
||||
task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(),
|
||||
typing_modules: vec![],
|
||||
flake8_annotations: flake8_annotations::settings::Settings::default(),
|
||||
flake8_bandit: flake8_bandit::settings::Settings::default(),
|
||||
flake8_bugbear: flake8_bugbear::settings::Settings::default(),
|
||||
flake8_builtins: flake8_builtins::settings::Settings::default(),
|
||||
flake8_comprehensions: flake8_comprehensions::settings::Settings::default(),
|
||||
flake8_copyright: flake8_copyright::settings::Settings::default(),
|
||||
flake8_errmsg: flake8_errmsg::settings::Settings::default(),
|
||||
flake8_implicit_str_concat: flake8_implicit_str_concat::settings::Settings::default(),
|
||||
flake8_import_conventions: flake8_import_conventions::settings::Settings::default(),
|
||||
flake8_pytest_style: flake8_pytest_style::settings::Settings::default(),
|
||||
flake8_quotes: flake8_quotes::settings::Settings::default(),
|
||||
flake8_gettext: flake8_gettext::settings::Settings::default(),
|
||||
flake8_self: flake8_self::settings::Settings::default(),
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings::default(),
|
||||
flake8_type_checking: flake8_type_checking::settings::Settings::default(),
|
||||
flake8_unused_arguments: flake8_unused_arguments::settings::Settings::default(),
|
||||
isort: isort::settings::Settings::default(),
|
||||
mccabe: mccabe::settings::Settings::default(),
|
||||
pep8_naming: pep8_naming::settings::Settings::default(),
|
||||
pycodestyle: pycodestyle::settings::Settings::default(),
|
||||
pydocstyle: pydocstyle::settings::Settings::default(),
|
||||
pyflakes: pyflakes::settings::Settings::default(),
|
||||
pylint: pylint::settings::Settings::default(),
|
||||
pyupgrade: pyupgrade::settings::Settings::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,21 @@
|
|||
//! command-line options. Structure is optimized for internal usage, as opposed
|
||||
//! to external visibility or parsing.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use globset::{Glob, GlobMatcher};
|
||||
use once_cell::sync::Lazy;
|
||||
use path_absolutize::path_dedot;
|
||||
use regex::Regex;
|
||||
use ruff_cache::cache_dir;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::codes::RuleCodePrefix;
|
||||
use ruff_macros::CacheKey;
|
||||
|
||||
use crate::registry::{Rule, RuleSet};
|
||||
use crate::registry::{Linter, Rule, RuleSet};
|
||||
use crate::rules::{
|
||||
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions,
|
||||
flake8_copyright, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat,
|
||||
|
@ -23,13 +27,13 @@ use crate::rules::{
|
|||
use crate::settings::types::{
|
||||
FilePattern, FilePatternSet, PerFileIgnore, PythonVersion, SerializationFormat,
|
||||
};
|
||||
use crate::{codes, RuleSelector};
|
||||
|
||||
use super::line_width::{LineLength, TabSize};
|
||||
|
||||
use self::rule_table::RuleTable;
|
||||
use self::types::PreviewMode;
|
||||
|
||||
pub mod defaults;
|
||||
pub mod flags;
|
||||
pub mod rule_table;
|
||||
pub mod types;
|
||||
|
@ -84,9 +88,9 @@ pub struct FileResolverSettings {
|
|||
}
|
||||
|
||||
impl FileResolverSettings {
|
||||
fn with_project_root(project_root: PathBuf) -> Self {
|
||||
fn with_project_root(project_root: &Path) -> Self {
|
||||
Self {
|
||||
project_root,
|
||||
project_root: project_root.to_path_buf(),
|
||||
exclude: FilePatternSet::try_from_vec(EXCLUDE.clone()).unwrap(),
|
||||
extend_exclude: FilePatternSet::default(),
|
||||
extend_include: FilePatternSet::default(),
|
||||
|
@ -98,22 +102,8 @@ impl FileResolverSettings {
|
|||
}
|
||||
|
||||
#[derive(Debug, CacheKey)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct Settings {
|
||||
#[cache_key(ignore)]
|
||||
pub cache_dir: PathBuf,
|
||||
#[cache_key(ignore)]
|
||||
pub fix: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub fix_only: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub output_format: SerializationFormat,
|
||||
#[cache_key(ignore)]
|
||||
pub show_fixes: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub show_source: bool,
|
||||
|
||||
pub file_resolver: FileResolverSettings,
|
||||
pub struct LinterSettings {
|
||||
pub project_root: PathBuf,
|
||||
|
||||
pub rules: RuleTable,
|
||||
pub per_file_ignores: Vec<(GlobMatcher, GlobMatcher, RuleSet)>,
|
||||
|
@ -161,7 +151,20 @@ pub struct Settings {
|
|||
pub pyupgrade: pyupgrade::settings::Settings,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub const PREFIXES: &[RuleSelector] = &[
|
||||
RuleSelector::Prefix {
|
||||
prefix: RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E),
|
||||
redirected_from: None,
|
||||
},
|
||||
RuleSelector::Linter(Linter::Pyflakes),
|
||||
];
|
||||
|
||||
pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];
|
||||
|
||||
pub static DUMMY_VARIABLE_RGX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$").unwrap());
|
||||
|
||||
impl LinterSettings {
|
||||
pub fn for_rule(rule_code: Rule) -> Self {
|
||||
Self {
|
||||
rules: RuleTable::from_iter([rule_code]),
|
||||
|
@ -178,7 +181,62 @@ impl Settings {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the [`Settings`] after updating the target [`PythonVersion`].
|
||||
pub fn with_project_root(project_root: &Path) -> Self {
|
||||
Self {
|
||||
target_version: PythonVersion::default(),
|
||||
project_root: project_root.to_path_buf(),
|
||||
rules: PREFIXES
|
||||
.iter()
|
||||
.flat_map(|selector| selector.rules(PreviewMode::default()))
|
||||
.collect(),
|
||||
allowed_confusables: FxHashSet::from_iter([]),
|
||||
|
||||
// Needs duplicating
|
||||
builtins: vec![],
|
||||
dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone(),
|
||||
|
||||
external: HashSet::default(),
|
||||
ignore_init_module_imports: false,
|
||||
line_length: LineLength::default(),
|
||||
logger_objects: vec![],
|
||||
namespace_packages: vec![],
|
||||
|
||||
per_file_ignores: vec![],
|
||||
|
||||
src: vec![path_dedot::CWD.clone()],
|
||||
// Needs duplicating
|
||||
tab_size: TabSize::default(),
|
||||
|
||||
task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(),
|
||||
typing_modules: vec![],
|
||||
flake8_annotations: flake8_annotations::settings::Settings::default(),
|
||||
flake8_bandit: flake8_bandit::settings::Settings::default(),
|
||||
flake8_bugbear: flake8_bugbear::settings::Settings::default(),
|
||||
flake8_builtins: flake8_builtins::settings::Settings::default(),
|
||||
flake8_comprehensions: flake8_comprehensions::settings::Settings::default(),
|
||||
flake8_copyright: flake8_copyright::settings::Settings::default(),
|
||||
flake8_errmsg: flake8_errmsg::settings::Settings::default(),
|
||||
flake8_implicit_str_concat: flake8_implicit_str_concat::settings::Settings::default(),
|
||||
flake8_import_conventions: flake8_import_conventions::settings::Settings::default(),
|
||||
flake8_pytest_style: flake8_pytest_style::settings::Settings::default(),
|
||||
flake8_quotes: flake8_quotes::settings::Settings::default(),
|
||||
flake8_gettext: flake8_gettext::settings::Settings::default(),
|
||||
flake8_self: flake8_self::settings::Settings::default(),
|
||||
flake8_tidy_imports: flake8_tidy_imports::settings::Settings::default(),
|
||||
flake8_type_checking: flake8_type_checking::settings::Settings::default(),
|
||||
flake8_unused_arguments: flake8_unused_arguments::settings::Settings::default(),
|
||||
isort: isort::settings::Settings::default(),
|
||||
mccabe: mccabe::settings::Settings::default(),
|
||||
pep8_naming: pep8_naming::settings::Settings::default(),
|
||||
pycodestyle: pycodestyle::settings::Settings::default(),
|
||||
pydocstyle: pydocstyle::settings::Settings::default(),
|
||||
pyflakes: pyflakes::settings::Settings::default(),
|
||||
pylint: pylint::settings::Settings::default(),
|
||||
pyupgrade: pyupgrade::settings::Settings::default(),
|
||||
preview: PreviewMode::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_target_version(mut self, target_version: PythonVersion) -> Self {
|
||||
self.target_version = target_version;
|
||||
|
@ -186,6 +244,32 @@ impl Settings {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for LinterSettings {
|
||||
fn default() -> Self {
|
||||
Self::with_project_root(path_dedot::CWD.as_path())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, CacheKey)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct Settings {
|
||||
#[cache_key(ignore)]
|
||||
pub cache_dir: PathBuf,
|
||||
#[cache_key(ignore)]
|
||||
pub fix: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub fix_only: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub output_format: SerializationFormat,
|
||||
#[cache_key(ignore)]
|
||||
pub show_fixes: bool,
|
||||
#[cache_key(ignore)]
|
||||
pub show_source: bool,
|
||||
|
||||
pub file_resolver: FileResolverSettings,
|
||||
pub linter: LinterSettings,
|
||||
}
|
||||
|
||||
/// Given a list of patterns, create a `GlobSet`.
|
||||
pub fn resolve_per_file_ignores(
|
||||
per_file_ignores: Vec<PerFileIgnore>,
|
||||
|
@ -204,3 +288,19 @@ pub fn resolve_per_file_ignores(
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
let project_root = path_dedot::CWD.as_path();
|
||||
Self {
|
||||
cache_dir: cache_dir(project_root),
|
||||
fix: false,
|
||||
fix_only: false,
|
||||
output_format: SerializationFormat::default(),
|
||||
show_fixes: false,
|
||||
show_source: false,
|
||||
linter: LinterSettings::with_project_root(project_root),
|
||||
file_resolver: FileResolverSettings::with_project_root(project_root),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,11 @@ use crate::message::{Emitter, EmitterContext, Message, TextEmitter};
|
|||
use crate::packaging::detect_package_root;
|
||||
use crate::registry::AsRule;
|
||||
use crate::rules::pycodestyle::rules::syntax_error;
|
||||
use crate::settings::{flags, Settings};
|
||||
use crate::settings::{flags, LinterSettings};
|
||||
use crate::source_kind::SourceKind;
|
||||
use ruff_notebook::{Notebook, NotebookError};
|
||||
use ruff_notebook::Notebook;
|
||||
#[cfg(not(fuzzing))]
|
||||
use ruff_notebook::NotebookError;
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
pub(crate) fn test_resource_path(path: impl AsRef<Path>) -> std::path::PathBuf {
|
||||
|
@ -37,7 +39,7 @@ pub(crate) fn test_resource_path(path: impl AsRef<Path>) -> std::path::PathBuf {
|
|||
|
||||
/// Run [`check_path`] on a file in the `resources/test/fixtures` directory.
|
||||
#[cfg(not(fuzzing))]
|
||||
pub(crate) fn test_path(path: impl AsRef<Path>, settings: &Settings) -> Result<Vec<Message>> {
|
||||
pub(crate) fn test_path(path: impl AsRef<Path>, settings: &LinterSettings) -> Result<Vec<Message>> {
|
||||
let path = test_resource_path("fixtures").join(path);
|
||||
let contents = std::fs::read_to_string(&path)?;
|
||||
Ok(test_contents(&SourceKind::Python(contents), &path, settings).0)
|
||||
|
@ -54,7 +56,7 @@ pub(crate) struct TestedNotebook {
|
|||
pub(crate) fn test_notebook_path(
|
||||
path: impl AsRef<Path>,
|
||||
expected: impl AsRef<Path>,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> Result<TestedNotebook, NotebookError> {
|
||||
let source_notebook = Notebook::from_path(path.as_ref())?;
|
||||
|
||||
|
@ -81,7 +83,7 @@ pub(crate) fn test_notebook_path(
|
|||
}
|
||||
|
||||
/// Run [`check_path`] on a snippet of Python code.
|
||||
pub fn test_snippet(contents: &str, settings: &Settings) -> Vec<Message> {
|
||||
pub fn test_snippet(contents: &str, settings: &LinterSettings) -> Vec<Message> {
|
||||
let path = Path::new("<filename>");
|
||||
let contents = dedent(contents);
|
||||
test_contents(&SourceKind::Python(contents.into_owned()), path, settings).0
|
||||
|
@ -104,7 +106,7 @@ pub(crate) fn max_iterations() -> usize {
|
|||
pub(crate) fn test_contents<'a>(
|
||||
source_kind: &'a SourceKind,
|
||||
path: &Path,
|
||||
settings: &Settings,
|
||||
settings: &LinterSettings,
|
||||
) -> (Vec<Message>, Cow<'a, SourceKind>) {
|
||||
let source_type = PySourceType::from(path);
|
||||
let tokens: Vec<LexResult> =
|
||||
|
|
|
@ -11,7 +11,7 @@ use ruff_linter::line_width::{LineLength, TabSize};
|
|||
use ruff_linter::linter::{check_path, LinterResult};
|
||||
use ruff_linter::registry::AsRule;
|
||||
use ruff_linter::settings::types::{PreviewMode, PythonVersion};
|
||||
use ruff_linter::settings::{defaults, flags, Settings};
|
||||
use ruff_linter::settings::{flags, Settings, DUMMY_VARIABLE_RGX, PREFIXES};
|
||||
use ruff_linter::source_kind::SourceKind;
|
||||
use ruff_python_ast::{Mod, PySourceType};
|
||||
use ruff_python_codegen::Stylist;
|
||||
|
@ -122,7 +122,7 @@ impl Workspace {
|
|||
// Propagate defaults.
|
||||
allowed_confusables: Some(Vec::default()),
|
||||
builtins: Some(Vec::default()),
|
||||
dummy_variable_rgx: Some(defaults::DUMMY_VARIABLE_RGX.as_str().to_string()),
|
||||
dummy_variable_rgx: Some(DUMMY_VARIABLE_RGX.as_str().to_string()),
|
||||
extend_fixable: Some(Vec::default()),
|
||||
extend_ignore: Some(Vec::default()),
|
||||
extend_select: Some(Vec::default()),
|
||||
|
@ -131,7 +131,7 @@ impl Workspace {
|
|||
ignore: Some(Vec::default()),
|
||||
line_length: Some(LineLength::default()),
|
||||
preview: Some(false),
|
||||
select: Some(defaults::PREFIXES.to_vec()),
|
||||
select: Some(PREFIXES.to_vec()),
|
||||
tab_size: Some(TabSize::default()),
|
||||
target_version: Some(PythonVersion::default()),
|
||||
// Ignore a bunch of options that don't make sense in a single-file editor.
|
||||
|
@ -198,7 +198,7 @@ impl Workspace {
|
|||
&stylist,
|
||||
&indexer,
|
||||
&directives,
|
||||
&self.settings,
|
||||
&self.settings.linter,
|
||||
flags::Noqa::Enabled,
|
||||
&source_kind,
|
||||
source_type,
|
||||
|
@ -301,12 +301,15 @@ impl<'a> ParsedModule<'a> {
|
|||
|
||||
fn format(&self, settings: &Settings) -> FormatResult<Formatted<PyFormatContext>> {
|
||||
// TODO(konstin): Add an options for py/pyi to the UI (2/2)
|
||||
// TODO(micha): Use formatter settings instead
|
||||
let options = PyFormatOptions::from_source_type(PySourceType::default())
|
||||
.with_preview(match settings.preview {
|
||||
.with_preview(match settings.linter.preview {
|
||||
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
|
||||
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
|
||||
})
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(settings.line_length)));
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(
|
||||
settings.linter.line_length,
|
||||
)));
|
||||
|
||||
format_node(
|
||||
&self.module,
|
||||
|
|
|
@ -28,7 +28,8 @@ use ruff_linter::settings::types::{
|
|||
Version,
|
||||
};
|
||||
use ruff_linter::settings::{
|
||||
defaults, resolve_per_file_ignores, FileResolverSettings, Settings, EXCLUDE, INCLUDE,
|
||||
resolve_per_file_ignores, FileResolverSettings, LinterSettings, Settings, DUMMY_VARIABLE_RGX,
|
||||
EXCLUDE, INCLUDE, PREFIXES, TASK_TAGS,
|
||||
};
|
||||
use ruff_linter::{
|
||||
fs, warn_user, warn_user_once, warn_user_once_by_id, RuleSelector, RUFF_PKG_VERSION,
|
||||
|
@ -121,6 +122,9 @@ impl Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
let target_version = self.target_version.unwrap_or_default();
|
||||
let rules = self.as_rule_table();
|
||||
|
||||
Ok(Settings {
|
||||
cache_dir: self
|
||||
.cache_dir
|
||||
|
@ -132,15 +136,6 @@ impl Configuration {
|
|||
show_fixes: self.show_fixes.unwrap_or(false),
|
||||
show_source: self.show_source.unwrap_or(false),
|
||||
|
||||
rules: self.as_rule_table(),
|
||||
allowed_confusables: self
|
||||
.allowed_confusables
|
||||
.map(FxHashSet::from_iter)
|
||||
.unwrap_or_default(),
|
||||
builtins: self.builtins.unwrap_or_default(),
|
||||
dummy_variable_rgx: self
|
||||
.dummy_variable_rgx
|
||||
.unwrap_or_else(|| defaults::DUMMY_VARIABLE_RGX.clone()),
|
||||
file_resolver: FileResolverSettings {
|
||||
exclude: FilePatternSet::try_from_vec(
|
||||
self.exclude.unwrap_or_else(|| EXCLUDE.clone()),
|
||||
|
@ -154,130 +149,140 @@ impl Configuration {
|
|||
respect_gitignore: self.respect_gitignore.unwrap_or(true),
|
||||
project_root: project_root.to_path_buf(),
|
||||
},
|
||||
external: FxHashSet::from_iter(self.external.unwrap_or_default()),
|
||||
ignore_init_module_imports: self.ignore_init_module_imports.unwrap_or_default(),
|
||||
line_length: self.line_length.unwrap_or_default(),
|
||||
tab_size: self.tab_size.unwrap_or_default(),
|
||||
namespace_packages: self.namespace_packages.unwrap_or_default(),
|
||||
per_file_ignores: resolve_per_file_ignores(
|
||||
self.per_file_ignores
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.chain(self.extend_per_file_ignores)
|
||||
.collect(),
|
||||
)?,
|
||||
src: self.src.unwrap_or_else(|| vec![project_root.to_path_buf()]),
|
||||
target_version: self.target_version.unwrap_or_default(),
|
||||
task_tags: self.task_tags.unwrap_or_else(|| {
|
||||
defaults::TASK_TAGS
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect()
|
||||
}),
|
||||
logger_objects: self.logger_objects.unwrap_or_default(),
|
||||
preview: self.preview.unwrap_or_default(),
|
||||
typing_modules: self.typing_modules.unwrap_or_default(),
|
||||
// Plugins
|
||||
flake8_annotations: self
|
||||
.flake8_annotations
|
||||
.map(Flake8AnnotationsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_bandit: self
|
||||
.flake8_bandit
|
||||
.map(Flake8BanditOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_bugbear: self
|
||||
.flake8_bugbear
|
||||
.map(Flake8BugbearOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_builtins: self
|
||||
.flake8_builtins
|
||||
.map(Flake8BuiltinsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_comprehensions: self
|
||||
.flake8_comprehensions
|
||||
.map(Flake8ComprehensionsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_copyright: self
|
||||
.flake8_copyright
|
||||
.map(Flake8CopyrightOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
flake8_errmsg: self
|
||||
.flake8_errmsg
|
||||
.map(Flake8ErrMsgOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_implicit_str_concat: self
|
||||
.flake8_implicit_str_concat
|
||||
.map(Flake8ImplicitStrConcatOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_import_conventions: self
|
||||
.flake8_import_conventions
|
||||
.map(Flake8ImportConventionsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_pytest_style: self
|
||||
.flake8_pytest_style
|
||||
.map(Flake8PytestStyleOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
flake8_quotes: self
|
||||
.flake8_quotes
|
||||
.map(Flake8QuotesOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_self: self
|
||||
.flake8_self
|
||||
.map(Flake8SelfOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_tidy_imports: self
|
||||
.flake8_tidy_imports
|
||||
.map(Flake8TidyImportsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_type_checking: self
|
||||
.flake8_type_checking
|
||||
.map(Flake8TypeCheckingOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_unused_arguments: self
|
||||
.flake8_unused_arguments
|
||||
.map(Flake8UnusedArgumentsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_gettext: self
|
||||
.flake8_gettext
|
||||
.map(Flake8GetTextOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
isort: self
|
||||
.isort
|
||||
.map(IsortOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
mccabe: self
|
||||
.mccabe
|
||||
.map(McCabeOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pep8_naming: self
|
||||
.pep8_naming
|
||||
.map(Pep8NamingOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
pycodestyle: self
|
||||
.pycodestyle
|
||||
.map(PycodestyleOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pydocstyle: self
|
||||
.pydocstyle
|
||||
.map(PydocstyleOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pyflakes: self
|
||||
.pyflakes
|
||||
.map(PyflakesOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pylint: self
|
||||
.pylint
|
||||
.map(PylintOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pyupgrade: self
|
||||
.pyupgrade
|
||||
.map(PyUpgradeOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
linter: LinterSettings {
|
||||
target_version,
|
||||
project_root: project_root.to_path_buf(),
|
||||
rules,
|
||||
allowed_confusables: self
|
||||
.allowed_confusables
|
||||
.map(FxHashSet::from_iter)
|
||||
.unwrap_or_default(),
|
||||
builtins: self.builtins.unwrap_or_default(),
|
||||
dummy_variable_rgx: self
|
||||
.dummy_variable_rgx
|
||||
.unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()),
|
||||
external: FxHashSet::from_iter(self.external.unwrap_or_default()),
|
||||
ignore_init_module_imports: self.ignore_init_module_imports.unwrap_or_default(),
|
||||
line_length: self.line_length.unwrap_or_default(),
|
||||
tab_size: self.tab_size.unwrap_or_default(),
|
||||
namespace_packages: self.namespace_packages.unwrap_or_default(),
|
||||
per_file_ignores: resolve_per_file_ignores(
|
||||
self.per_file_ignores
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.chain(self.extend_per_file_ignores)
|
||||
.collect(),
|
||||
)?,
|
||||
src: self.src.unwrap_or_else(|| vec![project_root.to_path_buf()]),
|
||||
|
||||
task_tags: self
|
||||
.task_tags
|
||||
.unwrap_or_else(|| TASK_TAGS.iter().map(ToString::to_string).collect()),
|
||||
logger_objects: self.logger_objects.unwrap_or_default(),
|
||||
preview: self.preview.unwrap_or_default(),
|
||||
typing_modules: self.typing_modules.unwrap_or_default(),
|
||||
// Plugins
|
||||
flake8_annotations: self
|
||||
.flake8_annotations
|
||||
.map(Flake8AnnotationsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_bandit: self
|
||||
.flake8_bandit
|
||||
.map(Flake8BanditOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_bugbear: self
|
||||
.flake8_bugbear
|
||||
.map(Flake8BugbearOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_builtins: self
|
||||
.flake8_builtins
|
||||
.map(Flake8BuiltinsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_comprehensions: self
|
||||
.flake8_comprehensions
|
||||
.map(Flake8ComprehensionsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_copyright: self
|
||||
.flake8_copyright
|
||||
.map(Flake8CopyrightOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
flake8_errmsg: self
|
||||
.flake8_errmsg
|
||||
.map(Flake8ErrMsgOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_implicit_str_concat: self
|
||||
.flake8_implicit_str_concat
|
||||
.map(Flake8ImplicitStrConcatOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_import_conventions: self
|
||||
.flake8_import_conventions
|
||||
.map(Flake8ImportConventionsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_pytest_style: self
|
||||
.flake8_pytest_style
|
||||
.map(Flake8PytestStyleOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
flake8_quotes: self
|
||||
.flake8_quotes
|
||||
.map(Flake8QuotesOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_self: self
|
||||
.flake8_self
|
||||
.map(Flake8SelfOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_tidy_imports: self
|
||||
.flake8_tidy_imports
|
||||
.map(Flake8TidyImportsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_type_checking: self
|
||||
.flake8_type_checking
|
||||
.map(Flake8TypeCheckingOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_unused_arguments: self
|
||||
.flake8_unused_arguments
|
||||
.map(Flake8UnusedArgumentsOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
flake8_gettext: self
|
||||
.flake8_gettext
|
||||
.map(Flake8GetTextOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
isort: self
|
||||
.isort
|
||||
.map(IsortOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
mccabe: self
|
||||
.mccabe
|
||||
.map(McCabeOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pep8_naming: self
|
||||
.pep8_naming
|
||||
.map(Pep8NamingOptions::try_into_settings)
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
pycodestyle: self
|
||||
.pycodestyle
|
||||
.map(PycodestyleOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pydocstyle: self
|
||||
.pydocstyle
|
||||
.map(PydocstyleOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pyflakes: self
|
||||
.pyflakes
|
||||
.map(PyflakesOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pylint: self
|
||||
.pylint
|
||||
.map(PylintOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
pyupgrade: self
|
||||
.pyupgrade
|
||||
.map(PyUpgradeOptions::into_settings)
|
||||
.unwrap_or_default(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -442,7 +447,7 @@ impl Configuration {
|
|||
let preview = self.preview.unwrap_or_default();
|
||||
|
||||
// The select_set keeps track of which rules have been selected.
|
||||
let mut select_set: RuleSet = defaults::PREFIXES
|
||||
let mut select_set: RuleSet = PREFIXES
|
||||
.iter()
|
||||
.flat_map(|selector| selector.rules(preview))
|
||||
.collect();
|
||||
|
|
|
@ -139,7 +139,10 @@ impl Resolver {
|
|||
// Search for the package root for each file.
|
||||
let mut package_roots: FxHashMap<&Path, Option<&Path>> = FxHashMap::default();
|
||||
for file in files {
|
||||
let namespace_packages = &self.resolve(file, pyproject_config).namespace_packages;
|
||||
let namespace_packages = &self
|
||||
.resolve(file, pyproject_config)
|
||||
.linter
|
||||
.namespace_packages;
|
||||
if let Some(package) = file.parent() {
|
||||
if package_roots.contains_key(package) {
|
||||
continue;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue