bevy_lint/groups.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
//! Lint groups that can be toggled together.
//!
//! Each [lint](crate::lints) is organized within a specific category, such as [`PERFORMANCE`] or
//! [`STYLE`]. The following groups are enabled by default:
//!
//! - [`CORRECTNESS`]
//! - [`SUSPICIOUS`]
//! - [`COMPLEXITY`]
//! - [`PERFORMANCE`]
//! - [`STYLE`]
//!
//! The following groups are disabled by default:
//!
//! - [`PEDANTIC`]
//! - [`RESTRICTION`]
//! - [`NURSERY`]
use crate::{
lint::{BevyLint, LintGroup},
lints::LINTS,
};
use rustc_lint::{Level, LintStore};
/// A macro for declaring [`LintGroup`]s that auto-generates a table with the name and default
/// level in the documentation.
macro_rules! declare_group {
{
$(#[$attr:meta])*
$vis:vis static $static_name:ident = {
name: $group_name:literal,
level: $level:expr$(,)?
};
} => {
$(#[$attr])*
///
/// <table>
/// <tr>
/// <td>Name</td>
#[doc = concat!(" <td><code>", stringify!($group_name), "</code></td>")]
/// </tr>
/// <tr>
/// <td>Default Level</td>
#[doc = concat!(" <td><code>", stringify!($level), "</code></td>")]
/// </tr>
/// </table>
$vis static $static_name: &LintGroup = &LintGroup {
name: $group_name,
level: $level,
};
};
}
declare_group! {
/// A group of deny-by-default lints that check for outright wrong or useless code.
///
/// These lints are carefully picked to be free of false positives. You should avoid
/// `#[allow(...)]`-ing these lints without a _very_ good reason.
pub static CORRECTNESS = {
name: "bevy::correctness",
level: Level::Deny,
};
}
declare_group! {
/// A group similar to [`CORRECTNESS`] that checks for suspicious or usually wrong code.
///
/// The linted code may have been written intentionally, but should probably still be fixed.
pub static SUSPICIOUS = {
name: "bevy::suspicious",
level: Level::Warn,
};
}
declare_group! {
/// A group that offers suggestions on how to simplify your code.
pub static COMPLEXITY = {
name: "bevy::complexity",
level: Level::Warn,
};
}
declare_group! {
/// A group that suggests how to increase the performance of your code.
pub static PERFORMANCE = {
name: "bevy::performance",
level: Level::Warn,
};
}
declare_group! {
/// A group of lints that encourage idiomatic code.
///
/// These lints are opinionated and may be freely disabled if you disagree with their suggestions.
pub static STYLE = {
name: "bevy::style",
level: Level::Warn,
};
}
declare_group! {
/// A group of lints that make the linter incredibly nit-picky.
///
/// If you enable this group, expect to liberally apply `#[allow(...)]` attributes throughout your
/// code.
pub static PEDANTIC = {
name: "bevy::pedantic",
level: Level::Allow,
};
}
declare_group! {
/// A group of opt-in lints that restrict you from writing certain code.
///
/// These are designed for scenarios where you want to increase the consistency of your code-base
/// and reject certain patterns. They should not all be enabled at once, but instead specific lints
/// should be individually enabled.
pub static RESTRICTION = {
name: "bevy::restriction",
level: Level::Allow,
};
}
declare_group! {
/// A group of unstable lints that may be removed at any time for any reason.
pub static NURSERY = {
name: "bevy::nursery",
level: Level::Allow,
};
}
/// A list of all [`LintGroup`]s.
///
/// If a group is not in this list, it will not be registered in [`register_groups()`].
static GROUPS: &[&LintGroup] = &[
CORRECTNESS,
SUSPICIOUS,
COMPLEXITY,
PERFORMANCE,
STYLE,
PEDANTIC,
RESTRICTION,
NURSERY,
];
/// Registers all [`LintGroup`]s in [`GROUPS`] with the [`LintStore`].
pub(crate) fn register_groups(store: &mut LintStore) {
for &group in GROUPS {
let lints = LINTS
.iter()
.copied()
// Only select lints of this specified group.
.filter(|l| l.group == group)
// Convert the lints into their `LintId`s.
.map(BevyLint::id)
// Collect into a `Vec`.
.collect();
store.register_group(true, group.name, None, lints);
}
}