|
1 | 1 | use std::fs; |
| 2 | +use std::path::Path; |
2 | 3 | use xshell::Shell; |
3 | 4 |
|
4 | 5 | use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH}; |
@@ -46,6 +47,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er |
46 | 47 | lint_workspace(sh)?; |
47 | 48 | lint_crates(sh, packages)?; |
48 | 49 | check_duplicate_deps(sh)?; |
| 50 | + check_clippy_toml_msrv(sh, packages)?; |
49 | 51 |
|
50 | 52 | quiet_println("Lint task completed successfully"); |
51 | 53 | Ok(()) |
@@ -139,3 +141,62 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> { |
139 | 141 | quiet_println("No duplicate dependencies found"); |
140 | 142 | Ok(()) |
141 | 143 | } |
| 144 | + |
| 145 | +/// Check for deprecated clippy.toml MSRV settings. |
| 146 | +/// |
| 147 | +/// The bitcoin ecosystem has moved to Rust 1.74+ and should use Cargo.toml |
| 148 | +/// package.rust-version instead of clippy.toml msrv settings. |
| 149 | +fn check_clippy_toml_msrv( |
| 150 | + sh: &Shell, |
| 151 | + packages: &[String], |
| 152 | +) -> Result<(), Box<dyn std::error::Error>> { |
| 153 | + const CLIPPY_CONFIG_FILES: &[&str] = &["clippy.toml", ".clippy.toml"]; |
| 154 | + |
| 155 | + quiet_println("Checking for deprecated clippy.toml MSRV settings..."); |
| 156 | + |
| 157 | + let mut clippy_files = Vec::new(); |
| 158 | + |
| 159 | + // Check workspace root. |
| 160 | + let workspace_root = sh.current_dir(); |
| 161 | + for filename in CLIPPY_CONFIG_FILES { |
| 162 | + let path = workspace_root.join(filename); |
| 163 | + if path.exists() { |
| 164 | + clippy_files.push(path); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + // Check each package. |
| 169 | + let crate_dirs = get_crate_dirs(sh, packages)?; |
| 170 | + for crate_dir in crate_dirs { |
| 171 | + for filename in CLIPPY_CONFIG_FILES { |
| 172 | + let path = Path::new(&crate_dir).join(filename); |
| 173 | + if path.exists() { |
| 174 | + clippy_files.push(path); |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + // Check each clippy file for the msrv setting. |
| 180 | + let mut problematic_files = Vec::new(); |
| 181 | + for path in clippy_files { |
| 182 | + let contents = fs::read_to_string(&path)?; |
| 183 | + let config: toml::Value = toml::from_str(&contents)?; |
| 184 | + |
| 185 | + if config.get("msrv").is_some() { |
| 186 | + problematic_files.push(path.display().to_string()); |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + if !problematic_files.is_empty() { |
| 191 | + eprintln!( |
| 192 | + "\nError: Found MSRV in clippy.toml, use Cargo.toml package.rust-version instead:" |
| 193 | + ); |
| 194 | + for file in &problematic_files { |
| 195 | + eprintln!(" {}", file); |
| 196 | + } |
| 197 | + return Err("MSRV should be specified in Cargo.toml, not clippy.toml".into()); |
| 198 | + } |
| 199 | + |
| 200 | + quiet_println("No deprecated clippy.toml MSRV settings found"); |
| 201 | + Ok(()) |
| 202 | +} |
0 commit comments