Skip to content

Commit

Permalink
test(oxlint): test fix test case
Browse files Browse the repository at this point in the history
closes #6061
  • Loading branch information
Boshen committed Oct 21, 2024
1 parent 6ffdcc0 commit efc94d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/linter/fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger
26 changes: 24 additions & 2 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ mod test {
let args = &["fixtures/linter"];
let result = test(args);
assert!(result.number_of_rules > 0);
assert_eq!(result.number_of_files, 2);
assert_eq!(result.number_of_warnings, 2);
assert_eq!(result.number_of_files, 3);
assert_eq!(result.number_of_warnings, 3);
assert_eq!(result.number_of_errors, 0);
}

Expand Down Expand Up @@ -564,4 +564,26 @@ mod test {
assert_eq!(result.number_of_warnings, 0);
assert_eq!(result.number_of_errors, 1);
}

#[test]
fn test_fix() {
use std::fs;
let file = "fixtures/linter/fix.js";
let args = &["--fix", file];
let content = fs::read_to_string(file).unwrap();
assert_eq!(&content, "debugger\n");

// Apply fix to the file.
let _ = test(args);
assert_eq!(fs::read_to_string(file).unwrap(), "\n");

// File should not be modified if no fix is applied.
let modified_before = fs::metadata(file).unwrap().modified().unwrap();
let _ = test(args);
let modified_after = fs::metadata(file).unwrap().modified().unwrap();
assert_eq!(modified_before, modified_after);

// Write the file back.
fs::write(file, content).unwrap();
}
}

0 comments on commit efc94d7

Please sign in to comment.