Source src/main.rs
1mod cargo;2mod cli;3mod diagnostic;4mod lint;5mod metadata;6mod output;7mod render;8mod source;9use diagnostic::model::*; warning: clippy::wildcard_imports10fn run(opts: cli::RunOptions) -> Result<i32, String> { warning: clippy::needless_pass_by_value11 let cwd = std::env::current_dir().map_err(|e| e.to_string())?;12 let ctx = cli::cargo_context(13 &opts,14 &cwd,15 std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into()),16 )?;17 let project = cargo::load_project(&ctx)?;18 let output = opts19 .output20 .as_ref()21 .map_or_else(|| project.target_dir.join("clippy-html"), |p| cwd.join(p));22 let target = output::prepare_target(&output, &project)?;23 let metadata_target = opts24 .metadata25 .as_ref()26 .map(|path| metadata::MetadataTarget::prepare(&cwd.join(path), &target))27 .transpose()?;28 let collected = cargo::collect(&ctx, &opts)?;29 let raw_count = collected.messages.len();30 let mut findings = diagnostic::dedup::merge_findings(31 collected32 .messages33 .iter()34 .map(|m| diagnostic::normalize::normalize(m, &project.workspace_root))35 .collect(),36 );37 let category_metadata = lint::metadata::resolve(&mut findings, opts.offline);38 if let Some(metadata) = &category_metadata39 && let Some(reason) = &metadata.reason40 && !opts.offline41 {42 eprintln!(43 "Warning: category metadata uses bundled {} data: {reason}",44 metadata.selector45 );46 }47 let report = Report {48 category_metadata,49 project,50 execution: collected.execution,51 raw_count,52 findings,53 };54 let sources = source::load_sources(&report.project, &report.findings);55 let pages = render::paths::build_page_map(&report, &sources);56 let navigation = metadata_target57 .as_ref()58 .map(|_| metadata::build(&report, &sources, &pages));59 let prepared_metadata = metadata_target60 .zip(navigation.as_ref())61 .map(|(target, navigation)| target.stage(navigation.json()?))62 .transpose()?;63 let published = output::publish_report(&target, |dir| {64 render::render_report(&report, &sources, &pages, dir)?;65 if let Some(metadata) = &prepared_metadata {66 metadata.write_report(dir)?;67 }68 if let Some(navigation) = &navigation {69 navigation.validate(dir)?;70 }71 Ok(())72 })73 .map_err(|e| {74 format!(75 "{e}\nClippy exit: {:?}; collection complete: {}",76 report.execution.code, report.execution.complete77 )78 })?;79 for warning in published.warnings {80 eprintln!("Warning: {warning}");81 }82 println!("Report: {}", published.index.display());83 if let Some(metadata) = prepared_metadata {84 metadata.publish_external().map_err(|e| format!(85 "{e}\nHTML report published at {}; requested metadata was not published.\nClippy exit: {:?}; collection complete: {}",86 published.index.display(), report.execution.code, report.execution.complete87 ))?;88 println!(89 "Metadata: {}",90 cwd.join(opts.metadata.as_ref().unwrap()).display()91 );92 }93 if opts.open {94 let url = url::Url::from_file_path(&published.index)95 .map_err(|_| "Cannot form report file URL")?; warning: clippy::ignored_unit_patterns96 if let Err(e) = webbrowser::open(url.as_str()) {97 eprintln!("Warning: report generated, browser could not open it: {e}");98 }99 }100 Ok(report.execution.exit_code())101}102fn main() {103 let opts = match cli::parse_args(std::env::args_os().collect()) {104 Ok(o) => o,105 Err(e) => e.exit(),106 };107 let code = match run(opts) {108 Ok(code) => code,109 Err(e) => {110 eprintln!("cargo-clippy-html: {e}");111 1112 }113 };114 std::process::exit(code);115}116Findings in this file§
warning clippy::wildcard_imports §
warning clippy::wildcard_imports §
Targets (1)
cargo-clippy-html (bin)
Primary: src/main.rs:9:5
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#wildcard_imports
help: try
Suggestion: try
--- "a/src/main.rs"
+++ "b/src/main.rs"
@@ -6,7 +6,7 @@
mod output;
mod render;
mod source;
-use diagnostic::model::*;
+use diagnostic::model::Report;
fn run(opts: cli::RunOptions) -> Result<i32, String> {
let cwd = std::env::current_dir().map_err(|e| e.to_string())?;
let ctx = cli::cargo_context(
Rendered diagnostic (text)
warning: usage of wildcard import --> src/main.rs:9:5 | 9 | use diagnostic::model::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `diagnostic::model::Report` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#wildcard_imports
warning clippy::needless_pass_by_value §
warning clippy::needless_pass_by_value §
Targets (1)
cargo-clippy-html (bin)
Primary: src/main.rs:10:14
Primary: src/main.rs:10:14
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#needless_pass_by_value
help: consider taking a reference instead
Suggestion: consider taking a reference instead
--- "a/src/main.rs"
+++ "b/src/main.rs"
@@ -7,7 +7,7 @@
mod render;
mod source;
use diagnostic::model::*;
-fn run(opts: cli::RunOptions) -> Result<i32, String> {
+fn run(opts: &cli::RunOptions) -> Result<i32, String> {
let cwd = std::env::current_dir().map_err(|e| e.to_string())?;
let ctx = cli::cargo_context(
&opts,
Rendered diagnostic (text)
warning: this argument is passed by value, but not consumed in the function body
--> src/main.rs:10:14
|
10 | fn run(opts: cli::RunOptions) -> Result<i32, String> {
| ^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#needless_pass_by_value
help: consider taking a reference instead
|
10 | fn run(opts: &cli::RunOptions) -> Result<i32, String> {
| +
warning clippy::ignored_unit_patterns §
warning clippy::ignored_unit_patterns §
Targets (1)
cargo-clippy-html (bin)
Primary: src/main.rs:95:23
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#ignored_unit_patterns
help: use `()` instead of `_`
Suggestion: use `()` instead of `_`
--- "a/src/main.rs"
+++ "b/src/main.rs"
@@ -92,7 +92,7 @@
}
if opts.open {
let url = url::Url::from_file_path(&published.index)
- .map_err(|_| "Cannot form report file URL")?;
+ .map_err(|()| "Cannot form report file URL")?;
if let Err(e) = webbrowser::open(url.as_str()) {
eprintln!("Warning: report generated, browser could not open it: {e}");
}
Rendered diagnostic (text)
warning: matching over `()` is more explicit --> src/main.rs:95:23 | 95 | .map_err(|_| "Cannot form report file URL")?; | ^ help: use `()` instead of `_`: `()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#ignored_unit_patterns