use super::types::*;
use crate::Result;
impl CodingStandards {
pub fn load() -> Result<Self> {
Ok(Self::default())
}
pub fn save(&self) -> Result<()> {
Ok(())
}
pub fn get_clippy_rules(&self) -> Vec<String> {
let mut rules = vec!["-D warnings".to_string()];
if self.banned_patterns.ban_unwrap {
rules.push("-D clippy::unwrap_used".to_string());
}
if self.banned_patterns.ban_expect {
rules.push("-D clippy::expect_used".to_string());
}
if self.banned_patterns.ban_panic {
rules.push("-D clippy::panic".to_string());
}
if self.banned_patterns.ban_todo {
rules.push("-D clippy::todo".to_string());
}
if self.banned_patterns.ban_unimplemented {
rules.push("-D clippy::unimplemented".to_string());
}
if self.documentation.require_public_docs {
rules.push("-D missing_docs".to_string());
}
if self.security.ban_unsafe {
rules.push("-D unsafe_code".to_string());
}
rules.extend([
"-W clippy::pedantic".to_string(),
"-W clippy::nursery".to_string(),
"-W clippy::cargo".to_string(),
"-D clippy::dbg_macro".to_string(),
"-D clippy::print_stdout".to_string(),
"-D clippy::print_stderr".to_string(),
]);
rules
}
pub fn generate_clippy_config(&self) -> String {
format!(
r#"# Ferrous Forge - Rust Standards Enforcement
# Generated automatically - do not edit manually
msrv = "{}"
max-fn-params-bools = 2
max-struct-bools = 2
max-trait-bounds = 2
max-include-file-size = {}
min-ident-chars-threshold = 2
literal-representation-threshold = 1000
check-private-items = {}
missing-docs-allow-unused = false
allow-comparison-to-zero = false
allow-mixed-uninlined-format-args = false
allow-one-hash-in-raw-strings = false
allow-useless-vec-in-tests = false
allow-indexing-slicing-in-tests = false
allowed-idents-below-min-chars = ["i", "j", "x", "y", "z"]
allowed-wildcard-imports = []
allow-exact-repetitions = false
allow-private-module-inception = false
too-large-for-stack = 100
upper-case-acronyms-aggressive = true
allowed-scripts = ["Latin"]
disallowed-names = ["foo", "bar", "baz", "qux", "quux", "test", "tmp", "temp"]
unreadable-literal-lint-fractions = true
semicolon-inside-block-ignore-singleline = false
semicolon-outside-block-ignore-multiline = false
arithmetic-side-effects-allowed = []
"#,
self.edition.min_rust_version,
self.file_limits.max_lines * 1000, self.documentation.require_private_docs,
)
}
pub async fn check_compliance(&self, project_path: &std::path::Path) -> Result<Vec<String>> {
let mut violations = Vec::new();
let cargo_toml = project_path.join("Cargo.toml");
if cargo_toml.exists() {
let content = tokio::fs::read_to_string(&cargo_toml).await?;
if !content.contains(&format!(r#"edition = "{}""#, self.edition.required_edition)) {
violations.push(format!(
"Project must use Rust Edition {}",
self.edition.required_edition
));
}
}
Ok(violations)
}
}