diff --git a/cli/src/commands/lint.rs b/cli/src/commands/lint.rs index 773ba2da..ba9d8159 100644 --- a/cli/src/commands/lint.rs +++ b/cli/src/commands/lint.rs @@ -70,7 +70,7 @@ pub fn execute(path_str: Option<&str>, fix: bool) -> ExitCode { } } - // Fix deprecation warnings + // If --fix is enabled, automatically modernize deprecated keywords and constructs if fix { let migrated = migrate_source(&content); if migrated != content { diff --git a/cli/tests/cli_tests.rs b/cli/tests/cli_tests.rs index 7dc47930..f8de2999 100644 --- a/cli/tests/cli_tests.rs +++ b/cli/tests/cli_tests.rs @@ -43,3 +43,30 @@ fn test_cli_emit_commands() { _ => panic!("Expected EmitLlvm subcommand"), } } + +#[test] +fn test_cli_lint_fix() { + let args = vec!["tech", "lint", "src/main.txs", "--fix"]; + let cli = Cli::try_parse_from(args).expect("args parse successfully"); + match cli.command { + Commands::Lint { path, fix } => { + assert_eq!(path.as_deref(), Some("src/main.txs")); + assert!(fix); + } + _ => panic!("Expected Lint subcommand"), + } + + // Verify actual lint execute with --fix on a temporary file with deprecated syntax + let temp_dir = std::env::temp_dir().join("techscript_lint_test"); + let _ = std::fs::create_dir_all(&temp_dir); + let test_file = temp_dir.join("deprecated.txs"); + std::fs::write(&test_file, "let x = 10;").expect("write test file"); + + let status = techscript_cli::commands::lint::execute(Some(test_file.to_str().unwrap()), true); + assert_eq!(status, techscript_cli::exit_code::ExitCode::Success); + + let content = std::fs::read_to_string(&test_file).expect("read test file"); + assert_eq!(content, "x = 10"); + + let _ = std::fs::remove_dir_all(&temp_dir); +}