diff --git a/cli/src/commands/lint.rs b/cli/src/commands/lint.rs index 5726cd9d..e2c1e182 100644 --- a/cli/src/commands/lint.rs +++ b/cli/src/commands/lint.rs @@ -2,6 +2,7 @@ //! //! Performs static analysis linting on TechScript sources. +use crate::commands::migrate::migrate_source; use crate::exit_code::ExitCode; use std::path::{Path, PathBuf}; @@ -43,6 +44,7 @@ pub fn execute(path_str: Option<&str>, fix: bool) -> ExitCode { let linter = techscript_linter::Linter::new(); let mut violation_count = 0; + let mut fixed_count = 0; for file in files_to_lint { if let Ok(content) = std::fs::read_to_string(&file) { @@ -66,9 +68,26 @@ pub fn execute(path_str: Option<&str>, fix: bool) -> ExitCode { } } } + + // Fix deprecation warnings + if fix { + let migrated = migrate_source(&content); + if migrated != content { + if let Err(e) = std::fs::write(&file, migrated) { + eprintln!("Error writing fixed file {:?}: {}", file, e); + } else { + println!("Fixed deprecated keywords in: {:?}", file); + fixed_count += 1; + } + } + } } } + if fix && fixed_count > 0 { + println!("Fixed deprecation warnings in {} file(s).", fixed_count); + } + if violation_count > 0 { println!("Linting found {} violation(s).", violation_count); ExitCode::LintFailure diff --git a/cli/src/commands/migrate.rs b/cli/src/commands/migrate.rs index 8bbd611d..292592b6 100644 --- a/cli/src/commands/migrate.rs +++ b/cli/src/commands/migrate.rs @@ -66,7 +66,7 @@ pub fn execute(path_str: Option<&str>) -> ExitCode { ExitCode::Success } -fn migrate_source(source: &str) -> String { +pub fn migrate_source(source: &str) -> String { let mut reporter = techscript_errors::DiagnosticReporter::new(); let tokens = techscript_lexer::lex_recovered(source, &mut reporter); let _program = techscript_parser::parse_recovered(&tokens, &mut reporter);