Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading