Skip to content

Add allow-invalid configuration option for disallowed_* to the documentation #14845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ The maximum cognitive complexity a function can have
## `disallowed-macros`
The list of disallowed macros, written as fully qualified paths.

**Fields:**
- `path` (required): the fully qualified path to the macro that should be disallowed
- `reason` (optional): explanation why this macro is disallowed
- `replacement` (optional): suggested alternative macro
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
if the path doesn't exist, instead of emitting an error

**Default Value:** `[]`

---
Expand All @@ -488,6 +495,13 @@ The list of disallowed macros, written as fully qualified paths.
## `disallowed-methods`
The list of disallowed methods, written as fully qualified paths.

**Fields:**
- `path` (required): the fully qualified path to the method that should be disallowed
- `reason` (optional): explanation why this method is disallowed
- `replacement` (optional): suggested alternative method
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
if the path doesn't exist, instead of emitting an error

**Default Value:** `[]`

---
Expand All @@ -510,6 +524,13 @@ default configuration of Clippy. By default, any configuration will replace the
## `disallowed-types`
The list of disallowed types, written as fully qualified paths.

**Fields:**
- `path` (required): the fully qualified path to the type that should be disallowed
- `reason` (optional): explanation why this type is disallowed
- `replacement` (optional): suggested alternative type
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
if the path doesn't exist, instead of emitting an error

**Default Value:** `[]`

---
Expand Down
21 changes: 21 additions & 0 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,24 @@ define_Conf! {
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
cyclomatic_complexity_threshold: u64 = 25,
/// The list of disallowed macros, written as fully qualified paths.
///
/// **Fields:**
/// - `path` (required): the fully qualified path to the macro that should be disallowed
/// - `reason` (optional): explanation why this macro is disallowed
/// - `replacement` (optional): suggested alternative macro
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
/// if the path doesn't exist, instead of emitting an error
#[disallowed_paths_allow_replacements = true]
#[lints(disallowed_macros)]
disallowed_macros: Vec<DisallowedPath> = Vec::new(),
/// The list of disallowed methods, written as fully qualified paths.
///
/// **Fields:**
/// - `path` (required): the fully qualified path to the method that should be disallowed
/// - `reason` (optional): explanation why this method is disallowed
/// - `replacement` (optional): suggested alternative method
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
/// if the path doesn't exist, instead of emitting an error
#[disallowed_paths_allow_replacements = true]
#[lints(disallowed_methods)]
disallowed_methods: Vec<DisallowedPath> = Vec::new(),
Expand All @@ -585,6 +599,13 @@ define_Conf! {
#[lints(disallowed_names)]
disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect(),
/// The list of disallowed types, written as fully qualified paths.
///
/// **Fields:**
/// - `path` (required): the fully qualified path to the type that should be disallowed
/// - `reason` (optional): explanation why this type is disallowed
/// - `replacement` (optional): suggested alternative type
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
/// if the path doesn't exist, instead of emitting an error
#[disallowed_paths_allow_replacements = true]
#[lints(disallowed_types)]
disallowed_types: Vec<DisallowedPath> = Vec::new(),
Expand Down
3 changes: 3 additions & 0 deletions clippy_lints/src/disallowed_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ declare_clippy_lint! {
/// # When using an inline table, can add a `reason` for why the macro
/// # is disallowed.
/// { path = "serde::Serialize", reason = "no serializing" },
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
/// # it will be silently ignored
/// { path = "std::invalid_macro", reason = "use alternative instead", allow-invalid = true }
/// ]
/// ```
/// ```no_run
Expand Down
3 changes: 3 additions & 0 deletions clippy_lints/src/disallowed_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ declare_clippy_lint! {
/// { path = "std::vec::Vec::leak", reason = "no leaking memory" },
/// # Can also add a `replacement` that will be offered as a suggestion.
/// { path = "std::sync::Mutex::new", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex::new" },
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
/// # it will be silently ignored
/// { path = "std::fs::InvalidPath", reason = "use alternative instead", allow-invalid = true },
/// ]
/// ```
///
Expand Down
3 changes: 3 additions & 0 deletions clippy_lints/src/disallowed_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ declare_clippy_lint! {
/// { path = "std::net::Ipv4Addr", reason = "no IPv4 allowed" },
/// # Can also add a `replacement` that will be offered as a suggestion.
/// { path = "std::sync::Mutex", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex" },
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
/// # it will be silently ignored
/// { path = "std::invalid::Type", reason = "use alternative instead", allow-invalid = true }
/// ]
/// ```
///
Expand Down