Skip to content

Commit b03cec6

Browse files
committedOct 21, 2024·
test(oxlint): add --fix test case (#6747)
closes #6061
1 parent 6ffdcc0 commit b03cec6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
 

‎apps/oxlint/fixtures/linter/fix.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debugger

‎apps/oxlint/src/lint.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ mod test {
265265
let args = &["fixtures/linter"];
266266
let result = test(args);
267267
assert!(result.number_of_rules > 0);
268-
assert_eq!(result.number_of_files, 2);
269-
assert_eq!(result.number_of_warnings, 2);
268+
assert_eq!(result.number_of_files, 3);
269+
assert_eq!(result.number_of_warnings, 3);
270270
assert_eq!(result.number_of_errors, 0);
271271
}
272272

@@ -564,4 +564,26 @@ mod test {
564564
assert_eq!(result.number_of_warnings, 0);
565565
assert_eq!(result.number_of_errors, 1);
566566
}
567+
568+
#[test]
569+
fn test_fix() {
570+
use std::fs;
571+
let file = "fixtures/linter/fix.js";
572+
let args = &["--fix", file];
573+
let content = fs::read_to_string(file).unwrap();
574+
assert_eq!(&content, "debugger\n");
575+
576+
// Apply fix to the file.
577+
let _ = test(args);
578+
assert_eq!(fs::read_to_string(file).unwrap(), "\n");
579+
580+
// File should not be modified if no fix is applied.
581+
let modified_before = fs::metadata(file).unwrap().modified().unwrap();
582+
let _ = test(args);
583+
let modified_after = fs::metadata(file).unwrap().modified().unwrap();
584+
assert_eq!(modified_before, modified_after);
585+
586+
// Write the file back.
587+
fs::write(file, content).unwrap();
588+
}
567589
}

0 commit comments

Comments
 (0)
Please sign in to comment.