mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 23:24:39 +00:00
Promote lint.
settings over top-level settings (#9476)
This commit is contained in:
parent
6996ff7b1e
commit
c3b33e9c4d
62 changed files with 389 additions and 310 deletions
|
@ -51,7 +51,7 @@ else:
|
|||
```
|
||||
|
||||
## Options
|
||||
- `pyflakes.extend-generics`
|
||||
- `lint.pyflakes.extend-generics`
|
||||
|
||||
## References
|
||||
- [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement)
|
||||
|
|
|
@ -116,7 +116,7 @@ fn process_documentation(documentation: &str, out: &mut String, rule_name: &str)
|
|||
}
|
||||
}
|
||||
|
||||
let anchor = option.replace('.', "-");
|
||||
let anchor = option.replace('.', "_");
|
||||
out.push_str(&format!("- [`{option}`][{option}]\n"));
|
||||
after.push_str(&format!("[{option}]: ../settings.md#{anchor}\n"));
|
||||
|
||||
|
@ -142,13 +142,13 @@ mod tests {
|
|||
let mut output = String::new();
|
||||
process_documentation(
|
||||
"
|
||||
See also [`mccabe.max-complexity`] and [`task-tags`].
|
||||
See also [`lint.mccabe.max-complexity`] and [`lint.task-tags`].
|
||||
Something [`else`][other].
|
||||
|
||||
## Options
|
||||
|
||||
- `task-tags`
|
||||
- `mccabe.max-complexity`
|
||||
- `lint.task-tags`
|
||||
- `lint.mccabe.max-complexity`
|
||||
|
||||
[other]: http://example.com.",
|
||||
&mut output,
|
||||
|
@ -157,18 +157,18 @@ Something [`else`][other].
|
|||
assert_eq!(
|
||||
output,
|
||||
"
|
||||
See also [`mccabe.max-complexity`][mccabe.max-complexity] and [`task-tags`][task-tags].
|
||||
See also [`lint.mccabe.max-complexity`][lint.mccabe.max-complexity] and [`lint.task-tags`][lint.task-tags].
|
||||
Something [`else`][other].
|
||||
|
||||
## Options
|
||||
|
||||
- [`task-tags`][task-tags]
|
||||
- [`mccabe.max-complexity`][mccabe.max-complexity]
|
||||
- [`lint.task-tags`][lint.task-tags]
|
||||
- [`lint.mccabe.max-complexity`][lint.mccabe.max-complexity]
|
||||
|
||||
[other]: http://example.com.
|
||||
|
||||
[task-tags]: ../settings.md#task-tags
|
||||
[mccabe.max-complexity]: ../settings.md#mccabe-max-complexity
|
||||
[lint.task-tags]: ../settings.md#lint_task-tags
|
||||
[lint.mccabe.max-complexity]: ../settings.md#lint_mccabe_max-complexity
|
||||
"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Generate a Markdown-compatible listing of configuration options for `pyproject.toml`.
|
||||
//!
|
||||
//! Used for <https://docs.astral.sh/ruff/settings/>.
|
||||
use itertools::Itertools;
|
||||
use std::fmt::Write;
|
||||
|
||||
use ruff_python_trivia::textwrap;
|
||||
|
@ -9,16 +10,29 @@ use ruff_workspace::options_base::{OptionField, OptionSet, OptionsMetadata, Visi
|
|||
|
||||
pub(crate) fn generate() -> String {
|
||||
let mut output = String::new();
|
||||
generate_set(&mut output, &Set::Toplevel(Options::metadata()));
|
||||
|
||||
generate_set(
|
||||
&mut output,
|
||||
Set::Toplevel(Options::metadata()),
|
||||
&mut Vec::new(),
|
||||
);
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
fn generate_set(output: &mut String, set: &Set) {
|
||||
if set.level() < 2 {
|
||||
writeln!(output, "### {title}\n", title = set.title()).unwrap();
|
||||
} else {
|
||||
writeln!(output, "#### {title}\n", title = set.title()).unwrap();
|
||||
fn generate_set(output: &mut String, set: Set, parents: &mut Vec<Set>) {
|
||||
match &set {
|
||||
Set::Toplevel(_) => {
|
||||
output.push_str("### Top-level\n");
|
||||
}
|
||||
Set::Named { name, .. } => {
|
||||
let title = parents
|
||||
.iter()
|
||||
.filter_map(|set| set.name())
|
||||
.chain(std::iter::once(name.as_str()))
|
||||
.join(".");
|
||||
writeln!(output, "#### `{title}`\n",).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(documentation) = set.metadata().documentation() {
|
||||
|
@ -35,72 +49,68 @@ fn generate_set(output: &mut String, set: &Set) {
|
|||
fields.sort_unstable_by(|(name, _), (name2, _)| name.cmp(name2));
|
||||
sets.sort_unstable_by(|(name, _), (name2, _)| name.cmp(name2));
|
||||
|
||||
parents.push(set);
|
||||
|
||||
// Generate the fields.
|
||||
for (name, field) in &fields {
|
||||
emit_field(output, name, field, set);
|
||||
emit_field(output, name, field, parents.as_slice());
|
||||
output.push_str("---\n\n");
|
||||
}
|
||||
|
||||
// Generate all the sub-sets.
|
||||
for (set_name, sub_set) in &sets {
|
||||
generate_set(output, &Set::Named(set_name, *sub_set, set.level() + 1));
|
||||
generate_set(
|
||||
output,
|
||||
Set::Named {
|
||||
name: set_name.to_string(),
|
||||
set: *sub_set,
|
||||
},
|
||||
parents,
|
||||
);
|
||||
}
|
||||
|
||||
parents.pop();
|
||||
}
|
||||
|
||||
enum Set<'a> {
|
||||
enum Set {
|
||||
Toplevel(OptionSet),
|
||||
Named(&'a str, OptionSet, u32),
|
||||
Named { name: String, set: OptionSet },
|
||||
}
|
||||
|
||||
impl<'a> Set<'a> {
|
||||
fn name(&self) -> Option<&'a str> {
|
||||
impl Set {
|
||||
fn name(&self) -> Option<&str> {
|
||||
match self {
|
||||
Set::Toplevel(_) => None,
|
||||
Set::Named(name, _, _) => Some(name),
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> &'a str {
|
||||
match self {
|
||||
Set::Toplevel(_) => "Top-level",
|
||||
Set::Named(name, _, _) => name,
|
||||
Set::Named { name, .. } => Some(name),
|
||||
}
|
||||
}
|
||||
|
||||
fn metadata(&self) -> &OptionSet {
|
||||
match self {
|
||||
Set::Toplevel(set) => set,
|
||||
Set::Named(_, set, _) => set,
|
||||
}
|
||||
}
|
||||
|
||||
fn level(&self) -> u32 {
|
||||
match self {
|
||||
Set::Toplevel(_) => 0,
|
||||
Set::Named(_, _, level) => *level,
|
||||
Set::Named { set, .. } => set,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_field(output: &mut String, name: &str, field: &OptionField, parent_set: &Set) {
|
||||
let header_level = if parent_set.level() < 2 {
|
||||
"####"
|
||||
} else {
|
||||
"#####"
|
||||
};
|
||||
fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[Set]) {
|
||||
let header_level = if parents.is_empty() { "####" } else { "#####" };
|
||||
let parents_anchor = parents.iter().filter_map(|parent| parent.name()).join("_");
|
||||
|
||||
if parents_anchor.is_empty() {
|
||||
output.push_str(&format!(
|
||||
"{header_level} [`{name}`](#{name}) {{: #{name} }}\n"
|
||||
));
|
||||
} else {
|
||||
output.push_str(&format!(
|
||||
"{header_level} [`{name}`](#{parents_anchor}_{name}) {{: #{parents_anchor}_{name} }}\n"
|
||||
));
|
||||
|
||||
// if there's a set name, we need to add it to the anchor
|
||||
if let Some(set_name) = parent_set.name() {
|
||||
// the anchor used to just be the name, but now it's the group name
|
||||
// for backwards compatibility, we need to keep the old anchor
|
||||
output.push_str(&format!("<span id=\"{name}\"></span>\n"));
|
||||
|
||||
output.push_str(&format!(
|
||||
"{header_level} [`{name}`](#{set_name}-{name}) {{: #{set_name}-{name} }}\n"
|
||||
));
|
||||
} else {
|
||||
output.push_str(&format!("{header_level} [`{name}`](#{name})\n"));
|
||||
}
|
||||
|
||||
output.push('\n');
|
||||
|
||||
if let Some(deprecated) = &field.deprecated {
|
||||
|
@ -129,12 +139,12 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parent_set:
|
|||
output.push_str("**Example usage**:\n\n");
|
||||
output.push_str(&format_tab(
|
||||
"pyproject.toml",
|
||||
&format_header(field.scope, parent_set, ConfigurationFile::PyprojectToml),
|
||||
&format_header(field.scope, parents, ConfigurationFile::PyprojectToml),
|
||||
field.example,
|
||||
));
|
||||
output.push_str(&format_tab(
|
||||
"ruff.toml",
|
||||
&format_header(field.scope, parent_set, ConfigurationFile::RuffToml),
|
||||
&format_header(field.scope, parents, ConfigurationFile::RuffToml),
|
||||
field.example,
|
||||
));
|
||||
output.push('\n');
|
||||
|
@ -152,52 +162,22 @@ fn format_tab(tab_name: &str, header: &str, content: &str) -> String {
|
|||
/// Format the TOML header for the example usage for a given option.
|
||||
///
|
||||
/// For example: `[tool.ruff.format]` or `[tool.ruff.lint.isort]`.
|
||||
fn format_header(
|
||||
scope: Option<&str>,
|
||||
parent_set: &Set,
|
||||
configuration: ConfigurationFile,
|
||||
) -> String {
|
||||
match configuration {
|
||||
ConfigurationFile::PyprojectToml => {
|
||||
let mut header = if let Some(set_name) = parent_set.name() {
|
||||
if set_name == "format" {
|
||||
String::from("tool.ruff.format")
|
||||
} else {
|
||||
format!("tool.ruff.lint.{set_name}")
|
||||
}
|
||||
} else {
|
||||
"tool.ruff".to_string()
|
||||
};
|
||||
if let Some(scope) = scope {
|
||||
if !header.is_empty() {
|
||||
header.push('.');
|
||||
}
|
||||
header.push_str(scope);
|
||||
}
|
||||
format!("[{header}]")
|
||||
}
|
||||
ConfigurationFile::RuffToml => {
|
||||
let mut header = if let Some(set_name) = parent_set.name() {
|
||||
if set_name == "format" {
|
||||
String::from("format")
|
||||
} else {
|
||||
format!("lint.{set_name}")
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
if let Some(scope) = scope {
|
||||
if !header.is_empty() {
|
||||
header.push('.');
|
||||
}
|
||||
header.push_str(scope);
|
||||
}
|
||||
if header.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("[{header}]")
|
||||
}
|
||||
}
|
||||
fn format_header(scope: Option<&str>, parents: &[Set], configuration: ConfigurationFile) -> String {
|
||||
let tool_parent = match configuration {
|
||||
ConfigurationFile::PyprojectToml => Some("tool.ruff"),
|
||||
ConfigurationFile::RuffToml => None,
|
||||
};
|
||||
|
||||
let header = tool_parent
|
||||
.into_iter()
|
||||
.chain(parents.iter().filter_map(|parent| parent.name()))
|
||||
.chain(scope)
|
||||
.join(".");
|
||||
|
||||
if header.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("[{header}]")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use super::super::detection::comment_contains_code;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `task-tags`
|
||||
/// - `lint.task-tags`
|
||||
///
|
||||
/// [#4845]: https://github.com/astral-sh/ruff/issues/4845
|
||||
#[violation]
|
||||
|
|
|
@ -23,11 +23,11 @@ use crate::checkers::ast::Checker;
|
|||
/// calls to the function, which can lead to unexpected behaviour.
|
||||
///
|
||||
/// Calls can be marked as an exception to this rule with the
|
||||
/// [`flake8-bugbear.extend-immutable-calls`] configuration option.
|
||||
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option.
|
||||
///
|
||||
/// Arguments with immutable type annotations will be ignored by this rule.
|
||||
/// Types outside of the standard library can be marked as immutable with the
|
||||
/// [`flake8-bugbear.extend-immutable-calls`] configuration option as well.
|
||||
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option as well.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -61,7 +61,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-bugbear.extend-immutable-calls`
|
||||
/// - `lint.flake8-bugbear.extend-immutable-calls`
|
||||
#[violation]
|
||||
pub struct FunctionCallInDefaultArgument {
|
||||
name: Option<String>,
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::checkers::ast::Checker;
|
|||
///
|
||||
/// Arguments with immutable type annotations will be ignored by this rule.
|
||||
/// Types outside of the standard library can be marked as immutable with the
|
||||
/// [`flake8-bugbear.extend-immutable-calls`] configuration option.
|
||||
/// [`lint.flake8-bugbear.extend-immutable-calls`] configuration option.
|
||||
///
|
||||
/// ## Known problems
|
||||
/// Mutable argument defaults can be used intentionally to cache computation
|
||||
|
@ -61,7 +61,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-bugbear.extend-immutable-calls`
|
||||
/// - `lint.flake8-bugbear.extend-immutable-calls`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values)
|
||||
|
|
|
@ -19,7 +19,7 @@ use super::super::helpers::shadows_builtin;
|
|||
/// builtin and vice versa.
|
||||
///
|
||||
/// Builtins can be marked as exceptions to this rule via the
|
||||
/// [`flake8-builtins.builtins-ignorelist`] configuration option.
|
||||
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -44,7 +44,7 @@ use super::super::helpers::shadows_builtin;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-builtins.builtins-ignorelist`
|
||||
/// - `lint.flake8-builtins.builtins-ignorelist`
|
||||
///
|
||||
/// ## References
|
||||
/// - [_Is it bad practice to use a built-in function name as an attribute or method identifier?_](https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide)
|
||||
|
|
|
@ -37,7 +37,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
|
|||
/// ```
|
||||
///
|
||||
/// Builtins can be marked as exceptions to this rule via the
|
||||
/// [`flake8-builtins.builtins-ignorelist`] configuration option, or
|
||||
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option, or
|
||||
/// converted to the appropriate dunder method. Methods decorated with
|
||||
/// `@typing.override` or `@typing_extensions.override` are also
|
||||
/// ignored.
|
||||
|
@ -55,7 +55,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-builtins.builtins-ignorelist`
|
||||
/// - `lint.flake8-builtins.builtins-ignorelist`
|
||||
#[violation]
|
||||
pub struct BuiltinAttributeShadowing {
|
||||
kind: Kind,
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
|
|||
/// builtin and vice versa.
|
||||
///
|
||||
/// Builtins can be marked as exceptions to this rule via the
|
||||
/// [`flake8-builtins.builtins-ignorelist`] configuration option.
|
||||
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -41,7 +41,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-builtins.builtins-ignorelist`
|
||||
/// - `lint.flake8-builtins.builtins-ignorelist`
|
||||
///
|
||||
/// ## References
|
||||
/// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python)
|
||||
|
|
|
@ -59,7 +59,7 @@ impl Violation for SingleLineImplicitStringConcatenation {
|
|||
///
|
||||
/// By default, this rule will only trigger if the string literal is
|
||||
/// concatenated via a backslash. To disallow implicit string concatenation
|
||||
/// altogether, set the [`flake8-implicit-str-concat.allow-multiline`] option
|
||||
/// altogether, set the [`lint.flake8-implicit-str-concat.allow-multiline`] option
|
||||
/// to `false`.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -77,7 +77,7 @@ impl Violation for SingleLineImplicitStringConcatenation {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-implicit-str-concat.allow-multiline`
|
||||
/// - `lint.flake8-implicit-str-concat.allow-multiline`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
|
||||
#[violation]
|
||||
|
|
|
@ -29,7 +29,7 @@ use ruff_text_size::Ranged;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-import-conventions.banned-aliases`
|
||||
/// - `lint.flake8-import-conventions.banned-aliases`
|
||||
#[violation]
|
||||
pub struct BannedImportAlias {
|
||||
name: String,
|
||||
|
|
|
@ -30,7 +30,7 @@ use ruff_text_size::Ranged;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-import-conventions.banned-from`
|
||||
/// - `lint.flake8-import-conventions.banned-from`
|
||||
#[violation]
|
||||
pub struct BannedImportFrom {
|
||||
name: String,
|
||||
|
|
|
@ -32,8 +32,8 @@ use crate::renamer::Renamer;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-import-conventions.aliases`
|
||||
/// - `flake8-import-conventions.extend-aliases`
|
||||
/// - `lint.flake8-import-conventions.aliases`
|
||||
/// - `lint.flake8-import-conventions.extend-aliases`
|
||||
#[violation]
|
||||
pub struct UnconventionalImportAlias {
|
||||
name: String,
|
||||
|
|
|
@ -30,9 +30,9 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -68,7 +68,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html)
|
||||
|
@ -114,9 +114,9 @@ impl Violation for LoggingStringFormat {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -152,7 +152,7 @@ impl Violation for LoggingStringFormat {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html)
|
||||
|
@ -197,9 +197,9 @@ impl Violation for LoggingPercentFormat {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -235,7 +235,7 @@ impl Violation for LoggingPercentFormat {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html)
|
||||
|
@ -279,9 +279,9 @@ impl Violation for LoggingStringConcat {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -317,7 +317,7 @@ impl Violation for LoggingStringConcat {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html)
|
||||
|
@ -349,9 +349,9 @@ impl Violation for LoggingFString {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -368,7 +368,7 @@ impl Violation for LoggingFString {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging.warning`](https://docs.python.org/3/library/logging.html#logging.warning)
|
||||
|
@ -409,9 +409,9 @@ impl AlwaysFixableViolation for LoggingWarn {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -436,7 +436,7 @@ impl AlwaysFixableViolation for LoggingWarn {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: LogRecord attributes](https://docs.python.org/3/library/logging.html#logrecord-attributes)
|
||||
|
@ -470,9 +470,9 @@ impl Violation for LoggingExtraAttrClash {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -495,7 +495,7 @@ impl Violation for LoggingExtraAttrClash {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging.exception`](https://docs.python.org/3/library/logging.html#logging.exception)
|
||||
|
@ -531,9 +531,9 @@ impl Violation for LoggingExcInfo {
|
|||
/// - Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
|
||||
/// - Objects whose name starts with `log` or ends with `logger` or `logging`,
|
||||
/// when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
|
||||
/// - Imported objects marked as loggers via the [`logger-objects`] setting, which can be
|
||||
/// - Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
|
||||
/// used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
|
||||
/// when [`logger-objects`] is set to `["module.logger"]`).
|
||||
/// when [`lint.logger-objects`] is set to `["module.logger"]`).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -556,7 +556,7 @@ impl Violation for LoggingExcInfo {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `logger-objects`
|
||||
/// - `lint.logger-objects`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `logging.exception`](https://docs.python.org/3/library/logging.html#logging.exception)
|
||||
|
|
|
@ -24,7 +24,7 @@ use super::helpers::{
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for argument-free `@pytest.fixture()` decorators with or without
|
||||
/// parentheses, depending on the `flake8-pytest-style.fixture-parentheses`
|
||||
/// parentheses, depending on the [`lint.flake8-pytest-style.fixture-parentheses`]
|
||||
/// setting.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
|
@ -55,7 +55,7 @@ use super::helpers::{
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-pytest-style.fixture-parentheses`
|
||||
/// - `lint.flake8-pytest-style.fixture-parentheses`
|
||||
///
|
||||
/// ## References
|
||||
/// - [`pytest` documentation: API Reference: Fixtures](https://docs.pytest.org/en/latest/reference/reference.html#fixtures-api)
|
||||
|
|
|
@ -11,7 +11,7 @@ use super::helpers::get_mark_decorators;
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for argument-free `@pytest.mark.<marker>()` decorators with or
|
||||
/// without parentheses, depending on the `flake8-pytest-style.mark-parentheses`
|
||||
/// without parentheses, depending on the [`lint.flake8-pytest-style.mark-parentheses`]
|
||||
/// setting.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
|
@ -42,7 +42,7 @@ use super::helpers::get_mark_decorators;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-pytest-style.mark-parentheses`
|
||||
/// - `lint.flake8-pytest-style.mark-parentheses`
|
||||
///
|
||||
/// ## References
|
||||
/// - [`pytest` documentation: Marks](https://docs.pytest.org/en/latest/reference/reference.html#marks)
|
||||
|
|
|
@ -26,7 +26,7 @@ use super::helpers::{is_pytest_parametrize, split_names};
|
|||
/// The `argnames` argument of `pytest.mark.parametrize` takes a string or
|
||||
/// a sequence of strings. For a single parameter, it's preferable to use a
|
||||
/// string. For multiple parameters, it's preferable to use the style
|
||||
/// configured via the [`flake8-pytest-style.parametrize-names-type`] setting.
|
||||
/// configured via the [`lint.flake8-pytest-style.parametrize-names-type`] setting.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -67,7 +67,7 @@ use super::helpers::{is_pytest_parametrize, split_names};
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-pytest-style.parametrize-names-type`
|
||||
/// - `lint.flake8-pytest-style.parametrize-names-type`
|
||||
///
|
||||
/// ## References
|
||||
/// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize)
|
||||
|
@ -103,17 +103,17 @@ impl Violation for PytestParametrizeNamesWrongType {
|
|||
/// of values.
|
||||
///
|
||||
/// The style for the list of values rows can be configured via the
|
||||
/// the [`flake8-pytest-style.parametrize-values-type`] setting, while the
|
||||
/// the [`lint.flake8-pytest-style.parametrize-values-type`] setting, while the
|
||||
/// style for each row of values can be configured via the
|
||||
/// the [`flake8-pytest-style.parametrize-values-row-type`] setting.
|
||||
/// the [`lint.flake8-pytest-style.parametrize-values-row-type`] setting.
|
||||
///
|
||||
/// For example, [`flake8-pytest-style.parametrize-values-type`] will lead to
|
||||
/// For example, [`lint.flake8-pytest-style.parametrize-values-type`] will lead to
|
||||
/// the following expectations:
|
||||
///
|
||||
/// - `tuple`: `@pytest.mark.parametrize("value", ("a", "b", "c"))`
|
||||
/// - `list`: `@pytest.mark.parametrize("value", ["a", "b", "c"])`
|
||||
///
|
||||
/// Similarly, [`flake8-pytest-style.parametrize-values-row-type`] will lead to
|
||||
/// Similarly, [`lint.flake8-pytest-style.parametrize-values-row-type`] will lead to
|
||||
/// the following expectations:
|
||||
///
|
||||
/// - `tuple`: `@pytest.mark.parametrize(("key", "value"), [("a", "b"), ("c", "d")])`
|
||||
|
@ -170,8 +170,8 @@ impl Violation for PytestParametrizeNamesWrongType {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-pytest-style.parametrize-values-type`
|
||||
/// - `flake8-pytest-style.parametrize-values-row-type`
|
||||
/// - `lint.flake8-pytest-style.parametrize-values-type`
|
||||
/// - `lint.flake8-pytest-style.parametrize-values-row-type`
|
||||
///
|
||||
/// ## References
|
||||
/// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize)
|
||||
|
|
|
@ -64,8 +64,8 @@ impl Violation for PytestRaisesWithMultipleStatements {
|
|||
/// unrelated to the code under test. To avoid this, `pytest.raises` should be
|
||||
/// called with a `match` parameter. The exception names that require a `match`
|
||||
/// parameter can be configured via the
|
||||
/// `flake8-pytest-style.raises-require-match-for` and
|
||||
/// `flake8-pytest-style.raises-extend-require-match-for` settings.
|
||||
/// [`lint.flake8-pytest-style.raises-require-match-for`] and
|
||||
/// [`lint.flake8-pytest-style.raises-extend-require-match-for`] settings.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -92,8 +92,8 @@ impl Violation for PytestRaisesWithMultipleStatements {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-pytest-style.raises-require-match-for`
|
||||
/// - `flake8-pytest-style.raises-extend-require-match-for`
|
||||
/// - `lint.flake8-pytest-style.raises-require-match-for`
|
||||
/// - `lint.flake8-pytest-style.raises-extend-require-match-for`
|
||||
///
|
||||
/// ## References
|
||||
/// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises)
|
||||
|
|
|
@ -14,7 +14,7 @@ use super::super::settings::Quote;
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for inline strings that use single quotes or double quotes,
|
||||
/// depending on the value of the [`flake8-quotes.inline-quotes`] option.
|
||||
/// depending on the value of the [`lint.flake8-quotes.inline-quotes`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Consistency is good. Use either single or double quotes for inline
|
||||
|
@ -31,7 +31,7 @@ use super::super::settings::Quote;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.inline-quotes`
|
||||
/// - `lint.flake8-quotes.inline-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
|
@ -65,7 +65,7 @@ impl AlwaysFixableViolation for BadQuotesInlineString {
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for multiline strings that use single quotes or double quotes,
|
||||
/// depending on the value of the [`flake8-quotes.multiline-quotes`]
|
||||
/// depending on the value of the [`lint.flake8-quotes.multiline-quotes`]
|
||||
/// setting.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
|
@ -87,7 +87,7 @@ impl AlwaysFixableViolation for BadQuotesInlineString {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.multiline-quotes`
|
||||
/// - `lint.flake8-quotes.multiline-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
|
@ -121,7 +121,7 @@ impl AlwaysFixableViolation for BadQuotesMultilineString {
|
|||
|
||||
/// ## What it does
|
||||
/// Checks for docstrings that use single quotes or double quotes, depending
|
||||
/// on the value of the [`flake8-quotes.docstring-quotes`] setting.
|
||||
/// on the value of the [`lint.flake8-quotes.docstring-quotes`] setting.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Consistency is good. Use either single or double quotes for docstring
|
||||
|
@ -142,7 +142,7 @@ impl AlwaysFixableViolation for BadQuotesMultilineString {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.docstring-quotes`
|
||||
/// - `lint.flake8-quotes.docstring-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
|
|
|
@ -43,7 +43,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-self.ignore-names`
|
||||
/// - `lint.flake8-self.ignore-names`
|
||||
///
|
||||
/// ## References
|
||||
/// - [_What is the meaning of single or double underscores before an object name?_](https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-single-and-double-underscore-before-an-object-name)
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::rules::flake8_tidy_imports::matchers::NameMatchPolicy;
|
|||
/// automatic way.
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-tidy-imports.banned-api`
|
||||
/// - `lint.flake8-tidy-imports.banned-api`
|
||||
#[violation]
|
||||
pub struct BannedApi {
|
||||
name: String,
|
||||
|
|
|
@ -38,7 +38,7 @@ use crate::rules::flake8_tidy_imports::matchers::NameMatchPolicy;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-tidy-imports.banned-module-level-imports`
|
||||
/// - `lint.flake8-tidy-imports.banned-module-level-imports`
|
||||
#[violation]
|
||||
pub struct BannedModuleLevelImports {
|
||||
name: String,
|
||||
|
|
|
@ -42,7 +42,7 @@ use crate::rules::flake8_tidy_imports::settings::Strictness;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-tidy-imports.ban-relative-imports`
|
||||
/// - `lint.flake8-tidy-imports.ban-relative-imports`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#imports
|
||||
#[violation]
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::rules::flake8_type_checking::imports::ImportBinding;
|
|||
/// The type-checking block is not executed at runtime, so the import will not
|
||||
/// be available at runtime.
|
||||
///
|
||||
/// If [`flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// If [`lint.flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// annotations will be wrapped in quotes if doing so would enable the
|
||||
/// corresponding import to remain in the type-checking block.
|
||||
///
|
||||
|
@ -48,7 +48,7 @@ use crate::rules::flake8_type_checking::imports::ImportBinding;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-type-checking.quote-annotations`
|
||||
/// - `lint.flake8-type-checking.quote-annotations`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 535](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
|
||||
|
|
|
@ -28,14 +28,14 @@ use crate::rules::isort::{categorize, ImportSection, ImportType};
|
|||
/// instead be imported conditionally under an `if TYPE_CHECKING:` block to
|
||||
/// minimize runtime overhead.
|
||||
///
|
||||
/// If [`flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// If [`lint.flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// annotations will be wrapped in quotes if doing so would enable the
|
||||
/// corresponding import to be moved into an `if TYPE_CHECKING:` block.
|
||||
///
|
||||
/// If a class _requires_ that type annotations be available at runtime (as is
|
||||
/// the case for Pydantic, SQLAlchemy, and other libraries), consider using
|
||||
/// the [`flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// the [`lint.flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`lint.flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// as such.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -64,9 +64,9 @@ use crate::rules::isort::{categorize, ImportSection, ImportType};
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-type-checking.quote-annotations`
|
||||
/// - `flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `flake8-type-checking.runtime-evaluated-decorators`
|
||||
/// - `lint.flake8-type-checking.quote-annotations`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-decorators`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 536](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
|
||||
|
@ -101,14 +101,14 @@ impl Violation for TypingOnlyFirstPartyImport {
|
|||
/// instead be imported conditionally under an `if TYPE_CHECKING:` block to
|
||||
/// minimize runtime overhead.
|
||||
///
|
||||
/// If [`flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// If [`lint.flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// annotations will be wrapped in quotes if doing so would enable the
|
||||
/// corresponding import to be moved into an `if TYPE_CHECKING:` block.
|
||||
///
|
||||
/// If a class _requires_ that type annotations be available at runtime (as is
|
||||
/// the case for Pydantic, SQLAlchemy, and other libraries), consider using
|
||||
/// the [`flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// the [`lint.flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`lint.flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// as such.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -137,9 +137,9 @@ impl Violation for TypingOnlyFirstPartyImport {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-type-checking.quote-annotations`
|
||||
/// - `flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `flake8-type-checking.runtime-evaluated-decorators`
|
||||
/// - `lint.flake8-type-checking.quote-annotations`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-decorators`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 536](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
|
||||
|
@ -174,14 +174,14 @@ impl Violation for TypingOnlyThirdPartyImport {
|
|||
/// instead be imported conditionally under an `if TYPE_CHECKING:` block to
|
||||
/// minimize runtime overhead.
|
||||
///
|
||||
/// If [`flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// If [`lint.flake8-type-checking.quote-annotations`] is set to `true`,
|
||||
/// annotations will be wrapped in quotes if doing so would enable the
|
||||
/// corresponding import to be moved into an `if TYPE_CHECKING:` block.
|
||||
///
|
||||
/// If a class _requires_ that type annotations be available at runtime (as is
|
||||
/// the case for Pydantic, SQLAlchemy, and other libraries), consider using
|
||||
/// the [`flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// the [`lint.flake8-type-checking.runtime-evaluated-base-classes`] and
|
||||
/// [`lint.flake8-type-checking.runtime-evaluated-decorators`] settings to mark them
|
||||
/// as such.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -210,9 +210,9 @@ impl Violation for TypingOnlyThirdPartyImport {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-type-checking.quote-annotations`
|
||||
/// - `flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `flake8-type-checking.runtime-evaluated-decorators`
|
||||
/// - `lint.flake8-type-checking.quote-annotations`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-base-classes`
|
||||
/// - `lint.flake8-type-checking.runtime-evaluated-decorators`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 536](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
|
||||
|
|
|
@ -44,7 +44,7 @@ use ruff_python_ast::identifier::Identifier;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `mccabe.max-complexity`
|
||||
/// - `lint.mccabe.max-complexity`
|
||||
#[violation]
|
||||
pub struct ComplexStructure {
|
||||
name: String,
|
||||
|
|
|
@ -22,10 +22,10 @@ use crate::checkers::ast::Checker;
|
|||
/// > append a single trailing underscore rather than use an abbreviation or spelling corruption.
|
||||
/// > Thus `class_` is better than `clss`. (Perhaps better is to avoid such clashes by using a synonym.)
|
||||
///
|
||||
/// Names can be excluded from this rule using the [`pep8-naming.ignore-names`]
|
||||
/// or [`pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// Names can be excluded from this rule using the [`lint.pep8-naming.ignore-names`]
|
||||
/// or [`lint.pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// to allow the use of `klass` as the first argument to class methods, set
|
||||
/// the [`pep8-naming.extend-ignore-names`] option to `["klass"]`.
|
||||
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["klass"]`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -44,10 +44,10 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pep8-naming.classmethod-decorators`
|
||||
/// - `pep8-naming.staticmethod-decorators`
|
||||
/// - `pep8-naming.ignore-names`
|
||||
/// - `pep8-naming.extend-ignore-names`
|
||||
/// - `lint.pep8-naming.classmethod-decorators`
|
||||
/// - `lint.pep8-naming.staticmethod-decorators`
|
||||
/// - `lint.pep8-naming.ignore-names`
|
||||
/// - `lint.pep8-naming.extend-ignore-names`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
||||
#[violation]
|
||||
|
|
|
@ -22,10 +22,10 @@ use crate::checkers::ast::Checker;
|
|||
/// > append a single trailing underscore rather than use an abbreviation or spelling corruption.
|
||||
/// > Thus `class_` is better than `clss`. (Perhaps better is to avoid such clashes by using a synonym.)
|
||||
///
|
||||
/// Names can be excluded from this rule using the [`pep8-naming.ignore-names`]
|
||||
/// or [`pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// Names can be excluded from this rule using the [`lint.pep8-naming.ignore-names`]
|
||||
/// or [`lint.pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// to allow the use of `this` as the first argument to instance methods, set
|
||||
/// the [`pep8-naming.extend-ignore-names`] option to `["this"]`.
|
||||
/// the [`lint.pep8-naming.extend-ignore-names`] option to `["this"]`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -42,10 +42,10 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pep8-naming.classmethod-decorators`
|
||||
/// - `pep8-naming.staticmethod-decorators`
|
||||
/// - `pep8-naming.ignore-names`
|
||||
/// - `pep8-naming.extend-ignore-names`
|
||||
/// - `lint.pep8-naming.classmethod-decorators`
|
||||
/// - `lint.pep8-naming.staticmethod-decorators`
|
||||
/// - `lint.pep8-naming.ignore-names`
|
||||
/// - `lint.pep8-naming.extend-ignore-names`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
||||
#[violation]
|
||||
|
|
|
@ -20,10 +20,10 @@ use crate::settings::types::IdentifierPattern;
|
|||
/// > improve readability. mixedCase is allowed only in contexts where that’s already the
|
||||
/// > prevailing style (e.g. threading.py), to retain backwards compatibility.
|
||||
///
|
||||
/// Names can be excluded from this rule using the [`pep8-naming.ignore-names`]
|
||||
/// or [`pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// Names can be excluded from this rule using the [`lint.pep8-naming.ignore-names`]
|
||||
/// or [`lint.pep8-naming.extend-ignore-names`] configuration options. For example,
|
||||
/// to ignore all functions starting with `test_` from this rule, set the
|
||||
/// [`pep8-naming.extend-ignore-names`] option to `["test_*"]`.
|
||||
/// [`lint.pep8-naming.extend-ignore-names`] option to `["test_*"]`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -38,8 +38,8 @@ use crate::settings::types::IdentifierPattern;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pep8-naming.ignore-names`
|
||||
/// - `pep8-naming.extend-ignore-names`
|
||||
/// - `lint.pep8-naming.ignore-names`
|
||||
/// - `lint.pep8-naming.extend-ignore-names`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
||||
#[violation]
|
||||
|
|
|
@ -34,8 +34,8 @@ use crate::rules::pep8_naming::helpers;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pep8-naming.ignore-names`
|
||||
/// - `pep8-naming.extend-ignore-names`
|
||||
/// - `lint.pep8-naming.ignore-names`
|
||||
/// - `lint.pep8-naming.extend-ignore-names`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
||||
#[violation]
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::settings::LinterSettings;
|
|||
/// For flowing long blocks of text (docstrings or comments), overlong lines
|
||||
/// can hurt readability. [PEP 8], for example, recommends that such lines be
|
||||
/// limited to 72 characters, while this rule enforces the limit specified by
|
||||
/// the [`pycodestyle.max-doc-length`] setting. (If no value is provided, this
|
||||
/// the [`lint.pycodestyle.max-doc-length`] setting. (If no value is provided, this
|
||||
/// rule will be ignored, even if it's added to your `--select` list.)
|
||||
///
|
||||
/// In the context of this rule, a "doc line" is defined as a line consisting
|
||||
|
@ -32,8 +32,8 @@ use crate::settings::LinterSettings;
|
|||
/// overlong if a pragma comment _causes_ it to exceed the line length.
|
||||
/// (This behavior aligns with that of the Ruff formatter.)
|
||||
///
|
||||
/// If [`pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will
|
||||
/// also ignore comments that start with any of the specified [`task-tags`]
|
||||
/// If [`lint.pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will
|
||||
/// also ignore comments that start with any of the specified [`lint.task-tags`]
|
||||
/// (e.g., `# TODO:`).
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -65,9 +65,9 @@ use crate::settings::LinterSettings;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `task-tags`
|
||||
/// - `pycodestyle.max-doc-length`
|
||||
/// - `pycodestyle.ignore-overlong-task-comments`
|
||||
/// - `lint.task-tags`
|
||||
/// - `lint.pycodestyle.max-doc-length`
|
||||
/// - `lint.pycodestyle.ignore-overlong-task-comments`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
|
||||
#[violation]
|
||||
|
|
|
@ -28,8 +28,8 @@ use crate::settings::LinterSettings;
|
|||
/// overlong if a pragma comment _causes_ it to exceed the line length.
|
||||
/// (This behavior aligns with that of the Ruff formatter.)
|
||||
///
|
||||
/// If [`pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will
|
||||
/// also ignore comments that start with any of the specified [`task-tags`]
|
||||
/// If [`lint.pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will
|
||||
/// also ignore comments that start with any of the specified [`lint.task-tags`]
|
||||
/// (e.g., `# TODO:`).
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -60,9 +60,9 @@ use crate::settings::LinterSettings;
|
|||
///
|
||||
/// ## Options
|
||||
/// - `line-length`
|
||||
/// - `task-tags`
|
||||
/// - `pycodestyle.ignore-overlong-task-comments`
|
||||
/// - `pycodestyle.max-line-length`
|
||||
/// - `lint.task-tags`
|
||||
/// - `lint.pycodestyle.ignore-overlong-task-comments`
|
||||
/// - `lint.pycodestyle.max-line-length`
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
|
||||
#[violation]
|
||||
|
|
|
@ -37,7 +37,7 @@ use crate::registry::Rule;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// [D211]: https://docs.astral.sh/ruff/rules/blank-line-before-class
|
||||
#[violation]
|
||||
|
@ -84,7 +84,7 @@ impl AlwaysFixableViolation for OneBlankLineBeforeClass {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -134,7 +134,7 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// [D203]: https://docs.astral.sh/ruff/rules/one-blank-line-before-class
|
||||
#[violation]
|
||||
|
|
|
@ -36,7 +36,7 @@ use crate::rules::pydocstyle::helpers::logical_line;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -37,7 +37,7 @@ use crate::rules::pydocstyle::helpers::logical_line;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -32,7 +32,7 @@ use crate::docstrings::Docstring;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -43,7 +43,7 @@ static MOOD: Lazy<Mood> = Lazy::new(Mood::new);
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -76,7 +76,7 @@ use crate::rules::pydocstyle::settings::Convention;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -175,7 +175,7 @@ impl AlwaysFixableViolation for SectionNotOverIndented {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -253,7 +253,7 @@ impl AlwaysFixableViolation for SectionUnderlineNotOverIndented {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -350,7 +350,7 @@ impl AlwaysFixableViolation for CapitalizeSectionName {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -446,7 +446,7 @@ impl AlwaysFixableViolation for NewLineAfterSectionName {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -548,7 +548,7 @@ impl AlwaysFixableViolation for DashedUnderlineAfterSection {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -647,7 +647,7 @@ impl AlwaysFixableViolation for SectionUnderlineAfterName {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -741,7 +741,7 @@ impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -835,7 +835,7 @@ impl AlwaysFixableViolation for NoBlankLineAfterSection {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -931,7 +931,7 @@ impl AlwaysFixableViolation for NoBlankLineBeforeSection {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -1021,7 +1021,7 @@ impl AlwaysFixableViolation for BlankLineAfterLastSection {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -1098,7 +1098,7 @@ impl Violation for EmptyDocstringSection {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -1180,7 +1180,7 @@ impl AlwaysFixableViolation for SectionNameEndsInColon {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
@ -1264,7 +1264,7 @@ impl Violation for UndocumentedParam {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -33,7 +33,7 @@ use crate::rules::pydocstyle::helpers::normalize_word;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pydocstyle.convention`
|
||||
/// - `lint.pydocstyle.convention`
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
|
|
|
@ -54,7 +54,7 @@ enum UnusedImportContext {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pyflakes.extend-generics`
|
||||
/// - `lint.pyflakes.extend-generics`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement)
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::fix::edits::delete_stmt;
|
|||
///
|
||||
/// If a variable is intentionally defined-but-not-used, it should be
|
||||
/// prefixed with an underscore, or some other value that adheres to the
|
||||
/// [`dummy-variable-rgx`] pattern.
|
||||
/// [`lint.dummy-variable-rgx`] pattern.
|
||||
///
|
||||
/// Under [preview mode](https://docs.astral.sh/ruff/preview), this rule also
|
||||
/// triggers on unused unpacked assignments (for example, `x, y = foo()`).
|
||||
|
@ -43,7 +43,7 @@ use crate::fix::edits::delete_stmt;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `dummy-variable-rgx`
|
||||
/// - `lint.dummy-variable-rgx`
|
||||
#[violation]
|
||||
pub struct UnusedVariable {
|
||||
pub name: String,
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::rules::pylint::helpers::is_known_dunder_method;
|
|||
/// `__init__`), as well as methods that are marked with `@override`.
|
||||
///
|
||||
/// Additional dunder methods names can be allowed via the
|
||||
/// [`pylint.allow-dunder-method-names`] setting.
|
||||
/// [`lint.pylint.allow-dunder-method-names`] setting.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -41,7 +41,7 @@ use crate::rules::pylint::helpers::is_known_dunder_method;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.allow-dunder-method-names`
|
||||
/// - `lint.pylint.allow-dunder-method-names`
|
||||
#[violation]
|
||||
pub struct BadDunderMethodName {
|
||||
name: String,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for function definitions that include too many arguments.
|
||||
///
|
||||
/// By default, this rule allows up to five arguments, as configured by the
|
||||
/// [`pylint.max-args`] option.
|
||||
/// [`lint.pylint.max-args`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions with many arguments are harder to understand, maintain, and call.
|
||||
|
@ -42,7 +42,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-args`
|
||||
/// - `lint.pylint.max-args`
|
||||
#[violation]
|
||||
pub struct TooManyArguments {
|
||||
c_args: usize,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for too many Boolean expressions in an `if` statement.
|
||||
///
|
||||
/// By default, this rule allows up to 5 expressions. This can be configured
|
||||
/// using the [`pylint.max-bool-expr`] option.
|
||||
/// using the [`lint.pylint.max-bool-expr`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `if` statements with many Boolean expressions are harder to understand
|
||||
|
@ -24,7 +24,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-bool-expr`
|
||||
/// - `lint.pylint.max-bool-expr`
|
||||
#[violation]
|
||||
pub struct TooManyBooleanExpressions {
|
||||
expressions: usize,
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruff_python_ast::identifier::Identifier;
|
|||
/// Checks for functions or methods with too many branches.
|
||||
///
|
||||
/// By default, this rule allows up to 12 branches. This can be configured
|
||||
/// using the [`pylint.max-branches`] option.
|
||||
/// using the [`lint.pylint.max-branches`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions or methods with many branches are harder to understand
|
||||
|
@ -67,7 +67,7 @@ use ruff_python_ast::identifier::Identifier;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-branches`
|
||||
/// - `lint.pylint.max-branches`
|
||||
#[violation]
|
||||
pub struct TooManyBranches {
|
||||
branches: usize,
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for functions that include too many local variables.
|
||||
///
|
||||
/// By default, this rule allows up to fifteen locals, as configured by the
|
||||
/// [`pylint.max-locals`] option.
|
||||
/// [`lint.pylint.max-locals`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions with many local variables are harder to understand and maintain.
|
||||
|
@ -18,7 +18,7 @@ use crate::checkers::ast::Checker;
|
|||
/// functions with fewer assignments.
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-locals`
|
||||
/// - `lint.pylint.max-locals`
|
||||
#[violation]
|
||||
pub struct TooManyLocals {
|
||||
current_amount: usize,
|
||||
|
|
|
@ -10,14 +10,14 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for functions or methods with too many nested blocks.
|
||||
///
|
||||
/// By default, this rule allows up to five nested blocks.
|
||||
/// This can be configured using the [`pylint.max-nested-blocks`] option.
|
||||
/// This can be configured using the [`lint.pylint.max-nested-blocks`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions or methods with too many nested blocks are harder to understand
|
||||
/// and maintain.
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-nested-blocks`
|
||||
/// - `lint.pylint.max-nested-blocks`
|
||||
#[violation]
|
||||
pub struct TooManyNestedBlocks {
|
||||
nested_blocks: usize,
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for function definitions that include too many positional arguments.
|
||||
///
|
||||
/// By default, this rule allows up to five arguments, as configured by the
|
||||
/// [`pylint.max-positional-args`] option.
|
||||
/// [`lint.pylint.max-positional-args`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions with many arguments are harder to understand, maintain, and call.
|
||||
|
@ -40,7 +40,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-positional-args`
|
||||
/// - `lint.pylint.max-positional-args`
|
||||
#[violation]
|
||||
pub struct TooManyPositional {
|
||||
c_pos: usize,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for classes with too many public methods
|
||||
///
|
||||
/// By default, this rule allows up to 20 public methods, as configured by
|
||||
/// the [`pylint.max-public-methods`] option.
|
||||
/// the [`lint.pylint.max-public-methods`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Classes with many public methods are harder to understand
|
||||
|
@ -81,7 +81,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-public-methods`
|
||||
/// - `lint.pylint.max-public-methods`
|
||||
#[violation]
|
||||
pub struct TooManyPublicMethods {
|
||||
methods: usize,
|
||||
|
|
|
@ -10,7 +10,7 @@ use ruff_python_ast::visitor::Visitor;
|
|||
/// Checks for functions or methods with too many return statements.
|
||||
///
|
||||
/// By default, this rule allows up to six return statements, as configured by
|
||||
/// the [`pylint.max-returns`] option.
|
||||
/// the [`lint.pylint.max-returns`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions or methods with many return statements are harder to understand
|
||||
|
@ -50,7 +50,7 @@ use ruff_python_ast::visitor::Visitor;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-returns`
|
||||
/// - `lint.pylint.max-returns`
|
||||
#[violation]
|
||||
pub struct TooManyReturnStatements {
|
||||
returns: usize,
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruff_python_ast::identifier::Identifier;
|
|||
/// Checks for functions or methods with too many statements.
|
||||
///
|
||||
/// By default, this rule allows up to 50 statements, as configured by the
|
||||
/// [`pylint.max-statements`] option.
|
||||
/// [`lint.pylint.max-statements`] option.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Functions or methods with many statements are harder to understand
|
||||
|
@ -44,7 +44,7 @@ use ruff_python_ast::identifier::Identifier;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `pylint.max-statements`
|
||||
/// - `lint.pylint.max-statements`
|
||||
#[violation]
|
||||
pub struct TooManyStatements {
|
||||
statements: usize,
|
||||
|
|
|
@ -30,7 +30,7 @@ use crate::settings::types::PythonVersion;
|
|||
/// `__future__` annotations are not evaluated at runtime. If your code relies
|
||||
/// on runtime type annotations (either directly or via a library like
|
||||
/// Pydantic), you can disable this behavior for Python versions prior to 3.9
|
||||
/// by setting [`pyupgrade.keep-runtime-typing`] to `true`.
|
||||
/// by setting [`lint.pyupgrade.keep-runtime-typing`] to `true`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -51,7 +51,7 @@ use crate::settings::types::PythonVersion;
|
|||
///
|
||||
/// ## Options
|
||||
/// - `target-version`
|
||||
/// - `pyupgrade.keep-runtime-typing`
|
||||
/// - `lint.pyupgrade.keep-runtime-typing`
|
||||
///
|
||||
/// [PEP 585]: https://peps.python.org/pep-0585/
|
||||
#[violation]
|
||||
|
|
|
@ -23,7 +23,7 @@ use crate::settings::types::PythonVersion;
|
|||
/// `__future__` annotations are not evaluated at runtime. If your code relies
|
||||
/// on runtime type annotations (either directly or via a library like
|
||||
/// Pydantic), you can disable this behavior for Python versions prior to 3.10
|
||||
/// by setting [`pyupgrade.keep-runtime-typing`] to `true`.
|
||||
/// by setting [`lint.pyupgrade.keep-runtime-typing`] to `true`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -46,7 +46,7 @@ use crate::settings::types::PythonVersion;
|
|||
///
|
||||
/// ## Options
|
||||
/// - `target-version`
|
||||
/// - `pyupgrade.keep-runtime-typing`
|
||||
/// - `lint.pyupgrade.keep-runtime-typing`
|
||||
///
|
||||
/// [PEP 604]: https://peps.python.org/pep-0604/
|
||||
#[violation]
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::settings::LinterSettings;
|
|||
/// spec recommends `GREEK CAPITAL LETTER OMEGA` over `OHM SIGN`.
|
||||
///
|
||||
/// You can omit characters from being flagged as ambiguous via the
|
||||
/// [`allowed-confusables`] setting.
|
||||
/// [`lint.allowed-confusables`] setting.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -41,7 +41,7 @@ use crate::settings::LinterSettings;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `allowed-confusables`
|
||||
/// - `lint.allowed-confusables`
|
||||
///
|
||||
/// [preview]: https://docs.astral.sh/ruff/preview/
|
||||
#[violation]
|
||||
|
@ -94,7 +94,7 @@ impl Violation for AmbiguousUnicodeCharacterString {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `allowed-confusables`
|
||||
/// - `lint.allowed-confusables`
|
||||
///
|
||||
/// [preview]: https://docs.astral.sh/ruff/preview/
|
||||
#[violation]
|
||||
|
@ -147,7 +147,7 @@ impl Violation for AmbiguousUnicodeCharacterDocstring {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `allowed-confusables`
|
||||
/// - `lint.allowed-confusables`
|
||||
///
|
||||
/// [preview]: https://docs.astral.sh/ruff/preview/
|
||||
#[violation]
|
||||
|
|
|
@ -53,7 +53,7 @@ use crate::rules::ruff::rules::helpers::{
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `flake8-bugbear.extend-immutable-calls`
|
||||
/// - `lint.flake8-bugbear.extend-immutable-calls`
|
||||
#[violation]
|
||||
pub struct FunctionCallInDataclassDefaultArgument {
|
||||
name: Option<String>,
|
||||
|
|
|
@ -30,7 +30,7 @@ use crate::checkers::ast::Checker;
|
|||
/// ...
|
||||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// ## References
|
||||
/// - [Python documentation: `typing.Never`](https://docs.python.org/3/library/typing.html#typing.Never)
|
||||
/// - [Python documentation: `typing.NoReturn`](https://docs.python.org/3/library/typing.html#typing.NoReturn)
|
||||
#[violation]
|
||||
|
|
|
@ -36,7 +36,7 @@ pub struct UnusedCodes {
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `external`
|
||||
/// - `lint.external`
|
||||
///
|
||||
/// ## References
|
||||
/// - [Ruff error suppression](https://docs.astral.sh/ruff/linter/#error-suppression)
|
||||
|
|
|
@ -396,11 +396,11 @@ impl Configuration {
|
|||
|
||||
pub fn from_options(options: Options, project_root: &Path) -> Result<Self> {
|
||||
let lint = if let Some(mut lint) = options.lint {
|
||||
lint.common = lint.common.combine(options.lint_top_level);
|
||||
lint.common = lint.common.combine(options.lint_top_level.common);
|
||||
lint
|
||||
} else {
|
||||
LintOptions {
|
||||
common: options.lint_top_level,
|
||||
common: options.lint_top_level.common,
|
||||
..LintOptions::default()
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::options_base::{OptionsMetadata, Visit};
|
||||
use ruff_formatter::IndentStyle;
|
||||
use ruff_linter::line_width::{IndentWidth, LineLength};
|
||||
use ruff_linter::rules::flake8_pytest_style::settings::SettingsError;
|
||||
|
@ -420,21 +421,21 @@ pub struct Options {
|
|||
)]
|
||||
pub tab_size: Option<IndentWidth>,
|
||||
|
||||
#[option_group]
|
||||
pub lint: Option<LintOptions>,
|
||||
|
||||
/// The lint sections specified at the top level.
|
||||
#[serde(flatten)]
|
||||
pub lint_top_level: LintCommonOptions,
|
||||
pub lint_top_level: DeprecatedTopLevelLintOptions,
|
||||
|
||||
/// Options to configure code formatting.
|
||||
#[option_group]
|
||||
pub format: Option<FormatOptions>,
|
||||
}
|
||||
|
||||
/// Experimental section to configure Ruff's linting. This new section will eventually
|
||||
/// replace the top-level linting options.
|
||||
/// Configures how ruff checks your code.
|
||||
///
|
||||
/// Options specified in the `lint` section take precedence over the top-level settings.
|
||||
/// Options specified in the `lint` section take precedence over the deprecated top-level settings.
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[derive(Debug, PartialEq, Eq, Default, OptionsMetadata, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
|
@ -477,15 +478,69 @@ pub struct LintOptions {
|
|||
pub preview: Option<bool>,
|
||||
}
|
||||
|
||||
/// Newtype wrapper for [`LintCommonOptions`] that allows customizing the JSON schema and omitting the fields from the [`OptionsMetadata`].
|
||||
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct DeprecatedTopLevelLintOptions {
|
||||
pub common: LintCommonOptions,
|
||||
}
|
||||
|
||||
impl OptionsMetadata for DeprecatedTopLevelLintOptions {
|
||||
fn record(_visit: &mut dyn Visit) {
|
||||
// Intentionally empty. Omit all fields from the documentation and instead promote the options under the `lint.` section.
|
||||
// This doesn't create an empty 'common' option because the field in the `Options` struct is marked with `#[serde(flatten)]`.
|
||||
// Meaning, the code here flattens no-properties into the parent, which is what we want.
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "schemars")]
|
||||
impl schemars::JsonSchema for DeprecatedTopLevelLintOptions {
|
||||
fn schema_name() -> std::string::String {
|
||||
"DeprecatedTopLevelLintOptions".to_owned()
|
||||
}
|
||||
fn schema_id() -> std::borrow::Cow<'static, str> {
|
||||
std::borrow::Cow::Borrowed(std::concat!(
|
||||
std::module_path!(),
|
||||
"::",
|
||||
"DeprecatedTopLevelLintOptions"
|
||||
))
|
||||
}
|
||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
||||
use schemars::schema::Schema;
|
||||
|
||||
let common_schema = LintCommonOptions::json_schema(gen);
|
||||
let mut schema_obj = common_schema.into_object();
|
||||
|
||||
if let Some(object) = schema_obj.object.as_mut() {
|
||||
for property in object.properties.values_mut() {
|
||||
if let Schema::Object(property_object) = property {
|
||||
if let Some(metadata) = &mut property_object.metadata {
|
||||
metadata.deprecated = true;
|
||||
} else {
|
||||
property_object.metadata = Some(Box::new(schemars::schema::Metadata {
|
||||
deprecated: true,
|
||||
..schemars::schema::Metadata::default()
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Schema::Object(schema_obj)
|
||||
}
|
||||
}
|
||||
|
||||
// Note: This struct should be inlined into [`LintOptions`] once support for the top-level lint settings
|
||||
// is removed.
|
||||
|
||||
// Don't add any new options to this struct. Add them to [`LintOptions`] directly to avoid exposing them in the
|
||||
// global settings.
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, Default, OptionsMetadata, CombineOptions, Serialize, Deserialize,
|
||||
)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
pub struct LintCommonOptions {
|
||||
// WARNING: Don't add new options to this type. Add them to `LintOptions` instead.
|
||||
/// A list of allowed "confusable" Unicode characters to ignore when
|
||||
/// enforcing `RUF001`, `RUF002`, and `RUF003`.
|
||||
#[option(
|
||||
|
@ -734,6 +789,7 @@ pub struct LintCommonOptions {
|
|||
)]
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
|
||||
// WARNING: Don't add new options to this type. Add them to `LintOptions` instead.
|
||||
/// Options for the `flake8-annotations` plugin.
|
||||
#[option_group]
|
||||
pub flake8_annotations: Option<Flake8AnnotationsOptions>,
|
||||
|
@ -830,6 +886,8 @@ pub struct LintCommonOptions {
|
|||
#[option_group]
|
||||
pub pyupgrade: Option<PyUpgradeOptions>,
|
||||
|
||||
// WARNING: Don't add new options to this type. Add them to `LintOptions` instead.
|
||||
|
||||
// Tables are required to go last.
|
||||
/// A list of mappings from file pattern to rule codes or prefixes to
|
||||
/// exclude, when considering any matching files.
|
||||
|
@ -857,6 +915,7 @@ pub struct LintCommonOptions {
|
|||
"#
|
||||
)]
|
||||
pub extend_per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
|
||||
// WARNING: Don't add new options to this type. Add them to `LintOptions` instead.
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
|
@ -2816,9 +2875,7 @@ impl PyUpgradeOptions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Experimental: Configures how `ruff format` formats your code.
|
||||
///
|
||||
/// Please provide feedback in [this discussion](https://github.com/astral-sh/ruff/discussions/7310).
|
||||
/// Configures the way ruff formats your code.
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, Default, Deserialize, Serialize, OptionsMetadata, CombineOptions,
|
||||
)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue