Skip to content
Merged
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
2 changes: 0 additions & 2 deletions src/diagnostics/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::workspace::{Feature, Features};
#[derive(Clone, Debug)]
pub struct Lint {
pub name: &'static str,
pub desc: &'static str,
pub primary_group: &'static LintGroup,
/// The minimum supported Rust version for applying this lint
///
Expand Down Expand Up @@ -239,7 +238,6 @@ mod tests {
fn test_lint(name: &'static str, group: &'static LintGroup) -> Lint {
Lint {
name,
desc: "test lint",
primary_group: group,
msrv: None,
feature_gate: None,
Expand Down
1 change: 0 additions & 1 deletion src/diagnostics/rules/blanket_hint_mostly_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "blanket_hint_mostly_unused",
desc: "blanket_hint_mostly_unused lint",
primary_group: &SUSPICIOUS,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down
3 changes: 1 addition & 2 deletions src/diagnostics/rules/im_a_teapot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::workspace::Workspace;
/// This lint is only to be used for testing purposes
pub static LINT: &Lint = &Lint {
name: "im_a_teapot",
desc: "`im_a_teapot` is specified",
primary_group: &TEST_DUMMY_UNSTABLE,
msrv: None,
feature_gate: Some(Feature::test_dummy_unstable()),
Expand Down Expand Up @@ -53,7 +52,7 @@ pub(crate) fn lint_package(
let manifest_path = workspace_rel_path(ws, path);
let emitted_source = LINT.emitted_source(lint_level, source);

let mut desc = Group::with_title(level.primary_title(LINT.desc));
let mut desc = Group::with_title(level.primary_title("`im_a_teapot` is specified"));

if let Some(document) = manifest.document()
&& let Some(contents) = manifest.contents()
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/rules/manual_readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::workspace::parser::default_readme_from_package_root;

pub static LINT: &Lint = &Lint {
name: "manual_readme",
desc: "explicit `package.readme` can be inferred",
primary_group: &STYLE,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -121,7 +120,8 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary =
Group::with_title(level.primary_title("explicit `package.readme` can be inferred"));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "readme"])
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/rules/missing_lints_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "missing_lints_inheritance",
desc: "missing `[lints]` to inherit `[workspace.lints]`",
primary_group: &SUSPICIOUS,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -97,7 +96,8 @@ pub(crate) fn lint_package(
let emitted_source = LINT.emitted_source(lint_level, source);
let manifest_path = workspace_rel_path(ws, manifest_path);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary =
Group::with_title(level.primary_title("missing `[lints]` to inherit `[workspace.lints]`"));
primary = primary.element(Origin::path(&manifest_path));
primary = primary.element(Level::NOTE.message(emitted_source));
let mut report = vec![primary];
Expand Down
31 changes: 17 additions & 14 deletions src/diagnostics/rules/non_kebab_case_bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "non_kebab_case_bins",
desc: "binaries should have a kebab-case name",
primary_group: &STYLE,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -116,12 +115,14 @@ fn lint_package_inner(
let primary_span_end = primary_span_start + original_name.len();
primary_source.push_str(original_name);
primary_source.push_str(std::env::consts::EXE_SUFFIX);
let mut primary_group =
level
.primary_title(LINT.desc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this makes the description of some lints unused. Should we remove the field and instead inline them all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muscraft thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like unknown_lints also kinda rewrote it:

let title = format!("{}: `{lint_name}`", LINT.desc);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember my exact reasons for adding the field, but I think I did it to match rustc's Lint struct. Regardless of the original reason, if we are not using the field in all cases, I think it would make sense to inline them. We can always add the field back if we find it useful.

.element(Snippet::source(&primary_source).annotation(
AnnotationKind::Primary.span(primary_span_start..primary_span_end),
));
let mut primary_group = level
.primary_title(format!(
"binary `{original_name}` should have a kebab-case name"
))
.element(
Snippet::source(&primary_source)
.annotation(AnnotationKind::Primary.span(primary_span_start..primary_span_end)),
);
if i == 0 {
primary_group = primary_group.element(Level::NOTE.message(emitted_source));
}
Expand All @@ -134,10 +135,9 @@ fn lint_package_inner(
.enumerate()
.find(|(_i, t)| t.name.as_deref() == Some(original_name))
{
let mut help = Group::with_title(
Level::HELP
.secondary_title("to change the binary name to kebab case, convert `bin.name`"),
);
let mut help = Group::with_title(Level::HELP.secondary_title(format!(
"to change the binary name to `{kebab_case}`, convert `bin.name`"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(
Expand Down Expand Up @@ -169,11 +169,12 @@ fn lint_package_inner(
// Showing package in case this is done before first publish to fix the problem at the
// root
let help_package_name =
"to change the binary name to kebab case, convert `package.name`";
format!("to change the binary name to `{kebab_case}`, convert `package.name`");
// Including `[[bin]]` in case it is already published.
// Preferring it over moving the file to avoid having to get into moving the
// files it `mod`s
let help_bin_table = "to change the binary name to kebab case, specify `bin.name`";
let help_bin_table =
format!("to change the binary name to `{kebab_case}`, specify `bin.name`");
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "name"])
Expand Down Expand Up @@ -230,7 +231,9 @@ path = "src/main.rs""#
})
.unwrap_or(0);
let help = Level::HELP
.secondary_title("to change the binary name to kebab case, convert the file stem")
.secondary_title(format!(
"to change the binary name to `{kebab_case}`, convert the file stem"
))
.element(Snippet::source(display_path).patch(Patch::new(start..end, kebab_case)));
report.push(help);
}
Expand Down
11 changes: 6 additions & 5 deletions src/diagnostics/rules/non_kebab_case_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "non_kebab_case_features",
desc: "features should have a kebab-case name",
primary_group: &RESTRICTION,
msrv: None,
feature_gate: None,
Expand Down Expand Up @@ -98,7 +97,9 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary = Group::with_title(level.primary_title(format!(
"feature `{original_name}` should have a kebab-case name"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["features", original_name])
Expand Down Expand Up @@ -133,9 +134,9 @@ fn lint_package_inner(
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["features", original_name])
{
let mut help = Group::with_title(Level::HELP.secondary_title(
"to change the feature name to kebab case, convert the `features` key",
));
let mut help = Group::with_title(Level::HELP.secondary_title(format!(
"to change the feature name to `{kebab_case}`, convert the `features` key"
)));
help = help.element(
Snippet::source(contents)
.path(manifest_path)
Expand Down
16 changes: 9 additions & 7 deletions src/diagnostics/rules/non_kebab_case_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "non_kebab_case_packages",
desc: "packages should have a kebab-case name",
primary_group: &RESTRICTION,
msrv: None,
feature_gate: None,
Expand Down Expand Up @@ -98,7 +97,9 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary = Group::with_title(level.primary_title(format!(
"package `{original_name}` should have a kebab-case name"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "name"])
Expand All @@ -117,10 +118,9 @@ fn lint_package_inner(
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "name"])
{
let mut help =
Group::with_title(Level::HELP.secondary_title(
"to change the package name to kebab case, convert `package.name`",
));
let mut help = Group::with_title(Level::HELP.secondary_title(format!(
"to change the package name to `{kebab_case}`, convert `package.name`"
)));
help = help.element(
Snippet::source(contents)
.path(manifest_path)
Expand All @@ -140,7 +140,9 @@ fn lint_package_inner(
})
.unwrap_or(0);
let help = Level::HELP
.secondary_title("to change the package name to kebab case, convert the file stem")
.secondary_title(format!(
"to change the package name to `{kebab_case}`, convert the file stem"
))
.element(Snippet::source(display_path).patch(Patch::new(start..end, kebab_case)));
report.push(help);
}
Expand Down
11 changes: 6 additions & 5 deletions src/diagnostics/rules/non_snake_case_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "non_snake_case_features",
desc: "features should have a snake-case name",
primary_group: &RESTRICTION,
msrv: None,
feature_gate: None,
Expand Down Expand Up @@ -98,7 +97,9 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary = Group::with_title(level.primary_title(format!(
"feature `{original_name}` should have a snake-case name"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["features", original_name])
Expand Down Expand Up @@ -133,9 +134,9 @@ fn lint_package_inner(
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["features", original_name])
{
let mut help = Group::with_title(Level::HELP.secondary_title(
"to change the feature name to snake case, convert the `features` key",
));
let mut help = Group::with_title(Level::HELP.secondary_title(format!(
"to change the feature name to `{snake_case}`, convert the `features` key"
)));
help = help.element(
Snippet::source(contents)
.path(manifest_path)
Expand Down
16 changes: 9 additions & 7 deletions src/diagnostics/rules/non_snake_case_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "non_snake_case_packages",
desc: "packages should have a snake-case name",
primary_group: &RESTRICTION,
msrv: None,
feature_gate: None,
Expand Down Expand Up @@ -98,7 +97,9 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary = Group::with_title(level.primary_title(format!(
"package `{original_name}` should have a snake-case name"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "name"])
Expand All @@ -117,10 +118,9 @@ fn lint_package_inner(
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "name"])
{
let mut help =
Group::with_title(Level::HELP.secondary_title(
"to change the package name to snake case, convert `package.name`",
));
let mut help = Group::with_title(Level::HELP.secondary_title(format!(
"to change the package name to `{snake_case}`, convert `package.name`"
)));
help = help.element(
Snippet::source(contents)
.path(manifest_path)
Expand All @@ -140,7 +140,9 @@ fn lint_package_inner(
})
.unwrap_or(0);
let help = Level::HELP
.secondary_title("to change the package name to snake case, convert the file stem")
.secondary_title(format!(
"to change the package name to `{snake_case}`, convert the file stem"
))
.element(Snippet::source(display_path).patch(Patch::new(start..end, snake_case)));
report.push(help);
}
Expand Down
5 changes: 3 additions & 2 deletions src/diagnostics/rules/redundant_homepage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "redundant_homepage",
desc: "`package.homepage` is redundant with another manifest field",
primary_group: &STYLE,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -114,7 +113,9 @@ fn lint_package_inner(
let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, source);

let mut primary = Group::with_title(level.primary_title(LINT.desc));
let mut primary = Group::with_title(level.primary_title(format!(
"`package.homepage` is redundant with `package.{other_field}`"
)));
if let Some(document) = document
&& let Some(contents) = contents
&& let Some(span) = get_key_value_span(document, &["package", "homepage"])
Expand Down
6 changes: 4 additions & 2 deletions src/diagnostics/rules/text_direction_codepoint_in_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "text_direction_codepoint_in_comment",
desc: "unicode codepoint changing visible direction of text present in comment",
primary_group: &CORRECTNESS,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -107,7 +106,10 @@ pub(crate) fn lint_manifest(
}

let level = lint_level.to_diagnostic_level();
let mut primary = Group::with_title(level.primary_title(LINT.desc)).element(snippet);
let mut primary = Group::with_title(level.primary_title(
"unicode codepoint changing visible direction of text present in comment",
))
.element(snippet);
if emitted_source.is_none() {
emitted_source = Some(LINT.emitted_source(lint_level, source));
primary = primary.element(Level::NOTE.message(emitted_source.as_ref().unwrap()));
Expand Down
6 changes: 4 additions & 2 deletions src/diagnostics/rules/text_direction_codepoint_in_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "text_direction_codepoint_in_literal",
desc: "unicode codepoint changing visible direction of text present in literal",
primary_group: &CORRECTNESS,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -148,7 +147,10 @@ pub(crate) fn lint_manifest(
}

let level = lint_level.to_diagnostic_level();
let mut primary = Group::with_title(level.primary_title(LINT.desc)).element(snippet);
let mut primary = Group::with_title(level.primary_title(
"unicode codepoint changing visible direction of text present in literal",
))
.element(snippet);
if emitted_source.is_none() {
emitted_source = Some(LINT.emitted_source(lint_level, source));
primary = primary.element(Level::NOTE.message(emitted_source.as_ref().unwrap()));
Expand Down
3 changes: 1 addition & 2 deletions src/diagnostics/rules/unknown_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::workspace::Workspace;

pub static LINT: &Lint = &Lint {
name: "unknown_lints",
desc: "unknown lint",
primary_group: &SUSPICIOUS,
msrv: Some(super::CARGO_LINTS_MSRV),
feature_gate: None,
Expand Down Expand Up @@ -136,7 +135,7 @@ fn lint_manifest_inner(
let level = lint_level.to_diagnostic_level();
let mut emitted_source = None;
for lint_name in unknown_lints {
let title = format!("{}: `{lint_name}`", LINT.desc);
let title = format!("unknown lint: `{lint_name}`");
let underscore_lint_name = lint_name.replace("-", "_");
let matching = if let Some(lint) = LINTS.iter().find(|l| l.name == underscore_lint_name) {
Some((lint.name, "lint"))
Expand Down
Loading