Implicitly set --type=cargo when using --category=cargo

This commit is contained in:
Serial 2022-07-26 19:32:34 -04:00
parent c8ee8c30f0
commit f31937043d
2 changed files with 16 additions and 8 deletions

View File

@ -36,8 +36,8 @@ fn main() {
match new_lint::create( match new_lint::create(
matches.get_one::<String>("pass"), matches.get_one::<String>("pass"),
matches.get_one::<String>("name"), matches.get_one::<String>("name"),
matches.get_one::<String>("category"), matches.get_one::<String>("category").map(String::as_str),
matches.get_one::<String>("type"), matches.get_one::<String>("type").map(String::as_str),
matches.contains_id("msrv"), matches.contains_id("msrv"),
) { ) {
Ok(_) => update_lints::update(update_lints::UpdateMode::Change), Ok(_) => update_lints::update(update_lints::UpdateMode::Change),

View File

@ -38,15 +38,20 @@ fn context<C: AsRef<str>>(self, text: C) -> Self {
pub fn create( pub fn create(
pass: Option<&String>, pass: Option<&String>,
lint_name: Option<&String>, lint_name: Option<&String>,
category: Option<&String>, category: Option<&str>,
ty: Option<&String>, mut ty: Option<&str>,
msrv: bool, msrv: bool,
) -> io::Result<()> { ) -> io::Result<()> {
if category == Some("cargo") && ty.is_none() {
// `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo`
ty = Some("cargo");
}
let lint = LintData { let lint = LintData {
pass: pass.map_or("", String::as_str), pass: pass.map_or("", String::as_str),
name: lint_name.expect("`name` argument is validated by clap"), name: lint_name.expect("`name` argument is validated by clap"),
category: category.expect("`category` argument is validated by clap"), category: category.expect("`category` argument is validated by clap"),
ty: ty.map(String::as_str), ty,
project_root: clippy_project_root(), project_root: clippy_project_root(),
}; };
@ -95,7 +100,7 @@ fn create_project_layout<P: Into<PathBuf>>(lint_name: &str, location: P, case: &
create_project_layout(lint.name, &test_dir, "fail", "Content that triggers the lint goes here")?; create_project_layout(lint.name, &test_dir, "fail", "Content that triggers the lint goes here")?;
create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint")?; create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint")?;
println!("Generated test directories: `{}`, `{}`", format!("{}/pass", relative_test_dir), format!("{}/fail", relative_test_dir)); println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`");
} else { } else {
let test_path = format!("tests/ui/{}.rs", lint.name); let test_path = format!("tests/ui/{}.rs", lint.name);
let test_contents = get_test_file_contents(lint.name, None); let test_contents = get_test_file_contents(lint.name, None);
@ -341,7 +346,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
"Lints of type `cargo` must have the `cargo` category" "Lints of type `cargo` must have the `cargo` category"
), ),
_ if lint.category == "cargo" => panic!("Lints of category `cargo` must have the `cargo` type"), _ if lint.category == "cargo" => panic!("Lints of category `cargo` must have the `cargo` type"),
_ => {} _ => {},
} }
let ty_dir = lint.project_root.join(format!("clippy_lints/src/{}", ty)); let ty_dir = lint.project_root.join(format!("clippy_lints/src/{}", ty));
@ -405,7 +410,10 @@ pub(super) fn check(cx: &{context_import}) {{
write_file(lint_file_path.as_path(), lint_file_contents)?; write_file(lint_file_path.as_path(), lint_file_contents)?;
println!("Generated lint file: `clippy_lints/src/{}/{}.rs`", ty, lint.name); println!("Generated lint file: `clippy_lints/src/{}/{}.rs`", ty, lint.name);
println!("Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!", lint.name, ty); println!(
"Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!",
lint.name, ty
);
Ok(()) Ok(())
} }