//! TOML lint source. use std::fs; use std::path::Path; use anyhow::Context as _; use lint_policy::cargo; use crate::source::LintGroups; /// Query a TOML file for the list of included lints, panicking on any error. /// /// # Panics /// If an error occurs while reading the file or parsing the content. pub(crate) fn read_lints(filepath: &Path) -> cargo::Lints { #[expect( clippy::expect_used, reason = "errors here are not deisgned to be recoverable" )] private_read_lints(filepath) .with_context(|| format!("reading lints from {}", filepath.display())) .expect("toml source error") } /// Query a TOML file for the list of included lints. /// /// # Errors /// IO can fail while reading the file, and TOML parsing can fail. fn private_read_lints(filepath: &Path) -> anyhow::Result { let contents = fs::read_to_string(filepath)?; let manifest: cargo::Manifest = toml::from_str(&contents)?; Ok(manifest.workspace.lints) } /// Query a TOML file for the list of included groups. /// /// There is currently no differentiator between lints and groups so this function /// just returns [Default]. pub(crate) fn read_groups(_: &Path) -> LintGroups { LintGroups::default() }