ferrous_forge/standards/
implementation.rs1use super::types::*;
4use crate::Result;
5
6impl CodingStandards {
7 pub fn load() -> Result<Self> {
13 Ok(Self::default())
16 }
17
18 pub fn save(&self) -> Result<()> {
24 Ok(())
26 }
27
28 pub fn get_clippy_rules(&self) -> Vec<String> {
30 let mut rules = vec!["-D warnings".to_string()];
31
32 if self.banned_patterns.ban_unwrap {
33 rules.push("-D clippy::unwrap_used".to_string());
34 }
35
36 if self.banned_patterns.ban_expect {
37 rules.push("-D clippy::expect_used".to_string());
38 }
39
40 if self.banned_patterns.ban_panic {
41 rules.push("-D clippy::panic".to_string());
42 }
43
44 if self.banned_patterns.ban_todo {
45 rules.push("-D clippy::todo".to_string());
46 }
47
48 if self.banned_patterns.ban_unimplemented {
49 rules.push("-D clippy::unimplemented".to_string());
50 }
51
52 if self.documentation.require_public_docs {
53 rules.push("-D missing_docs".to_string());
54 }
55
56 if self.security.ban_unsafe {
57 rules.push("-F unsafe_code".to_string());
58 }
59
60 rules.extend([
62 "-W clippy::pedantic".to_string(),
63 "-W clippy::nursery".to_string(),
64 "-W clippy::cargo".to_string(),
65 "-D clippy::dbg_macro".to_string(),
66 "-D clippy::print_stdout".to_string(),
67 "-D clippy::print_stderr".to_string(),
68 ]);
69
70 rules
71 }
72
73 pub fn generate_clippy_config(&self) -> String {
75 format!(
76 r#"# Ferrous Forge - Rust Standards Enforcement
77# Generated automatically - do not edit manually
78
79msrv = "{}"
80max-fn-params-bools = 2
81max-struct-bools = 2
82max-trait-bounds = 2
83max-include-file-size = {}
84min-ident-chars-threshold = 2
85literal-representation-threshold = 1000
86check-private-items = {}
87missing-docs-allow-unused = false
88allow-comparison-to-zero = false
89allow-mixed-uninlined-format-args = false
90allow-one-hash-in-raw-strings = false
91allow-useless-vec-in-tests = false
92allow-indexing-slicing-in-tests = false
93allowed-idents-below-min-chars = ["i", "j", "x", "y", "z"]
94allowed-wildcard-imports = []
95allow-exact-repetitions = false
96allow-private-module-inception = false
97too-large-for-stack = 100
98upper-case-acronyms-aggressive = true
99allowed-scripts = ["Latin"]
100disallowed-names = ["foo", "bar", "baz", "qux", "quux", "test", "tmp", "temp"]
101unreadable-literal-lint-fractions = true
102semicolon-inside-block-ignore-singleline = false
103semicolon-outside-block-ignore-multiline = false
104arithmetic-side-effects-allowed = []
105"#,
106 self.edition.min_rust_version,
107 self.file_limits.max_lines * 1000, self.documentation.require_private_docs,
109 )
110 }
111
112 pub async fn check_compliance(&self, project_path: &std::path::Path) -> Result<Vec<String>> {
118 let mut violations = Vec::new();
119
120 let cargo_toml = project_path.join("Cargo.toml");
122 if cargo_toml.exists() {
123 let content = tokio::fs::read_to_string(&cargo_toml).await?;
124 if !content.contains(&format!(r#"edition = "{}""#, self.edition.required_edition)) {
125 violations.push(format!(
126 "Project must use Rust Edition {}",
127 self.edition.required_edition
128 ));
129 }
130 }
131
132 Ok(violations)
135 }
136}