cargo_is_tested/lints/
emptiness.rs1use crate::impl_warn;
12
13use super::{super::span, Pass};
14use miette::Result;
15use miette::{Diagnostic, NamedSource, SourceSpan};
16use syn::{spanned::Spanned, Item};
17use thiserror::Error;
18
19#[rustfmt::skip]
20#[derive(Debug, Error, Diagnostic)]
21#[error("Empty items aren't recommended")]
22#[diagnostic(
23 code(EMPTY_ITEM),
24 severity(Warning)
25)]
26pub struct Emptiness {
27 #[source_code]
28 src: NamedSource,
29 #[label("right here")]
30 span: SourceSpan,
31}
32
33impl Pass for Emptiness {
34 fn check_items(source: &str, filename: &str, items: &Vec<Item>) -> Result<()> {
35 for item in items {
36 if let Item::Fn(func) = item {
37 if func.block.stmts.is_empty() {
38 Err(Emptiness {
39 src: NamedSource::new(filename, source.to_owned()),
40 span: span!(func.sig, source),
41 })?;
42 }
43 }
44 }
45 Ok(())
46 }
47}
48
49impl_warn! { Emptiness }