-
Notifications
You must be signed in to change notification settings - Fork 13
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
Create lint groups #98
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8deab34
feat: create lint groups
BD103 790b7d2
feat: add documentation and move lints to different groups
BD103 cd46cc6
feat!: define group within lint definitions
BD103 372c4a7
feat: allow trailing comma in macro
BD103 ae4b801
fix: review feedback
BD103 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::LintGroup; | ||
use rustc_lint::Level; | ||
|
||
/// 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: LintGroup = LintGroup { | ||
name: "bevy::correctness", | ||
level: Level::Deny, | ||
}; | ||
|
||
/// 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: LintGroup = LintGroup { | ||
name: "bevy::suspicious", | ||
level: Level::Warn, | ||
}; | ||
|
||
/// A group that offers suggestions on how to simplify your code. | ||
pub static COMPLEXITY: LintGroup = LintGroup { | ||
name: "bevy::complexity", | ||
level: Level::Warn, | ||
}; | ||
|
||
/// A group that suggests how to increase the performance of your code. | ||
pub static PERFORMANCE: LintGroup = LintGroup { | ||
name: "bevy::performance", | ||
level: Level::Warn, | ||
}; | ||
|
||
/// 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: LintGroup = LintGroup { | ||
name: "bevy::style", | ||
level: Level::Warn, | ||
}; | ||
|
||
/// 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: LintGroup = LintGroup { | ||
name: "bevy::pedantic", | ||
level: Level::Allow, | ||
}; | ||
|
||
/// 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: LintGroup = LintGroup { | ||
name: "bevy::restriction", | ||
level: Level::Allow, | ||
}; | ||
|
||
/// A group of unstable lints that may be removed at any time for any reason. | ||
pub static NURSERY: LintGroup = LintGroup { | ||
name: "bevy::nursery", | ||
level: Level::Allow, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use rustc_lint::{Level, Lint}; | ||
|
||
/// A Bevy lint definition and its associated group. | ||
/// | ||
/// The level of the lint must be the same as the level of the group. | ||
pub struct BevyLint { | ||
pub lint: &'static Lint, | ||
pub group: &'static LintGroup, | ||
} | ||
|
||
/// Represents a lint group. | ||
pub struct LintGroup { | ||
/// The name of the lint group. | ||
/// | ||
/// This will be used when trying to enable / disable the group, such as through | ||
/// `#![allow(group)]`. By convention, this should start with `bevy::`. | ||
pub name: &'static str, | ||
|
||
// The default level all lints within this group should be. | ||
pub level: Level, | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! declare_bevy_lint { | ||
{ | ||
$(#[$attr:meta])* | ||
$vis:vis $name:ident, | ||
$group:ident, | ||
$desc:expr$(,)? | ||
} => { | ||
$(#[$attr])* | ||
$vis static $name: &$crate::lint::BevyLint = &$crate::lint::BevyLint { | ||
lint: &::rustc_lint::Lint { | ||
name: concat!("bevy::", stringify!($name)), | ||
default_level: $crate::groups::$group.level, | ||
desc: $desc, | ||
edition_lint_opts: None, | ||
report_in_external_macro: false, | ||
future_incompatible: None, | ||
is_externally_loaded: true, | ||
feature_gate: None, | ||
crate_level_only: false, | ||
}, | ||
group: &$crate::groups::$group, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the obvious question is, "if they shouldn't all be enabled at once, why are they in a group"? Or are we saying, this group is for categorising but not for actual use 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want every lint to be within a group so that it's clear what its general purpose is. These lint groups are just as important for documentation as they are for bulk-toggling.
So yes, this group is a category that's never intended to be named directly. (Clippy has the same things!)