Skip to content

Commit 19c1c70

Browse files
Add allow-invalid configuration option for disallowed_* to the documentation (#14845)
Close #14836 changelog: none
2 parents b765acb + 0bac1ca commit 19c1c70

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

book/src/lint_configuration.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ The maximum cognitive complexity a function can have
488488
## `disallowed-macros`
489489
The list of disallowed macros, written as fully qualified paths.
490490

491+
**Fields:**
492+
- `path` (required): the fully qualified path to the macro that should be disallowed
493+
- `reason` (optional): explanation why this macro is disallowed
494+
- `replacement` (optional): suggested alternative macro
495+
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
496+
if the path doesn't exist, instead of emitting an error
497+
491498
**Default Value:** `[]`
492499

493500
---
@@ -498,6 +505,13 @@ The list of disallowed macros, written as fully qualified paths.
498505
## `disallowed-methods`
499506
The list of disallowed methods, written as fully qualified paths.
500507

508+
**Fields:**
509+
- `path` (required): the fully qualified path to the method that should be disallowed
510+
- `reason` (optional): explanation why this method is disallowed
511+
- `replacement` (optional): suggested alternative method
512+
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
513+
if the path doesn't exist, instead of emitting an error
514+
501515
**Default Value:** `[]`
502516

503517
---
@@ -520,6 +534,13 @@ default configuration of Clippy. By default, any configuration will replace the
520534
## `disallowed-types`
521535
The list of disallowed types, written as fully qualified paths.
522536

537+
**Fields:**
538+
- `path` (required): the fully qualified path to the type that should be disallowed
539+
- `reason` (optional): explanation why this type is disallowed
540+
- `replacement` (optional): suggested alternative type
541+
- `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
542+
if the path doesn't exist, instead of emitting an error
543+
523544
**Default Value:** `[]`
524545

525546
---

clippy_config/src/conf.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,24 @@ define_Conf! {
575575
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
576576
cyclomatic_complexity_threshold: u64 = 25,
577577
/// The list of disallowed macros, written as fully qualified paths.
578+
///
579+
/// **Fields:**
580+
/// - `path` (required): the fully qualified path to the macro that should be disallowed
581+
/// - `reason` (optional): explanation why this macro is disallowed
582+
/// - `replacement` (optional): suggested alternative macro
583+
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
584+
/// if the path doesn't exist, instead of emitting an error
578585
#[disallowed_paths_allow_replacements = true]
579586
#[lints(disallowed_macros)]
580587
disallowed_macros: Vec<DisallowedPath> = Vec::new(),
581588
/// The list of disallowed methods, written as fully qualified paths.
589+
///
590+
/// **Fields:**
591+
/// - `path` (required): the fully qualified path to the method that should be disallowed
592+
/// - `reason` (optional): explanation why this method is disallowed
593+
/// - `replacement` (optional): suggested alternative method
594+
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
595+
/// if the path doesn't exist, instead of emitting an error
582596
#[disallowed_paths_allow_replacements = true]
583597
#[lints(disallowed_methods)]
584598
disallowed_methods: Vec<DisallowedPath> = Vec::new(),
@@ -588,6 +602,13 @@ define_Conf! {
588602
#[lints(disallowed_names)]
589603
disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect(),
590604
/// The list of disallowed types, written as fully qualified paths.
605+
///
606+
/// **Fields:**
607+
/// - `path` (required): the fully qualified path to the type that should be disallowed
608+
/// - `reason` (optional): explanation why this type is disallowed
609+
/// - `replacement` (optional): suggested alternative type
610+
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
611+
/// if the path doesn't exist, instead of emitting an error
591612
#[disallowed_paths_allow_replacements = true]
592613
#[lints(disallowed_types)]
593614
disallowed_types: Vec<DisallowedPath> = Vec::new(),

clippy_lints/src/disallowed_macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ declare_clippy_lint! {
3939
/// # When using an inline table, can add a `reason` for why the macro
4040
/// # is disallowed.
4141
/// { path = "serde::Serialize", reason = "no serializing" },
42+
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
43+
/// # it will be silently ignored
44+
/// { path = "std::invalid_macro", reason = "use alternative instead", allow-invalid = true }
4245
/// ]
4346
/// ```
4447
/// ```no_run

clippy_lints/src/disallowed_methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ declare_clippy_lint! {
3434
/// { path = "std::vec::Vec::leak", reason = "no leaking memory" },
3535
/// # Can also add a `replacement` that will be offered as a suggestion.
3636
/// { path = "std::sync::Mutex::new", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex::new" },
37+
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
38+
/// # it will be silently ignored
39+
/// { path = "std::fs::InvalidPath", reason = "use alternative instead", allow-invalid = true },
3740
/// ]
3841
/// ```
3942
///

clippy_lints/src/disallowed_types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ declare_clippy_lint! {
3535
/// { path = "std::net::Ipv4Addr", reason = "no IPv4 allowed" },
3636
/// # Can also add a `replacement` that will be offered as a suggestion.
3737
/// { path = "std::sync::Mutex", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex" },
38+
/// # This would normally error if the path is incorrect, but with `allow-invalid` = `true`,
39+
/// # it will be silently ignored
40+
/// { path = "std::invalid::Type", reason = "use alternative instead", allow-invalid = true }
3841
/// ]
3942
/// ```
4043
///

0 commit comments

Comments
 (0)