From ccb6a89554fff6e85f4b6ce4f444374b5f52a68d Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Jan 2025 13:54:14 +0100 Subject: [PATCH] test(linter): use snapshot testing instead of LintResult --- Cargo.lock | 1 + apps/oxlint/src/lint.rs | 261 ++++-------------- apps/oxlint/src/output_formatter/default.rs | 132 +++++---- ...7566__tests__function__main.js@oxlint.snap | 7 + ...gnore fixtures__linter__nan.js@oxlint.snap | 17 ++ ...gnore fixtures__linter__nan.js@oxlint.snap | 7 + ...ern _____.vue fixtures__linter@oxlint.snap | 9 + ...l -D no-cycle fixtures__flow__@oxlint.snap | 9 + ...ugin fixtures__flow__index.mjs@oxlint.snap | 9 + ...xlint.snap => _--print-config@oxlint.snap} | 3 +- ...rc_vitest_replace__foo.test.js@oxlint.snap | 26 ++ ...nap => _-A all --print-config@oxlint.snap} | 3 +- .../_-A all fixtures__linter@oxlint.snap | 9 + ... fixtures__linter__debugger.js@oxlint.snap | 17 ++ ... fixtures__linter__debugger.js@oxlint.snap | 9 + ...ixtures__eslintrc_env__test.js@oxlint.snap | 16 ++ ...on fixtures__no_undef__test.js@oxlint.snap | 16 ++ ...ore_patterns__ignore_extension@oxlint.snap | 15 + ...ixtures__eslintrc_env__test.js@oxlint.snap | 9 + ...ixtures__eslintrc_off__test.js@oxlint.snap | 15 + ...rc_vitest_replace__foo.test.js@oxlint.snap | 9 + ...json fixtures__import__test.js@oxlint.snap | 18 ++ ... fixtures__linter__debugger.js@oxlint.snap | 17 ++ ...tures__no_console_off__test.js@oxlint.snap | 9 + ...pty_allow_empty_catch__test.js@oxlint.snap | 9 + ..._disallow_empty_catch__test.js@oxlint.snap | 17 ++ ...fixtures__overrides__other.jsx@oxlint.snap | 58 ++++ ...onfig.json fixtures__overrides@oxlint.snap | 38 +++ ... all -D eqeqeq --print-config@oxlint.snap} | 3 +- ...es__typescript_eslint__test.ts@oxlint.snap | 26 ++ ...es__typescript_eslint__test.ts@oxlint.snap | 34 +++ ...ixtures__astro__debugger.astro@oxlint.snap | 42 +++ .../snapshots/_fixtures__linter@oxlint.snap | 31 +++ ...er.js fixtures__linter__nan.js@oxlint.snap | 24 ++ ..._fixtures__linter__debugger.js@oxlint.snap | 17 ++ ...tures__svelte__debugger.svelte@oxlint.snap | 19 ++ .../_fixtures__vue__debugger.vue@oxlint.snap | 26 ++ .../_fixtures__vue__empty.vue@oxlint.snap | 9 + .../src/snapshots/_foo.asdf@oxlint.snap | 9 + ...o_config_detection_debugger.js@oxlint.snap | 17 ++ ...ore_directory_-c eslintrc.json@oxlint.snap | 17 ++ ...oxlint-typescript.json test.js@oxlint.snap | 34 +++ ... -c oxlint-vitest.json test.js@oxlint.snap | 36 +++ .../fixtures__linter_debugger.js@oxlint.snap | 17 ++ ...c_--format=checkstyle test.js@oxlint.snap} | 3 +- ...stic_--format=default test.js@oxlint.snap} | 21 +- ...ostic_--format=github test.js@oxlint.snap} | 3 +- ...gnostic_--format=json test.js@oxlint.snap} | 3 +- ...stic_--format=stylish test.js@oxlint.snap} | 3 +- apps/oxlint/src/tester.rs | 54 +++- crates/oxc_diagnostics/Cargo.toml | 1 + crates/oxc_diagnostics/src/service.rs | 9 +- 52 files changed, 926 insertions(+), 297 deletions(-) create mode 100644 apps/oxlint/src/snapshots/_--ignore-path fixtures__issue_7566__.oxlintignore fixtures__issue_7566__tests__main.js fixtures__issue_7566__tests__function__main.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore --no-ignore fixtures__linter__nan.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore fixtures__linter__nan.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_--ignore-pattern _____.js --ignore-pattern _____.vue fixtures__linter@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_--import-plugin -A all -D no-cycle fixtures__flow__@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_--import-plugin fixtures__flow__index.mjs@oxlint.snap rename apps/oxlint/src/snapshots/{--print-config@oxlint.snap => _--print-config@oxlint.snap} (98%) create mode 100644 apps/oxlint/src/snapshots/_--vitest-plugin -c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap rename apps/oxlint/src/snapshots/{-A all --print-config@oxlint.snap => _-A all --print-config@oxlint.snap} (93%) create mode 100644 apps/oxlint/src/snapshots/_-A all fixtures__linter@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-D correctness fixtures__linter__debugger.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-W correctness -A no-debugger fixtures__linter__debugger.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-W no-undef -c fixtures__eslintrc_env__eslintrc_no_env.json fixtures__eslintrc_env__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-W no-undef -c fixtures__no_undef__eslintrc.json fixtures__no_undef__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__eslintrc_env__eslintrc_env_browser.json fixtures__eslintrc_env__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__eslintrc_off__eslintrc.json fixtures__eslintrc_off__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__import__.oxlintrc.json fixtures__import__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__linter__eslintrc.json fixtures__linter__debugger.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__no_console_off__eslintrc.json fixtures__no_console_off__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__no_empty_allow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_allow_empty_catch__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__no_empty_disallow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_disallow_empty_catch__test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.js -c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.ts -c fixtures__overrides__.oxlintrc.json fixtures__overrides__other.jsx@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__overrides__directories-config.json fixtures__overrides@oxlint.snap rename apps/oxlint/src/snapshots/{-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap => _-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap} (88%) create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json --disable-typescript-plugin fixtures__typescript_eslint__test.ts@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json fixtures__typescript_eslint__test.ts@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__astro__debugger.astro@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__linter@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__linter__debugger.js fixtures__linter__nan.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__linter__debugger.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__svelte__debugger.svelte@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__vue__debugger.vue@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_fixtures__vue__empty.vue@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/_foo.asdf@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/fixtures__auto_config_detection_debugger.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__ignore_directory_-c eslintrc.json@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/fixtures__eslint_and_typescript_alias_rules_-c oxlint-eslint.json test.js -c oxlint-typescript.json test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/fixtures__jest_and_vitest_alias_rules_-c oxlint-jest.json test.js -c oxlint-vitest.json test.js@oxlint.snap create mode 100644 apps/oxlint/src/snapshots/fixtures__linter_debugger.js@oxlint.snap rename apps/oxlint/src/snapshots/{--format=checkstyle test.js@oxlint.snap => fixtures__output_formatter_diagnostic_--format=checkstyle test.js@oxlint.snap} (85%) rename apps/oxlint/src/snapshots/{--format=default test.js@oxlint.snap => fixtures__output_formatter_diagnostic_--format=default test.js@oxlint.snap} (86%) rename apps/oxlint/src/snapshots/{--format=github test.js@oxlint.snap => fixtures__output_formatter_diagnostic_--format=github test.js@oxlint.snap} (83%) rename apps/oxlint/src/snapshots/{--format=json test.js@oxlint.snap => fixtures__output_formatter_diagnostic_--format=json test.js@oxlint.snap} (92%) rename apps/oxlint/src/snapshots/{--format=stylish test.js@oxlint.snap => fixtures__output_formatter_diagnostic_--format=stylish test.js@oxlint.snap} (84%) diff --git a/Cargo.lock b/Cargo.lock index 381520a8f464d..0b649de30a9b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1746,6 +1746,7 @@ dependencies = [ name = "oxc_diagnostics" version = "0.48.1" dependencies = [ + "cow-utils", "oxc-miette", ] diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 9cfc4d69ccccd..6c740a90990ce 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -338,67 +338,49 @@ mod test { tester::Tester, }; + // lints the full directory of fixtures, + // so do not snapshot it, test only #[test] fn no_arg() { let args = &[]; - let result = Tester::new().get_lint_result(args); - assert!(result.number_of_warnings > 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test(args); } #[test] fn dir() { let args = &["fixtures/linter"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 3); - assert_eq!(result.number_of_warnings, 3); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn cwd() { let args = &["debugger.js"]; - let result = Tester::new().with_cwd("fixtures/linter".into()).get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().with_cwd("fixtures/linter".into()).test_and_snapshot(args); } #[test] fn file() { let args = &["fixtures/linter/debugger.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn multi_files() { let args = &["fixtures/linter/debugger.js", "fixtures/linter/nan.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 2); - assert_eq!(result.number_of_warnings, 2); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn wrong_extension() { let args = &["foo.asdf"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 0); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn ignore_pattern() { let args = &["--ignore-pattern", "**/*.js", "--ignore-pattern", "**/*.vue", "fixtures/linter"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 0); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } /// When a file is explicitly passed as a path and `--no-ignore` @@ -407,10 +389,7 @@ mod test { #[test] fn ignore_file_overrides_explicit_args() { let args = &["--ignore-path", "fixtures/linter/.customignore", "fixtures/linter/nan.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 0); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -421,85 +400,56 @@ mod test { "--no-ignore", "fixtures/linter/nan.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn ignore_flow() { let args = &["--import-plugin", "fixtures/flow/index.mjs"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] // https://github.com/oxc-project/oxc/issues/7406 fn ignore_flow_import_plugin_directory() { let args = &["--import-plugin", "-A all", "-D no-cycle", "fixtures/flow/"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 2); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn filter_allow_all() { let args = &["-A", "all", "fixtures/linter"]; - let result = Tester::new().get_lint_result(args); - assert!(result.number_of_files > 0); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn filter_allow_one() { let args = &["-W", "correctness", "-A", "no-debugger", "fixtures/linter/debugger.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn filter_error() { let args = &["-D", "correctness", "fixtures/linter/debugger.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + Tester::new().test_and_snapshot(args); } #[test] fn eslintrc_error() { let args = &["-c", "fixtures/linter/eslintrc.json", "fixtures/linter/debugger.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + Tester::new().test_and_snapshot(args); } #[test] fn eslintrc_off() { let args = &["-c", "fixtures/eslintrc_off/eslintrc.json", "fixtures/eslintrc_off/test.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); // triggered by no_empty_file - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn oxlint_config_auto_detection() { let args = &["debugger.js"]; - let result = - Tester::new().with_cwd("fixtures/auto_config_detection".into()).get_lint_result(args); - - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + Tester::new().with_cwd("fixtures/auto_config_detection".into()).test_and_snapshot(args); } #[test] @@ -511,10 +461,7 @@ mod test { "fixtures/no_undef/eslintrc.json", "fixtures/no_undef/test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -526,10 +473,7 @@ mod test { "fixtures/eslintrc_env/eslintrc_no_env.json", "fixtures/eslintrc_env/test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -539,10 +483,7 @@ mod test { "fixtures/eslintrc_env/eslintrc_env_browser.json", "fixtures/eslintrc_env/test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -554,10 +495,7 @@ mod test { "no-empty", "fixtures/no_empty_allow_empty_catch/test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -569,20 +507,14 @@ mod test { "no-empty", "fixtures/no_empty_disallow_empty_catch/test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn no_console_off() { let args = &["-c", "fixtures/no_console_off/eslintrc.json", "fixtures/no_console_off/test.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -592,10 +524,7 @@ mod test { "fixtures/typescript_eslint/eslintrc.json", "fixtures/typescript_eslint/test.ts", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 3); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -606,52 +535,37 @@ mod test { "--disable-typescript-plugin", "fixtures/typescript_eslint/test.ts", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 2); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn lint_vue_file() { let args = &["fixtures/vue/debugger.vue"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 2); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn lint_empty_vue_file() { let args = &["fixtures/vue/empty.vue"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn lint_astro_file() { let args = &["fixtures/astro/debugger.astro"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 4); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn lint_svelte_file() { let args = &["fixtures/svelte/debugger.svelte"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn test_tsconfig_option() { // passed - Tester::new().get_lint_result(&["--tsconfig", "fixtures/tsconfig/tsconfig.json"]); + Tester::new().test(&["--tsconfig", "fixtures/tsconfig/tsconfig.json"]); // failed assert!(Tester::new() @@ -666,10 +580,7 @@ mod test { "fixtures/eslintrc_vitest_replace/eslintrc.json", "fixtures/eslintrc_vitest_replace/foo.test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] @@ -680,18 +591,13 @@ mod test { "fixtures/eslintrc_vitest_replace/eslintrc.json", "fixtures/eslintrc_vitest_replace/foo.test.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_errors, 1); + Tester::new().test_and_snapshot(args); } #[test] fn test_import_plugin_enabled_in_config() { let args = &["-c", "fixtures/import/.oxlintrc.json", "fixtures/import/test.js"]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + Tester::new().test_and_snapshot(args); } #[test] @@ -705,7 +611,7 @@ mod test { assert_eq!(&content, "debugger\n"); // Apply fix to the file. - let _ = Tester::new().get_lint_result(args); + Tester::new().test(args); #[expect(clippy::disallowed_methods)] let new_content = fs::read_to_string(file).unwrap().replace("\r\n", "\n"); assert_eq!(new_content, "\n"); @@ -713,7 +619,7 @@ mod test { // File should not be modified if no fix is applied. let modified_before: std::time::SystemTime = fs::metadata(file).unwrap().modified().unwrap(); - let _ = Tester::new().get_lint_result(args); + Tester::new().test(args); let modified_after = fs::metadata(file).unwrap().modified().unwrap(); assert_eq!(modified_before, modified_after); @@ -756,36 +662,16 @@ mod test { #[test] fn test_overrides() { - let args = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/test.js"]; - let result = Tester::new().get_lint_result(args); - - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); - - let args = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/test.ts"]; - let result = Tester::new().get_lint_result(args); - - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 1); - assert_eq!(result.number_of_errors, 1); - - let args = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/other.jsx"]; - let result = Tester::new().get_lint_result(args); - - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + let args_1 = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/test.js"]; + let args_2 = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/test.ts"]; + let args_3 = &["-c", "fixtures/overrides/.oxlintrc.json", "fixtures/overrides/other.jsx"]; + Tester::new().test_and_snapshot_multiple(&[args_1, args_2, args_3]); } #[test] fn test_overrides_directories() { let args = &["-c", "fixtures/overrides/directories-config.json", "fixtures/overrides"]; - let result = Tester::new().get_lint_result(args); - - assert_eq!(result.number_of_files, 7); - assert_eq!(result.number_of_warnings, 2); - assert_eq!(result.number_of_errors, 2); + Tester::new().test_and_snapshot(args); } #[test] @@ -795,18 +681,16 @@ mod test { "fixtures/config_ignore_patterns/ignore_extension/eslintrc.json", "fixtures/config_ignore_patterns/ignore_extension", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); + Tester::new().test_and_snapshot(args); } #[test] fn test_config_ignore_patterns_directory() { - let result = Tester::new() + let args = &["-c", "eslintrc.json"]; + Tester::new() .with_cwd("fixtures/config_ignore_patterns/ignore_directory".into()) - .get_lint_result(&["-c", "eslintrc.json"]); - - assert_eq!(result.number_of_files, 1); + .test_and_snapshot(args); } // Issue: @@ -818,56 +702,25 @@ mod test { "fixtures/issue_7566/tests/main.js", "fixtures/issue_7566/tests/function/main.js", ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 0); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 0); + Tester::new().test_and_snapshot(args); } #[test] fn test_jest_and_vitest_alias_rules() { - let args = &[ - "-c", - "fixtures/jest_and_vitest_alias_rules/oxlint-jest.json", - "fixtures/jest_and_vitest_alias_rules/test.js", - ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); - - let args = &[ - "-c", - "fixtures/jest_and_vitest_alias_rules/oxlint-vitest.json", - "fixtures/jest_and_vitest_alias_rules/test.js", - ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + let args_1 = &["-c", "oxlint-jest.json", "test.js"]; + let args_2 = &["-c", "oxlint-vitest.json", "test.js"]; + Tester::new() + .with_cwd("fixtures/jest_and_vitest_alias_rules".into()) + .test_and_snapshot_multiple(&[args_1, args_2]); } #[test] fn test_eslint_and_typescript_alias_rules() { - let args = &[ - "-c", - "fixtures/eslint_and_typescript_alias_rules/oxlint-eslint.json", - "fixtures/eslint_and_typescript_alias_rules/test.js", - ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); - - let args = &[ - "-c", - "fixtures/eslint_and_typescript_alias_rules/oxlint-typescript.json", - "fixtures/eslint_and_typescript_alias_rules/test.js", - ]; - let result = Tester::new().get_lint_result(args); - assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 0); - assert_eq!(result.number_of_errors, 1); + let args_1 = &["-c", "oxlint-eslint.json", "test.js"]; + let args_2 = &["-c", "oxlint-typescript.json", "test.js"]; + Tester::new() + .with_cwd("fixtures/eslint_and_typescript_alias_rules".into()) + .test_and_snapshot_multiple(&[args_1, args_2]); } #[test] diff --git a/apps/oxlint/src/output_formatter/default.rs b/apps/oxlint/src/output_formatter/default.rs index 6de7da6d35d3b..38d9944048f9a 100644 --- a/apps/oxlint/src/output_formatter/default.rs +++ b/apps/oxlint/src/output_formatter/default.rs @@ -35,9 +35,17 @@ impl InternalFormatter for DefaultOutputFormatter { )) } + #[cfg(not(test))] fn get_diagnostic_reporter(&self) -> Box { Box::new(GraphicalReporter::default()) } + + #[cfg(test)] + fn get_diagnostic_reporter(&self) -> Box { + use crate::output_formatter::default::test_implementation::GraphicalReporterTester; + + Box::new(GraphicalReporterTester::default()) + } } impl DefaultOutputFormatter { @@ -58,61 +66,87 @@ struct GraphicalReporter { handler: GraphicalReportHandler, } -#[cfg(not(test))] impl Default for GraphicalReporter { fn default() -> Self { Self { handler: GraphicalReportHandler::new() } } } -#[cfg(test)] -use oxc_diagnostics::GraphicalTheme; +impl DiagnosticReporter for GraphicalReporter { + fn finish(&mut self, result: &DiagnosticResult) -> Option { + Some(get_diagnostic_result_output(result)) + } -/// we need to override the GraphicalReport for the tests -/// because our CI can not handle colors output and [`GraphicalReportHandler`] will auto detect the environment -#[cfg(test)] -impl Default for GraphicalReporter { - fn default() -> Self { - Self { handler: GraphicalReportHandler::new_themed(GraphicalTheme::none()) } + fn render_error(&mut self, error: Error) -> Option { + let mut output = String::new(); + self.handler.render_report(&mut output, error.as_ref()).unwrap(); + Some(output) } } -impl DiagnosticReporter for GraphicalReporter { - fn finish(&mut self, result: &DiagnosticResult) -> Option { - let mut output = String::new(); +fn get_diagnostic_result_output(result: &DiagnosticResult) -> String { + let mut output = String::new(); - if result.warnings_count() + result.errors_count() > 0 { - output.push('\n'); - } + if result.warnings_count() + result.errors_count() > 0 { + output.push('\n'); + } + output.push_str( + format!( + "Found {} warning{} and {} error{}.\n", + result.warnings_count(), + if result.warnings_count() == 1 { "" } else { "s" }, + result.errors_count(), + if result.errors_count() == 1 { "" } else { "s" }, + ) + .as_str(), + ); + + if result.max_warnings_exceeded() { output.push_str( - format!( - "Found {} warning{} and {} error{}.\n", - result.warnings_count(), - if result.warnings_count() == 1 { "" } else { "s" }, - result.errors_count(), - if result.errors_count() == 1 { "" } else { "s" }, - ) - .as_str(), + format!("Exceeded maximum number of warnings. Found {}.\n", result.warnings_count()) + .as_str(), ); + } - if result.max_warnings_exceeded() { - output.push_str( - format!( - "Exceeded maximum number of warnings. Found {}.\n", - result.warnings_count() - ) - .as_str(), - ); - } + output +} - Some(output) +#[cfg(test)] +mod test_implementation { + use oxc_diagnostics::{ + reporter::{DiagnosticReporter, DiagnosticResult, Info}, + Error, GraphicalReportHandler, GraphicalTheme, + }; + + use crate::output_formatter::default::get_diagnostic_result_output; + + #[derive(Default)] + pub struct GraphicalReporterTester { + diagnostics: Vec, } - fn render_error(&mut self, error: Error) -> Option { - let mut output = String::new(); - self.handler.render_report(&mut output, error.as_ref()).unwrap(); - Some(output) + impl DiagnosticReporter for GraphicalReporterTester { + fn finish(&mut self, result: &DiagnosticResult) -> Option { + let handler = GraphicalReportHandler::new_themed(GraphicalTheme::none()); + let mut output = String::new(); + + self.diagnostics.sort_by_key(|diagnostic| Info::new(diagnostic).filename); + self.diagnostics.sort_by_key(|diagnostic| Info::new(diagnostic).start.line); + + for diagnostic in &self.diagnostics { + handler.render_report(&mut output, diagnostic.as_ref()).unwrap(); + } + + output.push_str(&get_diagnostic_result_output(result)); + + Some(output) + } + + fn render_error(&mut self, error: Error) -> Option { + self.diagnostics.push(error); + None + } } } @@ -124,12 +158,7 @@ mod test { default::{DefaultOutputFormatter, GraphicalReporter}, InternalFormatter, LintCommandInfo, }; - use miette::NamedSource; - use oxc_diagnostics::{ - reporter::{DiagnosticReporter, DiagnosticResult}, - OxcDiagnostic, - }; - use oxc_span::Span; + use oxc_diagnostics::reporter::{DiagnosticReporter, DiagnosticResult}; #[test] fn all_rules() { @@ -198,21 +227,4 @@ mod test { "\nFound 6 warnings and 4 errors.\nExceeded maximum number of warnings. Found 6.\n" ); } - - #[test] - fn reporter_error() { - let mut reporter = GraphicalReporter::default(); - - let error = OxcDiagnostic::warn("error message") - .with_label(Span::new(0, 8)) - .with_source_code(NamedSource::new("file://test.ts", "debugger;")); - - let result = reporter.render_error(error); - - assert!(result.is_some()); - assert_eq!( - result.unwrap(), - "\n ! error message\n ,-[file://test.ts:1:1]\n 1 | debugger;\n : ^^^^^^^^\n `----\n" - ); - } } diff --git a/apps/oxlint/src/snapshots/_--ignore-path fixtures__issue_7566__.oxlintignore fixtures__issue_7566__tests__main.js fixtures__issue_7566__tests__function__main.js@oxlint.snap b/apps/oxlint/src/snapshots/_--ignore-path fixtures__issue_7566__.oxlintignore fixtures__issue_7566__tests__main.js fixtures__issue_7566__tests__function__main.js@oxlint.snap new file mode 100644 index 0000000000000..57dc472d99a23 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--ignore-path fixtures__issue_7566__.oxlintignore fixtures__issue_7566__tests__main.js fixtures__issue_7566__tests__function__main.js@oxlint.snap @@ -0,0 +1,7 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --ignore-path fixtures/issue_7566/.oxlintignore fixtures/issue_7566/tests/main.js fixtures/issue_7566/tests/function/main.js +working directory: +---------- diff --git a/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore --no-ignore fixtures__linter__nan.js@oxlint.snap b/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore --no-ignore fixtures__linter__nan.js@oxlint.snap new file mode 100644 index 0000000000000..51f4b6ec61066 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore --no-ignore fixtures__linter__nan.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --ignore-path fixtures/linter/.customignore --no-ignore fixtures/linter/nan.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/use-isnan.html\eslint(use-isnan)]8;;\: Requires calls to isNaN() when checking for NaN + ,-[fixtures/linter/nan.js:1:8] + 1 | 123 == NaN; + : ^^^ + `---- + help: Use the isNaN function to compare with NaN. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore fixtures__linter__nan.js@oxlint.snap b/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore fixtures__linter__nan.js@oxlint.snap new file mode 100644 index 0000000000000..b0fc86082c74d --- /dev/null +++ b/apps/oxlint/src/snapshots/_--ignore-path fixtures__linter__.customignore fixtures__linter__nan.js@oxlint.snap @@ -0,0 +1,7 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --ignore-path fixtures/linter/.customignore fixtures/linter/nan.js +working directory: +---------- diff --git a/apps/oxlint/src/snapshots/_--ignore-pattern _____.js --ignore-pattern _____.vue fixtures__linter@oxlint.snap b/apps/oxlint/src/snapshots/_--ignore-pattern _____.js --ignore-pattern _____.vue fixtures__linter@oxlint.snap new file mode 100644 index 0000000000000..0b32555145a54 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--ignore-pattern _____.js --ignore-pattern _____.vue fixtures__linter@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --ignore-pattern **/*.js --ignore-pattern **/*.vue fixtures/linter +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 0 files with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_--import-plugin -A all -D no-cycle fixtures__flow__@oxlint.snap b/apps/oxlint/src/snapshots/_--import-plugin -A all -D no-cycle fixtures__flow__@oxlint.snap new file mode 100644 index 0000000000000..4f875b63939e6 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--import-plugin -A all -D no-cycle fixtures__flow__@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --import-plugin -A all -D no-cycle fixtures/flow/ +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 2 files with 99 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_--import-plugin fixtures__flow__index.mjs@oxlint.snap b/apps/oxlint/src/snapshots/_--import-plugin fixtures__flow__index.mjs@oxlint.snap new file mode 100644 index 0000000000000..93851a3fbf622 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--import-plugin fixtures__flow__index.mjs@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --import-plugin fixtures/flow/index.mjs +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 99 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/--print-config@oxlint.snap b/apps/oxlint/src/snapshots/_--print-config@oxlint.snap similarity index 98% rename from apps/oxlint/src/snapshots/--print-config@oxlint.snap rename to apps/oxlint/src/snapshots/_--print-config@oxlint.snap index 1552a078f166d..cb02b3c41dd80 100644 --- a/apps/oxlint/src/snapshots/--print-config@oxlint.snap +++ b/apps/oxlint/src/snapshots/_--print-config@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## ---print-config +arguments: --print-config +working directory: ---------- { "plugins": [ diff --git a/apps/oxlint/src/snapshots/_--vitest-plugin -c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap b/apps/oxlint/src/snapshots/_--vitest-plugin -c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap new file mode 100644 index 0000000000000..1f15e83eaa362 --- /dev/null +++ b/apps/oxlint/src/snapshots/_--vitest-plugin -c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap @@ -0,0 +1,26 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --vitest-plugin -c fixtures/eslintrc_vitest_replace/eslintrc.json fixtures/eslintrc_vitest_replace/foo.test.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/expect-expect.html\eslint-plugin-jest(expect-expect)]8;;\: Test has no assertions + ,-[fixtures/eslintrc_vitest_replace/foo.test.js:1:1] + 1 | test.skip('foo', () => { + : ^^^^^^^^^ + 2 | // ... + `---- + help: Add assertion(s) in this Test + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/no-disabled-tests.html\eslint-plugin-jest(no-disabled-tests)]8;;\: Disabled test + ,-[fixtures/eslintrc_vitest_replace/foo.test.js:1:1] + 1 | test.skip('foo', () => { + : ^^^^^^^^^ + 2 | // ... + `---- + help: Remove the appending `.skip` + +Found 1 warning and 1 error. +Finished in ms on 1 file with 109 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/-A all --print-config@oxlint.snap b/apps/oxlint/src/snapshots/_-A all --print-config@oxlint.snap similarity index 93% rename from apps/oxlint/src/snapshots/-A all --print-config@oxlint.snap rename to apps/oxlint/src/snapshots/_-A all --print-config@oxlint.snap index b3e4703c1e9eb..5adf96c6d9f6d 100644 --- a/apps/oxlint/src/snapshots/-A all --print-config@oxlint.snap +++ b/apps/oxlint/src/snapshots/_-A all --print-config@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## --A all --print-config +arguments: -A all --print-config +working directory: ---------- { "plugins": [ diff --git a/apps/oxlint/src/snapshots/_-A all fixtures__linter@oxlint.snap b/apps/oxlint/src/snapshots/_-A all fixtures__linter@oxlint.snap new file mode 100644 index 0000000000000..45335849b7cc3 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-A all fixtures__linter@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -A all fixtures/linter +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 3 files with 0 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-D correctness fixtures__linter__debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/_-D correctness fixtures__linter__debugger.js@oxlint.snap new file mode 100644 index 0000000000000..4d3123fe4c50b --- /dev/null +++ b/apps/oxlint/src/snapshots/_-D correctness fixtures__linter__debugger.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -D correctness fixtures/linter/debugger.js +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-W correctness -A no-debugger fixtures__linter__debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/_-W correctness -A no-debugger fixtures__linter__debugger.js@oxlint.snap new file mode 100644 index 0000000000000..0c540f7393cd1 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-W correctness -A no-debugger fixtures__linter__debugger.js@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -W correctness -A no-debugger fixtures/linter/debugger.js +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 96 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__eslintrc_env__eslintrc_no_env.json fixtures__eslintrc_env__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__eslintrc_env__eslintrc_no_env.json fixtures__eslintrc_env__test.js@oxlint.snap new file mode 100644 index 0000000000000..9288c52699a0b --- /dev/null +++ b/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__eslintrc_env__eslintrc_no_env.json fixtures__eslintrc_env__test.js@oxlint.snap @@ -0,0 +1,16 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -W no-undef -c fixtures/eslintrc_env/eslintrc_no_env.json fixtures/eslintrc_env/test.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-undef.html\eslint(no-undef)]8;;\: 'console' is not defined. + ,-[fixtures/eslintrc_env/test.js:1:1] + 1 | console.log('') + : ^^^^^^^ + `---- + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 98 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__no_undef__eslintrc.json fixtures__no_undef__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__no_undef__eslintrc.json fixtures__no_undef__test.js@oxlint.snap new file mode 100644 index 0000000000000..9dff60f8ae7c9 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-W no-undef -c fixtures__no_undef__eslintrc.json fixtures__no_undef__test.js@oxlint.snap @@ -0,0 +1,16 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -W no-undef -c fixtures/no_undef/eslintrc.json fixtures/no_undef/test.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-undef.html\eslint(no-undef)]8;;\: 'console' is not defined. + ,-[fixtures/no_undef/test.js:1:1] + 1 | console.log(foo) + : ^^^^^^^ + `---- + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 98 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension@oxlint.snap new file mode 100644 index 0000000000000..ed1ee43583284 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension@oxlint.snap @@ -0,0 +1,15 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/config_ignore_patterns/ignore_extension/eslintrc.json fixtures/config_ignore_patterns/ignore_extension +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-empty-file.html\eslint-plugin-unicorn(no-empty-file)]8;;\: Empty files are not allowed. + ,-[fixtures/config_ignore_patterns/ignore_extension/main.ts:1:1] + `---- + help: Delete this file or add some code to it. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_env__eslintrc_env_browser.json fixtures__eslintrc_env__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_env__eslintrc_env_browser.json fixtures__eslintrc_env__test.js@oxlint.snap new file mode 100644 index 0000000000000..3eb99ac339b71 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_env__eslintrc_env_browser.json fixtures__eslintrc_env__test.js@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/eslintrc_env/eslintrc_env_browser.json fixtures/eslintrc_env/test.js +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 98 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_off__eslintrc.json fixtures__eslintrc_off__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_off__eslintrc.json fixtures__eslintrc_off__test.js@oxlint.snap new file mode 100644 index 0000000000000..af20b1d862db7 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_off__eslintrc.json fixtures__eslintrc_off__test.js@oxlint.snap @@ -0,0 +1,15 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/eslintrc_off/eslintrc.json fixtures/eslintrc_off/test.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-empty-file.html\eslint-plugin-unicorn(no-empty-file)]8;;\: Empty files are not allowed. + ,-[fixtures/eslintrc_off/test.js:1:1] + `---- + help: Delete this file or add some code to it. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap new file mode 100644 index 0000000000000..c25447093c6cf --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__eslintrc_vitest_replace__eslintrc.json fixtures__eslintrc_vitest_replace__foo.test.js@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/eslintrc_vitest_replace/eslintrc.json fixtures/eslintrc_vitest_replace/foo.test.js +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__import__.oxlintrc.json fixtures__import__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__import__.oxlintrc.json fixtures__import__test.js@oxlint.snap new file mode 100644 index 0000000000000..0a15dcd8fb7da --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__import__.oxlintrc.json fixtures__import__test.js@oxlint.snap @@ -0,0 +1,18 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/import/.oxlintrc.json fixtures/import/test.js +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/import/no-default-export.html\eslint-plugin-import(no-default-export)]8;;\: Prefer named exports + ,-[fixtures/import/test.js:7:8] + 6 | // import/no-default-export + 7 | export default function foo() {} + : ^^^^^^^ + 8 | + `---- + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 50 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__linter__eslintrc.json fixtures__linter__debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__linter__eslintrc.json fixtures__linter__debugger.js@oxlint.snap new file mode 100644 index 0000000000000..8f3bf438865a2 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__linter__eslintrc.json fixtures__linter__debugger.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/linter/eslintrc.json fixtures/linter/debugger.js +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__no_console_off__eslintrc.json fixtures__no_console_off__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__no_console_off__eslintrc.json fixtures__no_console_off__test.js@oxlint.snap new file mode 100644 index 0000000000000..e0c8c2605d671 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__no_console_off__eslintrc.json fixtures__no_console_off__test.js@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/no_console_off/eslintrc.json fixtures/no_console_off/test.js +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__no_empty_allow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_allow_empty_catch__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__no_empty_allow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_allow_empty_catch__test.js@oxlint.snap new file mode 100644 index 0000000000000..bd96491933691 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__no_empty_allow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_allow_empty_catch__test.js@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/no_empty_allow_empty_catch/eslintrc.json -W no-empty fixtures/no_empty_allow_empty_catch/test.js +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 98 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__no_empty_disallow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_disallow_empty_catch__test.js@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__no_empty_disallow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_disallow_empty_catch__test.js@oxlint.snap new file mode 100644 index 0000000000000..b2894fc27f629 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__no_empty_disallow_empty_catch__eslintrc.json -W no-empty fixtures__no_empty_disallow_empty_catch__test.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/no_empty_disallow_empty_catch/eslintrc.json -W no-empty fixtures/no_empty_disallow_empty_catch/test.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-empty.html\eslint(no-empty)]8;;\: Unexpected empty block statements + ,-[fixtures/no_empty_disallow_empty_catch/test.js:1:29] + 1 | try { console.log() } catch {} + : ^^ + `---- + help: Remove this block or add a comment inside it + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 98 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.js -c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.ts -c fixtures__overrides__.oxlintrc.json fixtures__overrides__other.jsx@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.js -c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.ts -c fixtures__overrides__.oxlintrc.json fixtures__overrides__other.jsx@oxlint.snap new file mode 100644 index 0000000000000..9fddaab6f8b1e --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.js -c fixtures__overrides__.oxlintrc.json fixtures__overrides__test.ts -c fixtures__overrides__.oxlintrc.json fixtures__overrides__other.jsx@oxlint.snap @@ -0,0 +1,58 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/test.js +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead. + ,-[fixtures/overrides/test.js:1:1] + 1 | var msg = "hello"; + : ^^^ + 2 | console.log(msg); + `---- + help: Replace var with let or const + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 99 rules using 1 threads. + +########## +arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/test.ts +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead. + ,-[fixtures/overrides/test.ts:1:1] + 1 | var msg = "hello"; + : ^^^ + 2 | console.log(msg); + `---- + help: Replace var with let or const + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement. + ,-[fixtures/overrides/test.ts:2:1] + 1 | var msg = "hello"; + 2 | console.log(msg); + : ^^^^^^^^^^^ + `---- + help: Delete this console statement. + +Found 1 warning and 1 error. +Finished in ms on 1 file with 99 rules using 1 threads. + +########## +arguments: -c fixtures/overrides/.oxlintrc.json fixtures/overrides/other.jsx +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-var.html\eslint(no-var)]8;;\: Unexpected var, use let or const instead. + ,-[fixtures/overrides/other.jsx:1:1] + 1 | var msg = "hello"; + : ^^^ + 2 | console.log(msg); + `---- + help: Replace var with let or const + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 99 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__overrides__directories-config.json fixtures__overrides@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__overrides__directories-config.json fixtures__overrides@oxlint.snap new file mode 100644 index 0000000000000..4463c1f3be196 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__overrides__directories-config.json fixtures__overrides@oxlint.snap @@ -0,0 +1,38 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/overrides/directories-config.json fixtures/overrides +working directory: +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/overrides/src/oxlint.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/overrides/lib/tests/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/overrides/lib/index.ts:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/overrides/src/tests/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 2 warnings and 2 errors. +Finished in ms on 7 files with 96 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap similarity index 88% rename from apps/oxlint/src/snapshots/-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap rename to apps/oxlint/src/snapshots/_-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap index 603c71ac07cb1..7e2751d02c222 100644 --- a/apps/oxlint/src/snapshots/-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap +++ b/apps/oxlint/src/snapshots/_-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq --print-config@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## --c fixtures/print_config/ban_rules/eslintrc.json -A all -D eqeqeq --print-config +arguments: -c fixtures/print_config/ban_rules/eslintrc.json -A all -D eqeqeq --print-config +working directory: ---------- { "plugins": [ diff --git a/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json --disable-typescript-plugin fixtures__typescript_eslint__test.ts@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json --disable-typescript-plugin fixtures__typescript_eslint__test.ts@oxlint.snap new file mode 100644 index 0000000000000..11e8250bbc76b --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json --disable-typescript-plugin fixtures__typescript_eslint__test.ts@oxlint.snap @@ -0,0 +1,26 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/typescript_eslint/eslintrc.json --disable-typescript-plugin fixtures/typescript_eslint/test.ts +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'X' is declared but never used. + ,-[fixtures/typescript_eslint/test.ts:1:11] + 1 | namespace X { + : | + : `-- 'X' is declared here + 2 | } + `---- + help: Consider removing this declaration. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime. + ,-[fixtures/typescript_eslint/test.ts:4:1] + 3 | + 4 | 9007199254740993 // no-loss-of-precision + : ^^^^^^^^^^^^^^^^ + `---- + +Found 2 warnings and 0 errors. +Finished in ms on 1 file with 48 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json fixtures__typescript_eslint__test.ts@oxlint.snap b/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json fixtures__typescript_eslint__test.ts@oxlint.snap new file mode 100644 index 0000000000000..d7533d5dfa568 --- /dev/null +++ b/apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json fixtures__typescript_eslint__test.ts@oxlint.snap @@ -0,0 +1,34 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c fixtures/typescript_eslint/eslintrc.json fixtures/typescript_eslint/test.ts +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'X' is declared but never used. + ,-[fixtures/typescript_eslint/test.ts:1:11] + 1 | namespace X { + : | + : `-- 'X' is declared here + 2 | } + `---- + help: Consider removing this declaration. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-namespace.html\typescript-eslint(no-namespace)]8;;\: ES2015 module syntax is preferred over namespaces. + ,-[fixtures/typescript_eslint/test.ts:1:1] + 1 | namespace X { + : ^^^^^^^^^ + 2 | } + `---- + help: Replace the namespace with an ES2015 module or use `declare module` + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime. + ,-[fixtures/typescript_eslint/test.ts:4:1] + 3 | + 4 | 9007199254740993 // no-loss-of-precision + : ^^^^^^^^^^^^^^^^ + `---- + +Found 3 warnings and 0 errors. +Finished in ms on 1 file with 59 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__astro__debugger.astro@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__astro__debugger.astro@oxlint.snap new file mode 100644 index 0000000000000..718851cbf5a50 --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__astro__debugger.astro@oxlint.snap @@ -0,0 +1,42 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/astro/debugger.astro +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/astro/debugger.astro:2:1] + 1 | + 2 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/astro/debugger.astro:2:3] + 1 | + 2 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/astro/debugger.astro:2:3] + 1 | + 2 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/astro/debugger.astro:2:3] + 1 | + 2 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + +Found 4 warnings and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__linter@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__linter@oxlint.snap new file mode 100644 index 0000000000000..6c0ae17497660 --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__linter@oxlint.snap @@ -0,0 +1,31 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/linter +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/fix.js:1:1] + 1 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/use-isnan.html\eslint(use-isnan)]8;;\: Requires calls to isNaN() when checking for NaN + ,-[fixtures/linter/nan.js:1:8] + 1 | 123 == NaN; + : ^^^ + `---- + help: Use the isNaN function to compare with NaN. + +Found 3 warnings and 0 errors. +Finished in ms on 3 files with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js fixtures__linter__nan.js@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js fixtures__linter__nan.js@oxlint.snap new file mode 100644 index 0000000000000..8a8c6ea1479a9 --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js fixtures__linter__nan.js@oxlint.snap @@ -0,0 +1,24 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/linter/debugger.js fixtures/linter/nan.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/use-isnan.html\eslint(use-isnan)]8;;\: Requires calls to isNaN() when checking for NaN + ,-[fixtures/linter/nan.js:1:8] + 1 | 123 == NaN; + : ^^^ + `---- + help: Use the isNaN function to compare with NaN. + +Found 2 warnings and 0 errors. +Finished in ms on 2 files with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js@oxlint.snap new file mode 100644 index 0000000000000..836cdfa98a72b --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__linter__debugger.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/linter/debugger.js +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/linter/debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__svelte__debugger.svelte@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__svelte__debugger.svelte@oxlint.snap new file mode 100644 index 0000000000000..13eaa5eae280b --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__svelte__debugger.svelte@oxlint.snap @@ -0,0 +1,19 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/svelte/debugger.svelte +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/svelte/debugger.svelte:2:2] + 1 | + 2 | debugger; + : ^^^^^^^^^ + 3 | + `---- + help: Delete this code. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__vue__debugger.vue@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__vue__debugger.vue@oxlint.snap new file mode 100644 index 0000000000000..52713c4d4d623 --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__vue__debugger.vue@oxlint.snap @@ -0,0 +1,26 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/vue/debugger.vue +working directory: +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/vue/debugger.vue:2:5] + 1 | + 2 | debugger + : ^^^^^^^^ + `---- + help: Delete this code. + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[fixtures/vue/debugger.vue:3:5] + 2 | let foo: T; // test ts syntax + 3 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 2 warnings and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_fixtures__vue__empty.vue@oxlint.snap b/apps/oxlint/src/snapshots/_fixtures__vue__empty.vue@oxlint.snap new file mode 100644 index 0000000000000..d9a82428553df --- /dev/null +++ b/apps/oxlint/src/snapshots/_fixtures__vue__empty.vue@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: fixtures/vue/empty.vue +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/_foo.asdf@oxlint.snap b/apps/oxlint/src/snapshots/_foo.asdf@oxlint.snap new file mode 100644 index 0000000000000..e104f11e2a804 --- /dev/null +++ b/apps/oxlint/src/snapshots/_foo.asdf@oxlint.snap @@ -0,0 +1,9 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: foo.asdf +working directory: +---------- +Found 0 warnings and 0 errors. +Finished in ms on 0 files with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/fixtures__auto_config_detection_debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__auto_config_detection_debugger.js@oxlint.snap new file mode 100644 index 0000000000000..b0210407596d3 --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__auto_config_detection_debugger.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: debugger.js +working directory: fixtures/auto_config_detection +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__ignore_directory_-c eslintrc.json@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__ignore_directory_-c eslintrc.json@oxlint.snap new file mode 100644 index 0000000000000..e427d3db4c88c --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__ignore_directory_-c eslintrc.json@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c eslintrc.json +working directory: fixtures/config_ignore_patterns/ignore_directory +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-empty-file.html\eslint-plugin-unicorn(no-empty-file)]8;;\: Empty files are not allowed. + ,-[main.js:1:1] + 1 | + : ^ + `---- + help: Delete this file or add some code to it. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/fixtures__eslint_and_typescript_alias_rules_-c oxlint-eslint.json test.js -c oxlint-typescript.json test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__eslint_and_typescript_alias_rules_-c oxlint-eslint.json test.js -c oxlint-typescript.json test.js@oxlint.snap new file mode 100644 index 0000000000000..c2296b1042ece --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__eslint_and_typescript_alias_rules_-c oxlint-eslint.json test.js -c oxlint-typescript.json test.js@oxlint.snap @@ -0,0 +1,34 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c oxlint-eslint.json test.js +working directory: fixtures/eslint_and_typescript_alias_rules +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-magic-numbers.html\eslint(no-magic-numbers)]8;;\: No magic number: 0.19 + ,-[test.js:4:32] + 3 | const price = 200; + 4 | const price_with_tax = price * 0.19; // taxes are expensive + : ^^^^ + 5 | + `---- + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 1 rules using 1 threads. + +########## +arguments: -c oxlint-typescript.json test.js +working directory: fixtures/eslint_and_typescript_alias_rules +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-magic-numbers.html\eslint(no-magic-numbers)]8;;\: No magic number: 0.19 + ,-[test.js:4:32] + 3 | const price = 200; + 4 | const price_with_tax = price * 0.19; // taxes are expensive + : ^^^^ + 5 | + `---- + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 1 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/fixtures__jest_and_vitest_alias_rules_-c oxlint-jest.json test.js -c oxlint-vitest.json test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__jest_and_vitest_alias_rules_-c oxlint-jest.json test.js -c oxlint-vitest.json test.js@oxlint.snap new file mode 100644 index 0000000000000..d8e62a6e7dc7e --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__jest_and_vitest_alias_rules_-c oxlint-jest.json test.js -c oxlint-vitest.json test.js@oxlint.snap @@ -0,0 +1,36 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c oxlint-jest.json test.js +working directory: fixtures/jest_and_vitest_alias_rules +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/no-identical-title.html\eslint-plugin-jest(no-identical-title)]8;;\: Test title is used multiple times in the same describe block. + ,-[test.js:3:6] + 2 | it("works", () => {}); + 3 | it("works", () => {}); + : ^^^^^^^ + 4 | }); + `---- + help: Change the title of test. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 1 rules using 1 threads. + +########## +arguments: -c oxlint-vitest.json test.js +working directory: fixtures/jest_and_vitest_alias_rules +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jest/no-identical-title.html\eslint-plugin-jest(no-identical-title)]8;;\: Test title is used multiple times in the same describe block. + ,-[test.js:3:6] + 2 | it("works", () => {}); + 3 | it("works", () => {}); + : ^^^^^^^ + 4 | }); + `---- + help: Change the title of test. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 1 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/fixtures__linter_debugger.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__linter_debugger.js@oxlint.snap new file mode 100644 index 0000000000000..df0dae9c45f09 --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__linter_debugger.js@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: debugger.js +working directory: fixtures/linter +---------- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[debugger.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + +Found 1 warning and 0 errors. +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/--format=checkstyle test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=checkstyle test.js@oxlint.snap similarity index 85% rename from apps/oxlint/src/snapshots/--format=checkstyle test.js@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=checkstyle test.js@oxlint.snap index 53cd97c1ff64c..91c902e18b1da 100644 --- a/apps/oxlint/src/snapshots/--format=checkstyle test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=checkstyle test.js@oxlint.snap @@ -2,6 +2,7 @@ source: apps/oxlint/src/tester.rs --- ########## ---format=checkstyle test.js +arguments: --format=checkstyle test.js +working directory: fixtures/output_formatter_diagnostic ---------- diff --git a/apps/oxlint/src/snapshots/--format=default test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=default test.js@oxlint.snap similarity index 86% rename from apps/oxlint/src/snapshots/--format=default test.js@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=default test.js@oxlint.snap index 34516fdf0481e..48dd1dd0f87a2 100644 --- a/apps/oxlint/src/snapshots/--format=default test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=default test.js@oxlint.snap @@ -2,17 +2,10 @@ source: apps/oxlint/src/tester.rs --- ########## ---format=default test.js +arguments: --format=default test.js +working directory: fixtures/output_formatter_diagnostic ---------- - x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed - ,-[test.js:5:1] - 4 | - 5 | debugger; - : ^^^^^^^^^ - `---- - help: Delete this code. - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Function 'foo' is declared but never used. ,-[test.js:1:10] 1 | function foo(a, b) { @@ -31,5 +24,13 @@ source: apps/oxlint/src/tester.rs `---- help: Consider removing this parameter. + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[test.js:5:1] + 4 | + 5 | debugger; + : ^^^^^^^^^ + `---- + help: Delete this code. + Found 2 warnings and 1 error. -Finished in on 1 file with 97 rules using . +Finished in ms on 1 file with 97 rules using 1 threads. diff --git a/apps/oxlint/src/snapshots/--format=github test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=github test.js@oxlint.snap similarity index 83% rename from apps/oxlint/src/snapshots/--format=github test.js@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=github test.js@oxlint.snap index 57d10d2077202..c764bf9fa9578 100644 --- a/apps/oxlint/src/snapshots/--format=github test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=github test.js@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## ---format=github test.js +arguments: --format=github test.js +working directory: fixtures/output_formatter_diagnostic ---------- ::error file=test.js,line=5,endLine=5,col=1,endColumn=10,title=oxlint::`debugger` statement is not allowed ::warning file=test.js,line=1,endLine=1,col=10,endColumn=13,title=oxlint::Function 'foo' is declared but never used. diff --git a/apps/oxlint/src/snapshots/--format=json test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=json test.js@oxlint.snap similarity index 92% rename from apps/oxlint/src/snapshots/--format=json test.js@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=json test.js@oxlint.snap index ed80afd1fec6a..b4ed3878df14c 100644 --- a/apps/oxlint/src/snapshots/--format=json test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=json test.js@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## ---format=json test.js +arguments: --format=json test.js +working directory: fixtures/output_formatter_diagnostic ---------- [ {"message": "`debugger` statement is not allowed","code": "eslint(no-debugger)","severity": "error","causes": [],"url": "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html","help": "Delete this code.","filename": "test.js","labels": [{"span": {"offset": 38,"length": 9}}],"related": []}, diff --git a/apps/oxlint/src/snapshots/--format=stylish test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=stylish test.js@oxlint.snap similarity index 84% rename from apps/oxlint/src/snapshots/--format=stylish test.js@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=stylish test.js@oxlint.snap index fb00d12c7ef5b..8d8bf92a27952 100644 --- a/apps/oxlint/src/snapshots/--format=stylish test.js@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=stylish test.js@oxlint.snap @@ -2,7 +2,8 @@ source: apps/oxlint/src/tester.rs --- ########## ---format=stylish test.js +arguments: --format=stylish test.js +working directory: fixtures/output_formatter_diagnostic ---------- test.js diff --git a/apps/oxlint/src/tester.rs b/apps/oxlint/src/tester.rs index acc0681daa100..4a1d4e88f8f87 100644 --- a/apps/oxlint/src/tester.rs +++ b/apps/oxlint/src/tester.rs @@ -1,5 +1,5 @@ #[cfg(test)] -use crate::cli::{lint_command, CliRunResult, LintResult, LintRunner}; +use crate::cli::{lint_command, CliRunResult, LintRunner}; #[cfg(test)] use crate::runner::Runner; #[cfg(test)] @@ -16,6 +16,11 @@ impl Tester { pub fn new() -> Self { let cwd = env::current_dir().unwrap(); + // disable multiple workers for diagnostic + // because the snapshot could change every time when we are analyzing multiple files + // do not unwrap because we can set it only one time. + let _ = rayon::ThreadPoolBuilder::new().num_threads(1).build_global(); + Self { cwd } } @@ -24,16 +29,13 @@ impl Tester { self } - pub fn get_lint_result(&self, args: &[&str]) -> LintResult { + pub fn test(&self, args: &[&str]) { let mut new_args = vec!["--silent"]; new_args.extend(args); let options = lint_command().run_inner(new_args.as_slice()).unwrap(); let mut output = Vec::new(); - match LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output) { - CliRunResult::LintResult(lint_result) => lint_result, - other => panic!("{other:?}"), - } + let _ = LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output); } pub fn get_invalid_option_result(&self, args: &[&str]) -> String { @@ -51,27 +53,49 @@ impl Tester { } pub fn test_and_snapshot(&self, args: &[&str]) { - let mut settings = insta::Settings::clone_current(); + self.test_and_snapshot_multiple(&[args]); + } - let options = lint_command().run_inner(args).unwrap(); + pub fn test_and_snapshot_multiple(&self, multiple_args: &[&[&str]]) { let mut output: Vec = Vec::new(); - let args_string = args.join(" "); + let current_cwd = std::env::current_dir().unwrap(); + let relative_dir = self.cwd.strip_prefix(current_cwd).unwrap_or(&self.cwd); - output.extend_from_slice(format!("########## \n{args_string}\n----------\n").as_bytes()); - let _ = LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output); - output.push(b'\n'); + for args in multiple_args { + let options = lint_command().run_inner(*args).unwrap(); + let args_string = args.join(" "); + + output.extend_from_slice("########## \n".as_bytes()); + output.extend_from_slice(format!("arguments: {args_string}\n").as_bytes()); + output.extend_from_slice( + format!("working directory: {}\n", relative_dir.to_str().unwrap()).as_bytes(), + ); + output.extend_from_slice("----------\n".as_bytes()); + let _ = LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output); + output.push(b'\n'); + } + let mut settings = insta::Settings::clone_current(); settings.set_prepend_module_to_snapshot(false); settings.set_omit_expression(true); settings.set_snapshot_suffix("oxlint"); - let regex = Regex::new(r"\d+ms|\d+ threads?").unwrap(); + let regex = Regex::new(r"\d+ms").unwrap(); let output_string = &String::from_utf8(output).unwrap(); - let output_string = regex.replace_all(output_string, ""); + let output_string = regex.replace_all(output_string, "ms"); + + let full_args_list = + multiple_args.iter().map(|args| args.join(" ")).collect::>().join(" "); + + let snapshot_file_name = format!("{}_{}", relative_dir.to_str().unwrap(), full_args_list); + // windows can not handle filenames with * + // allow replace instead of cow_replace. It only test + #[allow(clippy::disallowed_methods)] + let snapshot_file_name = snapshot_file_name.replace('*', "_"); settings.bind(|| { - insta::assert_snapshot!(format!("{}", args_string), output_string); + insta::assert_snapshot!(snapshot_file_name, output_string); }); } } diff --git a/crates/oxc_diagnostics/Cargo.toml b/crates/oxc_diagnostics/Cargo.toml index 41f16b778cfd1..c4b3f1fe1862d 100644 --- a/crates/oxc_diagnostics/Cargo.toml +++ b/crates/oxc_diagnostics/Cargo.toml @@ -19,4 +19,5 @@ workspace = true doctest = false [dependencies] +cow-utils = { workspace = true } miette = { workspace = true } diff --git a/crates/oxc_diagnostics/src/service.rs b/crates/oxc_diagnostics/src/service.rs index ee0e6bd507760..4f32c22de30b5 100644 --- a/crates/oxc_diagnostics/src/service.rs +++ b/crates/oxc_diagnostics/src/service.rs @@ -4,6 +4,8 @@ use std::{ sync::{mpsc, Arc}, }; +use cow_utils::CowUtils; + use crate::{ reporter::{DiagnosticReporter, DiagnosticResult}, Error, NamedSource, OxcDiagnostic, Severity, @@ -131,7 +133,12 @@ impl DiagnosticService { diagnostics: Vec, ) -> (PathBuf, Vec) { let path = path.as_ref(); - let source = Arc::new(NamedSource::new(path.to_string_lossy(), source_text.to_owned())); + let path_display = path.to_string_lossy(); + // replace windows \ path separator with posix style one + // reflects what eslint is outputting + let path_display = path_display.cow_replace('\\', "/"); + + let source = Arc::new(NamedSource::new(path_display, source_text.to_owned())); let diagnostics = diagnostics .into_iter() .map(|diagnostic| diagnostic.with_source_code(Arc::clone(&source)))