mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Switch to Rust 2024 edition (#18129)
This commit is contained in:
parent
e67b35743a
commit
9ae698fe30
1082 changed files with 4211 additions and 3300 deletions
|
@ -5,12 +5,12 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::env::VarError;
|
||||
use std::num::{NonZeroU16, NonZeroU8};
|
||||
use std::num::{NonZeroU8, NonZeroU16};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use glob::{glob, GlobError, Paths, PatternError};
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use glob::{GlobError, Paths, PatternError, glob};
|
||||
use itertools::Itertools;
|
||||
use regex::Regex;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
@ -23,7 +23,7 @@ use ruff_formatter::IndentStyle;
|
|||
use ruff_graph::{AnalyzeSettings, Direction};
|
||||
use ruff_linter::line_width::{IndentWidth, LineLength};
|
||||
use ruff_linter::registry::RuleNamespace;
|
||||
use ruff_linter::registry::{Rule, RuleSet, INCOMPATIBLE_CODES};
|
||||
use ruff_linter::registry::{INCOMPATIBLE_CODES, Rule, RuleSet};
|
||||
use ruff_linter::rule_selector::{PreviewOptions, Specificity};
|
||||
use ruff_linter::rules::{flake8_import_conventions, isort, pycodestyle};
|
||||
use ruff_linter::settings::fix_safety_table::FixSafetyTable;
|
||||
|
@ -34,11 +34,11 @@ use ruff_linter::settings::types::{
|
|||
RequiredVersion, UnsafeFixes,
|
||||
};
|
||||
use ruff_linter::settings::{
|
||||
LinterSettings, TargetVersion, DEFAULT_SELECTORS, DUMMY_VARIABLE_RGX, TASK_TAGS,
|
||||
DEFAULT_SELECTORS, DUMMY_VARIABLE_RGX, LinterSettings, TASK_TAGS, TargetVersion,
|
||||
};
|
||||
use ruff_linter::{
|
||||
fs, warn_user_once, warn_user_once_by_id, warn_user_once_by_message, RuleSelector,
|
||||
RUFF_PKG_VERSION,
|
||||
RUFF_PKG_VERSION, RuleSelector, fs, warn_user_once, warn_user_once_by_id,
|
||||
warn_user_once_by_message,
|
||||
};
|
||||
use ruff_python_ast as ast;
|
||||
use ruff_python_formatter::{
|
||||
|
@ -56,7 +56,7 @@ use crate::options::{
|
|||
PydoclintOptions, PydocstyleOptions, PyflakesOptions, PylintOptions, RuffOptions,
|
||||
};
|
||||
use crate::settings::{
|
||||
FileResolverSettings, FormatterSettings, LineEnding, Settings, EXCLUDE, INCLUDE,
|
||||
EXCLUDE, FileResolverSettings, FormatterSettings, INCLUDE, LineEnding, Settings,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@ -690,7 +690,9 @@ impl LintConfiguration {
|
|||
#[expect(deprecated)]
|
||||
let ignore_init_module_imports = {
|
||||
if options.common.ignore_init_module_imports.is_some() {
|
||||
warn_user_once!("The `ignore-init-module-imports` option is deprecated and will be removed in a future release. Ruff's handling of imports in `__init__.py` files has been improved (in preview) and unused imports will always be flagged.");
|
||||
warn_user_once!(
|
||||
"The `ignore-init-module-imports` option is deprecated and will be removed in a future release. Ruff's handling of imports in `__init__.py` files has been improved (in preview) and unused imports will always be flagged."
|
||||
);
|
||||
}
|
||||
options.common.ignore_init_module_imports
|
||||
};
|
||||
|
@ -1046,7 +1048,9 @@ impl LintConfiguration {
|
|||
[] => (),
|
||||
[selection] => {
|
||||
let (prefix, code) = selection.prefix_and_code();
|
||||
return Err(anyhow!("Selection of deprecated rule `{prefix}{code}` is not allowed when preview is enabled."));
|
||||
return Err(anyhow!(
|
||||
"Selection of deprecated rule `{prefix}{code}` is not allowed when preview is enabled."
|
||||
));
|
||||
}
|
||||
[..] => {
|
||||
let mut message = "Selection of deprecated rules is not allowed when preview is enabled. Remove selection of:".to_string();
|
||||
|
@ -1632,11 +1636,11 @@ mod tests {
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use ruff_linter::RuleSelector;
|
||||
use ruff_linter::codes::{Flake8Copyright, Pycodestyle, Refurb};
|
||||
use ruff_linter::registry::{Linter, Rule, RuleSet};
|
||||
use ruff_linter::rule_selector::PreviewOptions;
|
||||
use ruff_linter::settings::types::PreviewMode;
|
||||
use ruff_linter::RuleSelector;
|
||||
|
||||
use crate::configuration::{LintConfiguration, RuleSelection};
|
||||
use crate::options::PydocstyleOptions;
|
||||
|
|
|
@ -29,7 +29,7 @@ use ruff_linter::rules::{
|
|||
use ruff_linter::settings::types::{
|
||||
IdentifierPattern, OutputFormat, PythonVersion, RequiredVersion,
|
||||
};
|
||||
use ruff_linter::{warn_user_once, RuleSelector};
|
||||
use ruff_linter::{RuleSelector, warn_user_once};
|
||||
use ruff_macros::{CombineOptions, OptionsMetadata};
|
||||
use ruff_options_metadata::{OptionsMetadata, Visit};
|
||||
use ruff_python_ast::name::Name;
|
||||
|
@ -556,10 +556,10 @@ impl schemars::JsonSchema for DeprecatedTopLevelLintOptions {
|
|||
"DeprecatedTopLevelLintOptions"
|
||||
))
|
||||
}
|
||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
||||
fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
|
||||
use schemars::schema::Schema;
|
||||
|
||||
let common_schema = LintCommonOptions::json_schema(gen);
|
||||
let common_schema = LintCommonOptions::json_schema(generator);
|
||||
let mut schema_obj = common_schema.into_object();
|
||||
|
||||
if let Some(object) = schema_obj.object.as_mut() {
|
||||
|
@ -2670,7 +2670,9 @@ impl IsortOptions {
|
|||
let force_sort_within_sections = self.force_sort_within_sections.unwrap_or_default();
|
||||
let lines_between_types = self.lines_between_types.unwrap_or_default();
|
||||
if force_sort_within_sections && lines_between_types != 0 {
|
||||
warn_user_once!("`lines-between-types` is ignored when `force-sort-within-sections` is set to `true`");
|
||||
warn_user_once!(
|
||||
"`lines-between-types` is ignored when `force-sort-within-sections` is set to `true`"
|
||||
);
|
||||
}
|
||||
|
||||
// Extract any configuration options that deal with user-defined sections.
|
||||
|
|
|
@ -183,9 +183,13 @@ pub(super) fn load_options<P: AsRef<Path>>(
|
|||
if let Some(dir) = path.parent() {
|
||||
let fallback = get_fallback_target_version(dir);
|
||||
if let Some(version) = fallback {
|
||||
debug!("Derived `target-version` from `requires-python` in `pyproject.toml`: {version:?}");
|
||||
debug!(
|
||||
"Derived `target-version` from `requires-python` in `pyproject.toml`: {version:?}"
|
||||
);
|
||||
} else {
|
||||
debug!("No `pyproject.toml` with `requires-python` in same directory; `target-version` unspecified");
|
||||
debug!(
|
||||
"No `pyproject.toml` with `requires-python` in same directory; `target-version` unspecified"
|
||||
);
|
||||
}
|
||||
ruff.target_version = fallback;
|
||||
}
|
||||
|
@ -277,7 +281,7 @@ mod tests {
|
|||
use ruff_linter::settings::types::PatternPrefixPair;
|
||||
|
||||
use crate::options::{Flake8BuiltinsOptions, LintCommonOptions, LintOptions, Options};
|
||||
use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools};
|
||||
use crate::pyproject::{Pyproject, Tools, find_settings_toml, parse_pyproject_toml};
|
||||
|
||||
#[test]
|
||||
|
||||
|
@ -436,33 +440,39 @@ strict-checking = false
|
|||
);
|
||||
assert!(!settings.strict_checking);
|
||||
|
||||
assert!(toml::from_str::<Pyproject>(
|
||||
r"
|
||||
assert!(
|
||||
toml::from_str::<Pyproject>(
|
||||
r"
|
||||
[tool.black]
|
||||
[tool.ruff]
|
||||
line_length = 79
|
||||
",
|
||||
)
|
||||
.is_err());
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
assert!(toml::from_str::<Pyproject>(
|
||||
r#"
|
||||
assert!(
|
||||
toml::from_str::<Pyproject>(
|
||||
r#"
|
||||
[tool.black]
|
||||
[tool.ruff.lint]
|
||||
select = ["E123"]
|
||||
"#,
|
||||
)
|
||||
.is_err());
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
assert!(toml::from_str::<Pyproject>(
|
||||
r"
|
||||
assert!(
|
||||
toml::from_str::<Pyproject>(
|
||||
r"
|
||||
[tool.black]
|
||||
[tool.ruff]
|
||||
line-length = 79
|
||||
other-attribute = 1
|
||||
",
|
||||
)
|
||||
.is_err());
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ use std::ffi::OsStr;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::RwLock;
|
||||
|
||||
use anyhow::{anyhow, bail};
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{anyhow, bail};
|
||||
use globset::{Candidate, GlobSet};
|
||||
use ignore::{DirEntry, Error, ParallelVisitor, WalkBuilder, WalkState};
|
||||
use itertools::Itertools;
|
||||
|
@ -23,9 +23,9 @@ use ruff_linter::package::PackageRoot;
|
|||
use ruff_linter::packaging::is_package;
|
||||
|
||||
use crate::configuration::Configuration;
|
||||
use crate::pyproject::{settings_toml, TargetVersionStrategy};
|
||||
use crate::pyproject::{TargetVersionStrategy, settings_toml};
|
||||
use crate::settings::Settings;
|
||||
use crate::{pyproject, FileResolverSettings};
|
||||
use crate::{FileResolverSettings, pyproject};
|
||||
|
||||
/// The configuration information from a `pyproject.toml` file.
|
||||
#[derive(Debug)]
|
||||
|
@ -667,7 +667,7 @@ impl ParallelVisitor for PythonFilesVisitor<'_, '_> {
|
|||
impl Drop for PythonFilesVisitor<'_, '_> {
|
||||
fn drop(&mut self) {
|
||||
let mut merged = self.global.merged.lock().unwrap();
|
||||
let (ref mut files, ref mut error) = &mut *merged;
|
||||
let (files, error) = &mut *merged;
|
||||
|
||||
if files.is_empty() {
|
||||
*files = std::mem::take(&mut self.local_files);
|
||||
|
@ -910,7 +910,7 @@ pub fn match_any_inclusion(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs::{create_dir, File};
|
||||
use std::fs::{File, create_dir};
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -924,9 +924,9 @@ mod tests {
|
|||
use crate::configuration::Configuration;
|
||||
use crate::pyproject::find_settings_toml;
|
||||
use crate::resolver::{
|
||||
is_file_excluded, match_exclusion, python_files_in_path, resolve_root_settings,
|
||||
ConfigurationOrigin, ConfigurationTransformer, PyprojectConfig, PyprojectDiscoveryStrategy,
|
||||
ResolvedFile, Resolver,
|
||||
ResolvedFile, Resolver, is_file_excluded, match_exclusion, python_files_in_path,
|
||||
resolve_root_settings,
|
||||
};
|
||||
use crate::settings::Settings;
|
||||
use crate::tests::test_resource_path;
|
||||
|
|
|
@ -3,11 +3,11 @@ use ruff_cache::cache_dir;
|
|||
use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
|
||||
use ruff_graph::AnalyzeSettings;
|
||||
use ruff_linter::display_settings;
|
||||
use ruff_linter::settings::LinterSettings;
|
||||
use ruff_linter::settings::types::{
|
||||
CompiledPerFileTargetVersionList, ExtensionMapping, FilePattern, FilePatternSet, OutputFormat,
|
||||
UnsafeFixes,
|
||||
};
|
||||
use ruff_linter::settings::LinterSettings;
|
||||
use ruff_macros::CacheKey;
|
||||
use ruff_python_ast::{PySourceType, PythonVersion};
|
||||
use ruff_python_formatter::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue