mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
Improvement documentation around ignore-names
globbing (#7674)
## Summary Improves the documentation on the setting itself, along with that on the relevant rules. Closes https://github.com/astral-sh/ruff/issues/7660.
This commit is contained in:
parent
0a8cad2550
commit
15f3d8c8e0
6 changed files with 40 additions and 7 deletions
|
@ -22,6 +22,11 @@ use crate::checkers::ast::Checker;
|
||||||
/// > append a single trailing underscore rather than use an abbreviation or spelling corruption.
|
/// > 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.)
|
/// > 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,
|
||||||
|
/// to allow the use of `klass` as the first argument to class methods, set
|
||||||
|
/// the [`pep8-naming.extend-ignore-names`] option to `["klass"]`.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
|
@ -42,6 +47,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// - `pep8-naming.classmethod-decorators`
|
/// - `pep8-naming.classmethod-decorators`
|
||||||
/// - `pep8-naming.staticmethod-decorators`
|
/// - `pep8-naming.staticmethod-decorators`
|
||||||
/// - `pep8-naming.ignore-names`
|
/// - `pep8-naming.ignore-names`
|
||||||
|
/// - `pep8-naming.extend-ignore-names`
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
||||||
#[violation]
|
#[violation]
|
||||||
|
|
|
@ -22,6 +22,11 @@ use crate::checkers::ast::Checker;
|
||||||
/// > append a single trailing underscore rather than use an abbreviation or spelling corruption.
|
/// > 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.)
|
/// > 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,
|
||||||
|
/// to allow the use of `this` as the first argument to instance methods, set
|
||||||
|
/// the [`pep8-naming.extend-ignore-names`] option to `["this"]`.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Example:
|
/// class Example:
|
||||||
|
@ -40,6 +45,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// - `pep8-naming.classmethod-decorators`
|
/// - `pep8-naming.classmethod-decorators`
|
||||||
/// - `pep8-naming.staticmethod-decorators`
|
/// - `pep8-naming.staticmethod-decorators`
|
||||||
/// - `pep8-naming.ignore-names`
|
/// - `pep8-naming.ignore-names`
|
||||||
|
/// - `pep8-naming.extend-ignore-names`
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
|
||||||
#[violation]
|
#[violation]
|
||||||
|
|
|
@ -20,6 +20,11 @@ use crate::settings::types::IdentifierPattern;
|
||||||
/// > improve readability. mixedCase is allowed only in contexts where that’s already the
|
/// > improve readability. mixedCase is allowed only in contexts where that’s already the
|
||||||
/// > prevailing style (e.g. threading.py), to retain backwards compatibility.
|
/// > 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,
|
||||||
|
/// to ignore all functions starting with `test_` from this rule, set the
|
||||||
|
/// [`pep8-naming.extend-ignore-names`] option to `["test_*"]`.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def myFunction():
|
/// def myFunction():
|
||||||
|
@ -34,6 +39,7 @@ use crate::settings::types::IdentifierPattern;
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
/// - `pep8-naming.ignore-names`
|
/// - `pep8-naming.ignore-names`
|
||||||
|
/// - `pep8-naming.extend-ignore-names`
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
||||||
#[violation]
|
#[violation]
|
||||||
|
|
|
@ -35,6 +35,7 @@ use crate::rules::pep8_naming::helpers;
|
||||||
///
|
///
|
||||||
/// ## Options
|
/// ## Options
|
||||||
/// - `pep8-naming.ignore-names`
|
/// - `pep8-naming.ignore-names`
|
||||||
|
/// - `pep8-naming.extend-ignore-names`
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names
|
||||||
#[violation]
|
#[violation]
|
||||||
|
|
|
@ -2050,6 +2050,10 @@ impl McCabeOptions {
|
||||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||||
pub struct Pep8NamingOptions {
|
pub struct Pep8NamingOptions {
|
||||||
/// A list of names (or patterns) to ignore when considering `pep8-naming` violations.
|
/// A list of names (or patterns) to ignore when considering `pep8-naming` violations.
|
||||||
|
///
|
||||||
|
/// Supports glob patterns. For example, to ignore all names starting with
|
||||||
|
/// or ending with `_test`, you could use `ignore-names = ["test_*", "*_test"]`.
|
||||||
|
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
|
||||||
#[option(
|
#[option(
|
||||||
default = r#"["setUp", "tearDown", "setUpClass", "tearDownClass", "setUpModule", "tearDownModule", "asyncSetUp", "asyncTearDown", "setUpTestData", "failureException", "longMessage", "maxDiff"]"#,
|
default = r#"["setUp", "tearDown", "setUpClass", "tearDownClass", "setUpModule", "tearDownModule", "asyncSetUp", "asyncTearDown", "setUpTestData", "failureException", "longMessage", "maxDiff"]"#,
|
||||||
value_type = "list[str]",
|
value_type = "list[str]",
|
||||||
|
@ -2060,7 +2064,11 @@ pub struct Pep8NamingOptions {
|
||||||
pub ignore_names: Option<Vec<String>>,
|
pub ignore_names: Option<Vec<String>>,
|
||||||
|
|
||||||
/// Additional names (or patterns) to ignore when considering `pep8-naming` violations,
|
/// Additional names (or patterns) to ignore when considering `pep8-naming` violations,
|
||||||
/// in addition to those included in `ignore-names`.
|
/// in addition to those included in `ignore-names`
|
||||||
|
///
|
||||||
|
/// Supports glob patterns. For example, to ignore all names starting with
|
||||||
|
/// or ending with `_test`, you could use `ignore-names = ["test_*", "*_test"]`.
|
||||||
|
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax)..
|
||||||
#[option(
|
#[option(
|
||||||
default = r#"[]"#,
|
default = r#"[]"#,
|
||||||
value_type = "list[str]",
|
value_type = "list[str]",
|
||||||
|
@ -2074,6 +2082,9 @@ pub struct Pep8NamingOptions {
|
||||||
///
|
///
|
||||||
/// For example, Ruff will expect that any method decorated by a decorator
|
/// For example, Ruff will expect that any method decorated by a decorator
|
||||||
/// in this list takes a `cls` argument as its first argument.
|
/// in this list takes a `cls` argument as its first argument.
|
||||||
|
///
|
||||||
|
/// Expects to receive a list of fully-qualified names (e.g., `pydantic.validator`,
|
||||||
|
/// rather than `validator`).
|
||||||
#[option(
|
#[option(
|
||||||
default = r#"[]"#,
|
default = r#"[]"#,
|
||||||
value_type = "list[str]",
|
value_type = "list[str]",
|
||||||
|
@ -2090,12 +2101,15 @@ pub struct Pep8NamingOptions {
|
||||||
///
|
///
|
||||||
/// For example, Ruff will expect that any method decorated by a decorator
|
/// For example, Ruff will expect that any method decorated by a decorator
|
||||||
/// in this list has no `self` or `cls` argument.
|
/// in this list has no `self` or `cls` argument.
|
||||||
|
///
|
||||||
|
/// Expects to receive a list of fully-qualified names (e.g., `belay.Device.teardown`,
|
||||||
|
/// rather than `teardown`).
|
||||||
#[option(
|
#[option(
|
||||||
default = r#"[]"#,
|
default = r#"[]"#,
|
||||||
value_type = "list[str]",
|
value_type = "list[str]",
|
||||||
example = r#"
|
example = r#"
|
||||||
# Allow a shorthand alias, `@stcmthd`, to trigger static method treatment.
|
# Allow Belay's `@Device.teardown` decorator to trigger static method treatment.
|
||||||
staticmethod-decorators = ["stcmthd"]
|
staticmethod-decorators = ["belay.Device.teardown"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
pub staticmethod_decorators: Option<Vec<String>>,
|
pub staticmethod_decorators: Option<Vec<String>>,
|
||||||
|
|
8
ruff.schema.json
generated
8
ruff.schema.json
generated
|
@ -1576,7 +1576,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"classmethod-decorators": {
|
"classmethod-decorators": {
|
||||||
"description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a class method (in addition to the builtin `@classmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list takes a `cls` argument as its first argument.",
|
"description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a class method (in addition to the builtin `@classmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list takes a `cls` argument as its first argument.\n\nExpects to receive a list of fully-qualified names (e.g., `pydantic.validator`, rather than `validator`).",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
@ -1586,7 +1586,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extend-ignore-names": {
|
"extend-ignore-names": {
|
||||||
"description": "Additional names (or patterns) to ignore when considering `pep8-naming` violations, in addition to those included in `ignore-names`.",
|
"description": "Additional names (or patterns) to ignore when considering `pep8-naming` violations, in addition to those included in `ignore-names`\n\nSupports glob patterns. For example, to ignore all names starting with or ending with `_test`, you could use `ignore-names = [\"test_*\", \"*_test\"]`. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax)..",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
@ -1596,7 +1596,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ignore-names": {
|
"ignore-names": {
|
||||||
"description": "A list of names (or patterns) to ignore when considering `pep8-naming` violations.",
|
"description": "A list of names (or patterns) to ignore when considering `pep8-naming` violations.\n\nSupports glob patterns. For example, to ignore all names starting with or ending with `_test`, you could use `ignore-names = [\"test_*\", \"*_test\"]`. For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
@ -1606,7 +1606,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"staticmethod-decorators": {
|
"staticmethod-decorators": {
|
||||||
"description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a static method (in addition to the builtin `@staticmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list has no `self` or `cls` argument.",
|
"description": "A list of decorators that, when applied to a method, indicate that the method should be treated as a static method (in addition to the builtin `@staticmethod`).\n\nFor example, Ruff will expect that any method decorated by a decorator in this list has no `self` or `cls` argument.\n\nExpects to receive a list of fully-qualified names (e.g., `belay.Device.teardown`, rather than `teardown`).",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue