diff --git a/apps/oxlint/test/__snapshots__/e2e.test.ts.snap b/apps/oxlint/test/__snapshots__/e2e.test.ts.snap deleted file mode 100644 index c3b6d3a5138fe..0000000000000 --- a/apps/oxlint/test/__snapshots__/e2e.test.ts.snap +++ /dev/null @@ -1,1911 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`oxlint CLI > should apply fixes when \`--fix\` is enabled 1`] = ` -"Found 0 warnings and 0 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should apply fixes when \`--fix\` is enabled 2`] = ` -" - -let daddy = 1; -let abacus = 2; -let magic = 3; -let damned = 4; -let elephant = 5; -let feck = 6; -let numpty = 7; -let dangermouse = 8; -let granular = 9; -let cowabunga = 10; - - -" -`; - -exports[`oxlint CLI > should have UTF-16 spans in AST 1`] = ` -" - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | // £ - \`---- - help: Remove the debugger statement - - x utf16-plugin(no-debugger): Debugger at 0-9 - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | // £ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:3:1] - 2 | // £ - 3 | debugger; - : ^^^^^^^^^ - 4 | // 🤨 - \`---- - help: Remove the debugger statement - - x utf16-plugin(no-debugger): Debugger at 15-24 - ,-[files/index.js:3:1] - 2 | // £ - 3 | debugger; - : ^^^^^^^^^ - 4 | // 🤨 - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:6:3] - 5 | { - 6 | debugger; - : ^^^^^^^^^ - 7 | } - \`---- - help: Remove the debugger statement - - x utf16-plugin(no-debugger): Debugger at 35-44 - ,-[files/index.js:6:3] - 5 | { - 6 | debugger; - : ^^^^^^^^^ - 7 | } - \`---- - -Found 3 warnings and 3 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should lint a directory with errors with JS plugins enabled 1`] = ` -" - x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should lint a directory with errors without JS plugins enabled 1`] = ` -" - x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should lint a directory without errors with JS plugins enabled 1`] = ` -"Found 0 warnings and 0 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should lint a directory without errors without JS plugins enabled 1`] = ` -"Found 0 warnings and 0 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should load a custom plugin 1`] = ` -" - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 1 warning and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should load a custom plugin when configured in overrides 1`] = ` -" - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 1 warning and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should load a custom plugin with multiple files 1`] = ` -" - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/01.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/01.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/02.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/02.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/03.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/03.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/04.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/04.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/05.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/05.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/06.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/06.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/07.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/07.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/08.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/08.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/09.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/09.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/10.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/10.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/11.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/11.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/12.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/12.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/13.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/13.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/14.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/14.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/15.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/15.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/16.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/16.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/17.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/17.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/18.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/18.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/19.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/19.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/20.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/20.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 20 warnings and 20 errors. -Finished in Xms on 20 files using X threads." -`; - -exports[`oxlint CLI > should load a custom plugin with various import styles 1`] = ` -" - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - - x plugin1(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - x plugin2(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - x plugin3(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - x plugin4(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - x plugin5(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - x plugin6(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - -Found 1 warning and 6 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should not apply fixes when \`--fix\` is disabled 1`] = ` -" - x fixes-plugin(fixes): Remove debugger statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | - \`---- - - x fixes-plugin(fixes): Replace "a" with "daddy" - ,-[files/index.js:3:5] - 2 | - 3 | let a = 1; - : ^ - 4 | let b = 2; - \`---- - - x fixes-plugin(fixes): Replace "b" with "abacus" - ,-[files/index.js:4:5] - 3 | let a = 1; - 4 | let b = 2; - : ^ - 5 | let c = 3; - \`---- - - x fixes-plugin(fixes): Prefix "c" with "magi" - ,-[files/index.js:5:5] - 4 | let b = 2; - 5 | let c = 3; - : ^ - 6 | let d = 4; - \`---- - - x fixes-plugin(fixes): Prefix "d" with "damne" - ,-[files/index.js:6:5] - 5 | let c = 3; - 6 | let d = 4; - : ^ - 7 | let e = 5; - \`---- - - x fixes-plugin(fixes): Postfix "e" with "lephant" - ,-[files/index.js:7:5] - 6 | let d = 4; - 7 | let e = 5; - : ^ - 8 | let f = 6; - \`---- - - x fixes-plugin(fixes): Postfix "f" with "eck" - ,-[files/index.js:8:5] - 7 | let e = 5; - 8 | let f = 6; - : ^ - 9 | let g = 7; - \`---- - - x fixes-plugin(fixes): Replace "g" with "numpty" - ,-[files/index.js:9:5] - 8 | let f = 6; - 9 | let g = 7; - : ^ - 10 | let h = 8; - \`---- - - x fixes-plugin(fixes): Replace "h" with "dangermouse" - ,-[files/index.js:10:5] - 9 | let g = 7; - 10 | let h = 8; - : ^ - 11 | let i = 9; - \`---- - - x fixes-plugin(fixes): Replace "i" with "granular" - ,-[files/index.js:11:5] - 10 | let h = 8; - 11 | let i = 9; - : ^ - 12 | let j = 10; - \`---- - - x fixes-plugin(fixes): Replace "j" with "cowabunga" - ,-[files/index.js:12:5] - 11 | let i = 9; - 12 | let j = 10; - : ^ - 13 | - \`---- - - x fixes-plugin(fixes): Remove debugger statement - ,-[files/index.js:14:1] - 13 | - 14 | debugger; - : ^^^^^^^^^ - \`---- - -Found 0 warnings and 12 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should receive ESTree-compatible AST 1`] = ` -" - x estree-check(check): Visited nodes: - | * Program - | * VariableDeclaration: let - | * VariableDeclarator: (init: ObjectExpression) - | * Identifier: a - | * ObjectExpression - | * Identifier: x - | * Identifier: y - | * VariableDeclaration:exit: let - | * VariableDeclaration: const - | * VariableDeclarator: (init: BinaryExpression) - | * Identifier: b - | * BinaryExpression: * (right: BinaryExpression) - | * Identifier: x - | * BinaryExpression: + (right: Literal) - | * Literal: str - | * Literal: 123 - | * VariableDeclaration:exit: const - | * TSTypeAliasDeclaration: (typeAnnotation: TSStringKeyword) - | * Identifier: T - | * TSStringKeyword - | * TSTypeAliasDeclaration:exit: (typeAnnotation: TSStringKeyword) - | * TSTypeAliasDeclaration: (typeAnnotation: TSUnionType) - | * Identifier: U - | * TSUnionType: (types: TSStringKeyword, TSNumberKeyword) - | * TSStringKeyword - | * TSNumberKeyword - | * TSUnionType:exit: (types: TSStringKeyword, TSNumberKeyword) - | * TSTypeAliasDeclaration:exit: (typeAnnotation: TSUnionType) - | * Program:exit - ,-[files/index.ts:2:1] - 1 | // All \`Identifier\`s - 2 | ,-> let a = { x: y }; - 3 | | - 4 | | // No \`ParenthesizedExpression\`s in AST - 5 | | const b = (x * ((('str' + ((123)))))); - 6 | | - 7 | | // TS syntax - 8 | | type T = string; - 9 | | - 10 | | // No \`TSParenthesizedType\`s in AST - 11 | \`-> type U = (((((string)) | ((number))))); - \`---- - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should receive data via \`context\` 1`] = ` -" - x context-plugin(log-context): id: context-plugin/log-context - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x context-plugin(log-context): filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x context-plugin(log-context): physicalFilename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x context-plugin(log-context): id: context-plugin/log-context - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x context-plugin(log-context): filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x context-plugin(log-context): physicalFilename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - -Found 0 warnings and 6 errors. -Finished in Xms on 2 files using X threads." -`; - -exports[`oxlint CLI > should report an error if a a rule is not found within a custom plugin (via overrides) 1`] = ` -"Failed to build configuration. - - x Rule 'missing' not found in plugin 'basic-custom-plugin' -" -`; - -exports[`oxlint CLI > should report an error if a custom plugin in config but JS plugins are not enabled 1`] = ` -"Failed to parse configuration file. - - x \`plugins\` config contains './plugin.js'. JS plugins are not supported without \`--js-plugins\` CLI option. Note: JS plugin support is experimental. -" -`; - -exports[`oxlint CLI > should report an error if a custom plugin is missing 1`] = ` -"Failed to parse configuration file. - - x Failed to load JS plugin: ./plugin.js - | Cannot find module './plugin.js' -" -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during import 1`] = ` -"Failed to parse configuration file. - - x Failed to load JS plugin: ./plugin.js - | Error: whoops! - | at /apps/oxlint/test/fixtures/custom_plugin_import_error/plugin.js:1:7 -" -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in \`after\` hook 1`] = ` -" - x Error running JS plugin. - | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/files/index.js - | Error: Whoops! - | at after (/apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/plugin.js:10:19) - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in \`before\` hook 1`] = ` -" - x Error running JS plugin. - | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/files/index.js - | Error: Whoops! - | at before (/apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/plugin.js:10:19) - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in \`create\` method 1`] = ` -" - x Error running JS plugin. - | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_create_error/files/index.js - | Error: Whoops! - | at Object.create (/apps/oxlint/test/fixtures/custom_plugin_lint_create_error/plugin.js:8:15) - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in \`createOnce\` method 1`] = ` -"Failed to parse configuration file. - - x Failed to load JS plugin: ./plugin.js - | Error: Whoops! - | at Object.createOnce (/apps/oxlint/test/fixtures/custom_plugin_lint_createOnce_error/plugin.js:8:15) -" -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in \`fix\` function 1`] = ` -" - x Error running JS plugin. - | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/files/index.js - | Error: Whoops! - | at Object.fix (/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/plugin.js:14:23) - | at Identifier (/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/plugin.js:10:21) - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should report an error if a custom plugin throws an error during linting > in visit function 1`] = ` -" - x Error running JS plugin. - | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/files/index.js - | Error: Whoops! - | at Identifier (/apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/plugin.js:10:19) - -Found 0 warnings and 1 error. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should report an error if a rule is not found within a custom plugin 1`] = ` -"Failed to parse configuration file. - - x Rule 'unknown-rule' not found in plugin 'basic-custom-plugin' -" -`; - -exports[`oxlint CLI > should report the correct severity when using a custom plugin 1`] = ` -" - ! basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - \`---- - help: Remove the debugger statement - -Found 2 warnings and 0 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should respect disable directives for custom plugin rules 1`] = ` -" - x test-plugin(no-var): Use let or const instead of var - ,-[files/index.js:1:1] - 1 | var shouldError = 1; - : ^^^^^^^^^^^^^^^^^^^^ - 2 | - \`---- - - x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:10:1] - 9 | // should trigger an error - 10 | debugger; - : ^^^^^^^^^ - 11 | - \`---- - help: Remove the debugger statement - - x test-plugin(no-var): Use let or const instead of var - ,-[files/index.js:16:1] - 15 | /* oxlint-disable-next-line test-plugin */ // \`test-plugin\` should be \`test-plugin/no-var\` - 16 | var incorrectlyDisabled = 4; - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 17 | - \`---- - - x test-plugin(no-var): Use let or const instead of var - ,-[files/index.js:19:1] - 18 | /* oxlint-disable-next-line no-var */ // \`no-var\` should be \`test-plugin/no-var\` - 19 | var anotherIncorrectlyDisabled = 4; - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 20 | - \`---- - - x test-plugin(no-var): Use let or const instead of var - ,-[files/index.js:22:1] - 21 | // This var should trigger an error again - 22 | var shouldErrorAgain = 3; - : ^^^^^^^^^^^^^^^^^^^^^^^^^ - \`---- - -Found 0 warnings and 5 errors. -Finished in Xms on 1 file using X threads." -`; - -exports[`oxlint CLI > should support \`createOnce\` 1`] = ` -" - x create-once-plugin(after-only): after hook: filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(after-only): after hook: id: create-once-plugin/after-only - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: call count: 1 - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: filename: Cannot access \`context.filename\` in \`createOnce\` - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): before hook: filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): after hook: filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: id: Cannot access \`context.id\` in \`createOnce\` - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): before hook: id: create-once-plugin/always-run - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): after hook: id: create-once-plugin/always-run - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: options: Cannot access \`context.options\` in \`createOnce\` - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: physicalFilename: Cannot access \`context.physicalFilename\` in \`createOnce\` - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: report: Cannot report errors in \`createOnce\` - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: this === rule: true - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(before-only): before hook: filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(before-only): before hook: id: create-once-plugin/before-only - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(skip-run): before hook: filename: files/1.js - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(skip-run): before hook: id: create-once-plugin/skip-run - ,-[files/1.js:1:1] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(after-only): ident visit fn "x": filename: files/1.js - ,-[files/1.js:1:5] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(always-run): ident visit fn "x": filename: files/1.js - ,-[files/1.js:1:5] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(before-only): ident visit fn "x": filename: files/1.js - ,-[files/1.js:1:5] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(no-hooks): ident visit fn "x": filename: files/1.js - ,-[files/1.js:1:5] - 1 | let x; - : ^ - \`---- - - x create-once-plugin(after-only): after hook: filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(after-only): after hook: id: create-once-plugin/after-only - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: call count: 1 - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: filename: Cannot access \`context.filename\` in \`createOnce\` - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): before hook: filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): after hook: filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: id: Cannot access \`context.id\` in \`createOnce\` - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): before hook: id: create-once-plugin/always-run - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): after hook: id: create-once-plugin/always-run - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: options: Cannot access \`context.options\` in \`createOnce\` - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: physicalFilename: Cannot access \`context.physicalFilename\` in \`createOnce\` - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: report: Cannot report errors in \`createOnce\` - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): createOnce: this === rule: true - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(before-only): before hook: filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(before-only): before hook: id: create-once-plugin/before-only - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(skip-run): before hook: filename: files/2.js - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(skip-run): before hook: id: create-once-plugin/skip-run - ,-[files/2.js:1:1] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(after-only): ident visit fn "y": filename: files/2.js - ,-[files/2.js:1:5] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(always-run): ident visit fn "y": filename: files/2.js - ,-[files/2.js:1:5] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(before-only): ident visit fn "y": filename: files/2.js - ,-[files/2.js:1:5] - 1 | let y; - : ^ - \`---- - - x create-once-plugin(no-hooks): ident visit fn "y": filename: files/2.js - ,-[files/2.js:1:5] - 1 | let y; - : ^ - \`---- - -Found 0 warnings and 42 errors. -Finished in Xms on 2 files using X threads." -`; - -exports[`oxlint CLI > should support \`definePlugin\` 1`] = ` -" - x define-plugin-plugin(create): create body: - | this === rule: true - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once): after hook: - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): after hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-false): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once): ident visit fn "a": - | identNum: 1 - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-no-hooks): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once): ident visit fn "b": - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create-once-no-hooks): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-plugin(create): create body: - | this === rule: true - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once): after hook: - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-false): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-false): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once): ident visit fn "c": - | identNum: 1 - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-false): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-no-hooks): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once): ident visit fn "d": - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-after-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-false): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-before-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-plugin(create-once-no-hooks): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - -Found 0 warnings and 35 errors. -Finished in Xms on 2 files using X threads." -`; - -exports[`oxlint CLI > should support \`definePlugin\` and \`defineRule\` together 1`] = ` -" - x define-plugin-and-rule-plugin(create): create body: - | this === rule: true - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): after hook: - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): after hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-false): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): ident visit fn "a": - | identNum: 1 - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): ident visit fn "b": - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create): create body: - | this === rule: true - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): after hook: - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-false): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-false): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): ident visit fn "c": - | identNum: 1 - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-false): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once): ident visit fn "d": - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-false): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - -Found 0 warnings and 35 errors. -Finished in Xms on 2 files using X threads." -`; - -exports[`oxlint CLI > should support \`defineRule\` 1`] = ` -" - x define-rule-plugin(create): create body: - | this === rule: true - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once): after hook: - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): after hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-before-false): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): before hook: - | filename: files/1.js - ,-[files/1.js:1:1] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once): ident visit fn "a": - | identNum: 1 - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-no-hooks): ident visit fn "a": - | filename: files/1.js - ,-[files/1.js:1:5] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once): ident visit fn "b": - | identNum: 2 - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create-once-no-hooks): ident visit fn "b": - | filename: files/1.js - ,-[files/1.js:1:8] - 1 | let a, b; - : ^ - \`---- - - x define-rule-plugin(create): create body: - | this === rule: true - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once): before hook: - | createOnce call count: 1 - | this === rule: true - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once): after hook: - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-false): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-false): after hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): before hook: - | filename: files/2.js - ,-[files/2.js:1:1] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once): ident visit fn "c": - | identNum: 1 - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-false): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-no-hooks): ident visit fn "c": - | filename: files/2.js - ,-[files/2.js:1:5] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once): ident visit fn "d": - | identNum: 2 - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-after-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-false): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-before-only): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - - x define-rule-plugin(create-once-no-hooks): ident visit fn "d": - | filename: files/2.js - ,-[files/2.js:1:8] - 1 | let c, d; - : ^ - \`---- - -Found 0 warnings and 35 errors. -Finished in Xms on 2 files using X threads." -`; - -exports[`oxlint CLI > should work with multiple rules 1`] = ` -" - x basic-custom-plugin(no-debugger): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | - \`---- - - x basic-custom-plugin(no-debugger-2): Unexpected Debugger Statement - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed - ,-[files/index.js:1:1] - 1 | debugger; - : ^^^^^^^^^ - 2 | - \`---- - help: Remove the debugger statement - - x basic-custom-plugin(no-identifiers-named-foo): Unexpected Identifier named foo - ,-[files/index.js:3:1] - 2 | - 3 | foo; - : ^^^ - \`---- - - ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\\eslint(no-unused-expressions)]8;;\\: Expected expression to be used - ,-[files/index.js:3:1] - 2 | - 3 | foo; - : ^^^^ - \`---- - help: Consider using this expression or removing it - -Found 2 warnings and 3 errors. -Finished in Xms on 1 file using X threads." -`; diff --git a/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap b/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap deleted file mode 100644 index c7007e737773f..0000000000000 --- a/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap +++ /dev/null @@ -1,271 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`ESLint compatibility > \`definePlugin\` and \`defineRule\` together should work 1`] = ` -" -/apps/oxlint/test/fixtures/definePlugin_and_defineRule/files/1.js - 0:1 error create body: -this === rule: true define-plugin-and-rule-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/1.js define-plugin-and-rule-plugin/create-once - 0:1 error before hook: -filename: files/1.js define-plugin-and-rule-plugin/create-once-before-false - 0:1 error before hook: -filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/1.js define-plugin-and-rule-plugin/create-once - 0:1 error after hook: -filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-and-rule-plugin/create - 1:5 error ident visit fn "a": -identNum: 1 -filename: files/1.js define-plugin-and-rule-plugin/create-once - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-and-rule-plugin/create-once-no-hooks - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-and-rule-plugin/create - 1:8 error ident visit fn "b": -identNum: 2 -filename: files/1.js define-plugin-and-rule-plugin/create-once - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-and-rule-plugin/create-once-no-hooks - -/apps/oxlint/test/fixtures/definePlugin_and_defineRule/files/2.js - 0:1 error create body: -this === rule: true define-plugin-and-rule-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/2.js define-plugin-and-rule-plugin/create-once - 0:1 error before hook: -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false - 0:1 error before hook: -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/2.js define-plugin-and-rule-plugin/create-once - 0:1 error after hook: -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false - 0:1 error after hook: -filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-and-rule-plugin/create - 1:5 error ident visit fn "c": -identNum: 1 -filename: files/2.js define-plugin-and-rule-plugin/create-once - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-and-rule-plugin/create-once-no-hooks - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-and-rule-plugin/create - 1:8 error ident visit fn "d": -identNum: 2 -filename: files/2.js define-plugin-and-rule-plugin/create-once - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-and-rule-plugin/create-once-no-hooks - -✖ 35 problems (35 errors, 0 warnings) -" -`; - -exports[`ESLint compatibility > \`definePlugin\` should work 1`] = ` -" -/apps/oxlint/test/fixtures/definePlugin/files/1.js - 0:1 error create body: -this === rule: true define-plugin-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/1.js define-plugin-plugin/create-once - 0:1 error before hook: -filename: files/1.js define-plugin-plugin/create-once-before-false - 0:1 error before hook: -filename: files/1.js define-plugin-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/1.js define-plugin-plugin/create-once - 0:1 error after hook: -filename: files/1.js define-plugin-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-plugin/create - 1:5 error ident visit fn "a": -identNum: 1 -filename: files/1.js define-plugin-plugin/create-once - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-plugin/create-once-before-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-plugin-plugin/create-once-no-hooks - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-plugin/create - 1:8 error ident visit fn "b": -identNum: 2 -filename: files/1.js define-plugin-plugin/create-once - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-plugin/create-once-before-only - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-plugin/create-once-after-only - 1:8 error ident visit fn "b": -filename: files/1.js define-plugin-plugin/create-once-no-hooks - -/apps/oxlint/test/fixtures/definePlugin/files/2.js - 0:1 error create body: -this === rule: true define-plugin-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/2.js define-plugin-plugin/create-once - 0:1 error before hook: -filename: files/2.js define-plugin-plugin/create-once-before-false - 0:1 error before hook: -filename: files/2.js define-plugin-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/2.js define-plugin-plugin/create-once - 0:1 error after hook: -filename: files/2.js define-plugin-plugin/create-once-before-false - 0:1 error after hook: -filename: files/2.js define-plugin-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-plugin/create - 1:5 error ident visit fn "c": -identNum: 1 -filename: files/2.js define-plugin-plugin/create-once - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-plugin/create-once-before-false - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-plugin/create-once-before-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-plugin-plugin/create-once-no-hooks - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-plugin/create - 1:8 error ident visit fn "d": -identNum: 2 -filename: files/2.js define-plugin-plugin/create-once - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-plugin/create-once-before-false - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-plugin/create-once-before-only - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-plugin/create-once-after-only - 1:8 error ident visit fn "d": -filename: files/2.js define-plugin-plugin/create-once-no-hooks - -✖ 35 problems (35 errors, 0 warnings) -" -`; - -exports[`ESLint compatibility > \`defineRule\` should work 1`] = ` -" -/apps/oxlint/test/fixtures/defineRule/files/1.js - 0:1 error create body: -this === rule: true define-rule-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/1.js define-rule-plugin/create-once - 0:1 error before hook: -filename: files/1.js define-rule-plugin/create-once-before-false - 0:1 error before hook: -filename: files/1.js define-rule-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/1.js define-rule-plugin/create-once - 0:1 error after hook: -filename: files/1.js define-rule-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-rule-plugin/create - 1:5 error ident visit fn "a": -identNum: 1 -filename: files/1.js define-rule-plugin/create-once - 1:5 error ident visit fn "a": -filename: files/1.js define-rule-plugin/create-once-before-only - 1:5 error ident visit fn "a": -filename: files/1.js define-rule-plugin/create-once-after-only - 1:5 error ident visit fn "a": -filename: files/1.js define-rule-plugin/create-once-no-hooks - 1:8 error ident visit fn "b": -filename: files/1.js define-rule-plugin/create - 1:8 error ident visit fn "b": -identNum: 2 -filename: files/1.js define-rule-plugin/create-once - 1:8 error ident visit fn "b": -filename: files/1.js define-rule-plugin/create-once-before-only - 1:8 error ident visit fn "b": -filename: files/1.js define-rule-plugin/create-once-after-only - 1:8 error ident visit fn "b": -filename: files/1.js define-rule-plugin/create-once-no-hooks - -/apps/oxlint/test/fixtures/defineRule/files/2.js - 0:1 error create body: -this === rule: true define-rule-plugin/create - 0:1 error before hook: -createOnce call count: 1 -this === rule: true -filename: files/2.js define-rule-plugin/create-once - 0:1 error before hook: -filename: files/2.js define-rule-plugin/create-once-before-false - 0:1 error before hook: -filename: files/2.js define-rule-plugin/create-once-before-only - 0:1 error after hook: -identNum: 2 -filename: files/2.js define-rule-plugin/create-once - 0:1 error after hook: -filename: files/2.js define-rule-plugin/create-once-before-false - 0:1 error after hook: -filename: files/2.js define-rule-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-rule-plugin/create - 1:5 error ident visit fn "c": -identNum: 1 -filename: files/2.js define-rule-plugin/create-once - 1:5 error ident visit fn "c": -filename: files/2.js define-rule-plugin/create-once-before-false - 1:5 error ident visit fn "c": -filename: files/2.js define-rule-plugin/create-once-before-only - 1:5 error ident visit fn "c": -filename: files/2.js define-rule-plugin/create-once-after-only - 1:5 error ident visit fn "c": -filename: files/2.js define-rule-plugin/create-once-no-hooks - 1:8 error ident visit fn "d": -filename: files/2.js define-rule-plugin/create - 1:8 error ident visit fn "d": -identNum: 2 -filename: files/2.js define-rule-plugin/create-once - 1:8 error ident visit fn "d": -filename: files/2.js define-rule-plugin/create-once-before-false - 1:8 error ident visit fn "d": -filename: files/2.js define-rule-plugin/create-once-before-only - 1:8 error ident visit fn "d": -filename: files/2.js define-rule-plugin/create-once-after-only - 1:8 error ident visit fn "d": -filename: files/2.js define-rule-plugin/create-once-no-hooks - -✖ 35 problems (35 errors, 0 warnings) -" -`; diff --git a/apps/oxlint/test/e2e.test.ts b/apps/oxlint/test/e2e.test.ts index 326f52dd5702b..80cb750641454 100644 --- a/apps/oxlint/test/e2e.test.ts +++ b/apps/oxlint/test/e2e.test.ts @@ -1,274 +1,186 @@ -import fs from 'node:fs'; -import { dirname, join as pathJoin } from 'node:path'; +import fs from 'node:fs/promises'; +import { join as pathJoin } from 'node:path'; +import { describe, it } from 'vitest'; +import { FIXTURES_DIR_PATH, PACKAGE_ROOT_PATH, testFixtureWithCommand } from './utils.js'; -import { describe, expect, it } from 'vitest'; - -import { execa } from 'execa'; - -const PACKAGE_ROOT_PATH = dirname(import.meta.dirname); -const ROOT_PATH = pathJoin(PACKAGE_ROOT_PATH, '../../'); const CLI_PATH = pathJoin(PACKAGE_ROOT_PATH, 'dist/cli.js'); -const ROOT_URL = new URL('../../../', import.meta.url).href; -const FIXTURES_URL = new URL('./fixtures/', import.meta.url).href; - -async function runOxlintWithoutPlugins(cwd: string, args: string[] = []) { - return await execa('node', [CLI_PATH, ...args], { - cwd: pathJoin(PACKAGE_ROOT_PATH, cwd), - reject: false, - }); -} -async function runOxlint(cwd: string, args: string[] = []) { - return await runOxlintWithoutPlugins(cwd, ['--js-plugins', ...args]); +// Options to pass to `testFixture`. +interface TestOptions { + // Arguments to pass to the CLI. + // Defaults to `['--js-plugins']`. + args?: string[]; + // Name of the snapshot file. + // Defaults to `output`. + // Supply a different name when there are multiple tests for a single fixture. + snapshotName?: string; + // Function to get extra data to include in the snapshot + getExtraSnapshotData?: (dirPath: string) => Promise<{ [key: string]: string }>; } -async function runOxlintWithFixes(cwd: string, args: string[] = []) { - return await runOxlintWithoutPlugins(cwd, ['--js-plugins', '--fix', ...args]); -} - -function normalizeOutput(output: string): string { - let lines = output.split('\n'); - - // Remove timing and thread count info which can vary between runs - lines[lines.length - 1] = lines[lines.length - 1].replace( - /^Finished in \d+(?:\.\d+)?(?:s|ms|us|ns) on (\d+) file(s?) using \d+ threads.$/, - 'Finished in Xms on $1 file$2 using X threads.', - ); - - // Remove lines from stack traces which are outside `fixtures` directory. - // Replace path to repo root in stack traces with ``. - lines = lines.flatMap((line) => { - // e.g. ` | at file:///path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js:1:1` - // e.g. ` | at whatever (file:///path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js:1:1)` - let match = line.match(/^(\s*\|\s+at (?:.+?\()?)(.+)$/); - if (match) { - const [, premable, at] = match; - return at.startsWith(FIXTURES_URL) ? [`${premable}/${at.slice(ROOT_URL.length)}`] : []; - } else { - // e.g. ` | File path: /path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js` - match = line.match(/^(\s*\|\s+File path: )(.+)$/); - if (match) { - const [, premable, path] = match; - if (path.startsWith(ROOT_PATH)) return [`${premable}/${path.slice(ROOT_PATH.length)}`]; - } - } - return [line]; +/** + * Run a test fixture. + * @param fixtureName - Name of the fixture directory within `test/fixtures` + * @param options - Options to customize the test (optional) + */ +async function testFixture(fixtureName: string, options?: TestOptions): Promise { + const args = options?.args ?? ['--js-plugins']; + + await testFixtureWithCommand({ + command: 'node', + args: [CLI_PATH, ...args], + fixtureName, + snapshotName: options?.snapshotName ?? 'output', + getExtraSnapshotData: options?.getExtraSnapshotData, }); - - return lines.join('\n'); } describe('oxlint CLI', () => { it('should lint a directory without errors without JS plugins enabled', async () => { - const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/built_in_no_errors'); - expect(exitCode).toBe(0); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('built_in_no_errors', { args: [], snapshotName: 'plugins_disabled' }); }); it('should lint a directory with errors without JS plugins enabled', async () => { - const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/built_in_errors'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('built_in_errors', { args: [], snapshotName: 'plugins_disabled' }); }); it('should lint a directory without errors with JS plugins enabled', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/built_in_no_errors'); - expect(exitCode).toBe(0); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('built_in_no_errors', { snapshotName: 'plugins_enabled' }); }); it('should lint a directory with errors with JS plugins enabled', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/built_in_errors'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('built_in_errors', { snapshotName: 'plugins_enabled' }); }); it('should load a custom plugin', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/basic_custom_plugin'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('basic_custom_plugin', { snapshotName: 'plugins_enabled' }); }); it('should load a custom plugin with various import styles', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/load_paths'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('load_paths'); }); it('should load a custom plugin with multiple files', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/basic_custom_plugin_many_files'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('basic_custom_plugin_many_files'); }); it('should load a custom plugin when configured in overrides', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_via_overrides'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_via_overrides'); }); it('should report an error if a custom plugin in config but JS plugins are not enabled', async () => { - const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/basic_custom_plugin'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('basic_custom_plugin', { args: [], snapshotName: 'plugins_disabled' }); }); it('should report an error if a custom plugin is missing', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/missing_custom_plugin'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('missing_custom_plugin'); }); it('should report an error if a custom plugin throws an error during import', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_import_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_import_error'); }); it('should report an error if a rule is not found within a custom plugin', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_missing_rule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_missing_rule'); }); it('should report an error if a a rule is not found within a custom plugin (via overrides)', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_via_overrides_missing_rule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_via_overrides_missing_rule'); }); describe('should report an error if a custom plugin throws an error during linting', () => { it('in `create` method', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_create_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_create_error'); }); it('in `createOnce` method', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_createOnce_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_createOnce_error'); }); it('in visit function', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_visit_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_visit_error'); }); it('in `before` hook', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_before_hook_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_before_hook_error'); }); it('in `after` hook', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_after_hook_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_after_hook_error'); }); it('in `fix` function', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_lint_fix_error'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_lint_fix_error'); }); }); it('should report the correct severity when using a custom plugin', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/basic_custom_plugin_warn_severity'); - expect(exitCode).toBe(0); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('basic_custom_plugin_warn_severity'); }); it('should work with multiple rules', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/basic_custom_plugin_multiple_rules'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('basic_custom_plugin_multiple_rules'); }); it('should receive ESTree-compatible AST', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/estree'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('estree'); }); it('should receive data via `context`', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/context_properties'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('context_properties'); }); it('should support `createOnce`', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/createOnce'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('createOnce'); }); - it('should support `defineRule`', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/defineRule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + it('should support `definePlugin`', async () => { + await testFixture('definePlugin'); }); - it('should support `definePlugin`', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/definePlugin'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + it('should support `defineRule`', async () => { + await testFixture('defineRule'); }); it('should support `definePlugin` and `defineRule` together', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/definePlugin_and_defineRule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('definePlugin_and_defineRule'); }); it('should have UTF-16 spans in AST', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/utf16_offsets'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('utf16_offsets'); }); it('should respect disable directives for custom plugin rules', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/custom_plugin_disable_directives'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('custom_plugin_disable_directives'); }); it('should not apply fixes when `--fix` is disabled', async () => { - const fixtureFilePath = pathJoin(PACKAGE_ROOT_PATH, 'test/fixtures/fixes/files/index.js'); - const codeBefore = fs.readFileSync(fixtureFilePath, 'utf8'); - - let error = true; - try { - const { stdout, exitCode } = await runOxlint('test/fixtures/fixes'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); - error = false; - } finally { - const codeAfter = fs.readFileSync(fixtureFilePath, 'utf8'); - if (codeAfter !== codeBefore) { - fs.writeFileSync(fixtureFilePath, codeBefore); - // oxlint-disable-next-line no-unsafe-finally - if (!error) throw new Error('Test modified fixture file'); - } - } + await testFixture('fixes', { + snapshotName: 'fixes_disabled', + async getExtraSnapshotData(fixtureDirPath) { + const fixtureFilePath = pathJoin(fixtureDirPath, 'files/index.js'); + const codeAfter = await fs.readFile(fixtureFilePath, 'utf8'); + return { 'Code after': codeAfter }; + }, + }); }); it('should apply fixes when `--fix` is enabled', async () => { - const fixtureFilePath = pathJoin(PACKAGE_ROOT_PATH, 'test/fixtures/fixes/files/index.js'); - const codeBefore = fs.readFileSync(fixtureFilePath, 'utf8'); + const fixtureFilePath = pathJoin(FIXTURES_DIR_PATH, 'fixes/files/index.js'); + const codeBefore = await fs.readFile(fixtureFilePath, 'utf8'); - let error = true; try { - const { stdout, exitCode } = await runOxlintWithFixes('test/fixtures/fixes'); - expect(exitCode).toBe(0); - expect(normalizeOutput(stdout)).toMatchSnapshot(); - error = false; + await testFixture('fixes', { + args: ['--js-plugins', '--fix'], + snapshotName: 'fixes_enabled', + async getExtraSnapshotData() { + const codeAfter = await fs.readFile(fixtureFilePath, 'utf8'); + return { 'Code after': codeAfter }; + }, + }); } finally { - const codeAfter = fs.readFileSync(fixtureFilePath, 'utf8'); - fs.writeFileSync(fixtureFilePath, codeBefore); - if (!error) expect(codeAfter).toMatchSnapshot(); + // Revert fixture file code changes + await fs.writeFile(fixtureFilePath, codeBefore); } }); }); diff --git a/apps/oxlint/test/eslint-compat.test.ts b/apps/oxlint/test/eslint-compat.test.ts index 55c3ae9042161..ddb881be69f9b 100644 --- a/apps/oxlint/test/eslint-compat.test.ts +++ b/apps/oxlint/test/eslint-compat.test.ts @@ -1,44 +1,29 @@ -import { dirname, join as pathJoin } from 'node:path'; - -import { describe, expect, it } from 'vitest'; - -import { execa } from 'execa'; - -const PACKAGE_ROOT_PATH = dirname(import.meta.dirname); -const REPO_ROOT_PATH = pathJoin(PACKAGE_ROOT_PATH, '../..'); - -async function runEslint(cwd: string, args: string[] = []) { - return await execa('pnpx', ['eslint', ...args], { - cwd: pathJoin(PACKAGE_ROOT_PATH, cwd), - reject: false, +import { describe, it } from 'vitest'; +import { testFixtureWithCommand } from './utils.js'; + +/** + * Run ESLint on a test fixture. + * @param fixtureName - Name of the fixture directory within `test/fixtures` + */ +async function testFixture(fixtureName: string): Promise { + await testFixtureWithCommand({ + command: 'pnpx', + args: ['eslint'], + fixtureName, + snapshotName: 'eslint', }); } -function normalizeOutput(output: string): string { - const lines = output.split('\n'); - for (let i = lines.length - 1; i >= 0; i--) { - const line = lines[i]; - if (line.startsWith(REPO_ROOT_PATH)) lines[i] = `${line.slice(REPO_ROOT_PATH.length)}`; - } - return lines.join('\n'); -} - describe('ESLint compatibility', () => { - it('`defineRule` should work', async () => { - const { stdout, exitCode } = await runEslint('test/fixtures/defineRule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + it('`definePlugin` should work', async () => { + await testFixture('definePlugin'); }); - it('`definePlugin` should work', async () => { - const { stdout, exitCode } = await runEslint('test/fixtures/definePlugin'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + it('`defineRule` should work', async () => { + await testFixture('defineRule'); }); it('`definePlugin` and `defineRule` together should work', async () => { - const { stdout, exitCode } = await runEslint('test/fixtures/definePlugin_and_defineRule'); - expect(exitCode).toBe(1); - expect(normalizeOutput(stdout)).toMatchSnapshot(); + await testFixture('definePlugin_and_defineRule'); }); }); diff --git a/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_disabled.snap.md b/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_disabled.snap.md new file mode 100644 index 0000000000000..36a26c7162cb8 --- /dev/null +++ b/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_disabled.snap.md @@ -0,0 +1,10 @@ +# Exit code +1 + +# stdout +``` +Failed to parse configuration file. + + x `plugins` config contains './plugin.js'. JS plugins are not supported without `--js-plugins` CLI option. Note: JS plugin support is experimental. + +``` diff --git a/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_enabled.snap.md b/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_enabled.snap.md new file mode 100644 index 0000000000000..e22acbcb51389 --- /dev/null +++ b/apps/oxlint/test/fixtures/basic_custom_plugin/plugins_enabled.snap.md @@ -0,0 +1,22 @@ +# Exit code +1 + +# stdout +``` + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 1 warning and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/basic_custom_plugin_many_files/output.snap.md b/apps/oxlint/test/fixtures/basic_custom_plugin_many_files/output.snap.md new file mode 100644 index 0000000000000..2ae372490637a --- /dev/null +++ b/apps/oxlint/test/fixtures/basic_custom_plugin_many_files/output.snap.md @@ -0,0 +1,269 @@ +# Exit code +1 + +# stdout +``` + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/01.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/01.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/02.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/02.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/03.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/03.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/04.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/04.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/05.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/05.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/06.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/06.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/07.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/07.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/08.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/08.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/09.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/09.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/10.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/10.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/11.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/11.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/12.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/12.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/13.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/13.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/14.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/14.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/15.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/15.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/16.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/16.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/17.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/17.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/18.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/18.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/19.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/19.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/20.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/20.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 20 warnings and 20 errors. +Finished in Xms on 20 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/basic_custom_plugin_multiple_rules/output.snap.md b/apps/oxlint/test/fixtures/basic_custom_plugin_multiple_rules/output.snap.md new file mode 100644 index 0000000000000..f15ddecc06c27 --- /dev/null +++ b/apps/oxlint/test/fixtures/basic_custom_plugin_multiple_rules/output.snap.md @@ -0,0 +1,46 @@ +# Exit code +1 + +# stdout +``` + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | + `---- + + x basic-custom-plugin(no-debugger-2): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | + `---- + help: Remove the debugger statement + + x basic-custom-plugin(no-identifiers-named-foo): Unexpected Identifier named foo + ,-[files/index.js:3:1] + 2 | + 3 | foo; + : ^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used + ,-[files/index.js:3:1] + 2 | + 3 | foo; + : ^^^^ + `---- + help: Consider using this expression or removing it + +Found 2 warnings and 3 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/basic_custom_plugin_warn_severity/output.snap.md b/apps/oxlint/test/fixtures/basic_custom_plugin_warn_severity/output.snap.md new file mode 100644 index 0000000000000..22be826c4d6e9 --- /dev/null +++ b/apps/oxlint/test/fixtures/basic_custom_plugin_warn_severity/output.snap.md @@ -0,0 +1,22 @@ +# Exit code +0 + +# stdout +``` + + ! basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 2 warnings and 0 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/built_in_errors/plugins_disabled.snap.md b/apps/oxlint/test/fixtures/built_in_errors/plugins_disabled.snap.md new file mode 100644 index 0000000000000..53e4b66efc68b --- /dev/null +++ b/apps/oxlint/test/fixtures/built_in_errors/plugins_disabled.snap.md @@ -0,0 +1,16 @@ +# Exit code +1 + +# stdout +``` + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/built_in_errors/plugins_enabled.snap.md b/apps/oxlint/test/fixtures/built_in_errors/plugins_enabled.snap.md new file mode 100644 index 0000000000000..53e4b66efc68b --- /dev/null +++ b/apps/oxlint/test/fixtures/built_in_errors/plugins_enabled.snap.md @@ -0,0 +1,16 @@ +# Exit code +1 + +# stdout +``` + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/built_in_no_errors/plugins_disabled.snap.md b/apps/oxlint/test/fixtures/built_in_no_errors/plugins_disabled.snap.md new file mode 100644 index 0000000000000..91a4ebf4dc45a --- /dev/null +++ b/apps/oxlint/test/fixtures/built_in_no_errors/plugins_disabled.snap.md @@ -0,0 +1,8 @@ +# Exit code +0 + +# stdout +``` +Found 0 warnings and 0 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/built_in_no_errors/plugins_enabled.snap.md b/apps/oxlint/test/fixtures/built_in_no_errors/plugins_enabled.snap.md new file mode 100644 index 0000000000000..91a4ebf4dc45a --- /dev/null +++ b/apps/oxlint/test/fixtures/built_in_no_errors/plugins_enabled.snap.md @@ -0,0 +1,8 @@ +# Exit code +0 + +# stdout +``` +Found 0 warnings and 0 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/context_properties/output.snap.md b/apps/oxlint/test/fixtures/context_properties/output.snap.md new file mode 100644 index 0000000000000..6f2dae72959cd --- /dev/null +++ b/apps/oxlint/test/fixtures/context_properties/output.snap.md @@ -0,0 +1,45 @@ +# Exit code +1 + +# stdout +``` + + x context-plugin(log-context): id: context-plugin/log-context + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x context-plugin(log-context): filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x context-plugin(log-context): physicalFilename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x context-plugin(log-context): id: context-plugin/log-context + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x context-plugin(log-context): filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x context-plugin(log-context): physicalFilename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + +Found 0 warnings and 6 errors. +Finished in Xms on 2 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/createOnce/output.snap.md b/apps/oxlint/test/fixtures/createOnce/output.snap.md new file mode 100644 index 0000000000000..6c720b02f8e7d --- /dev/null +++ b/apps/oxlint/test/fixtures/createOnce/output.snap.md @@ -0,0 +1,261 @@ +# Exit code +1 + +# stdout +``` + + x create-once-plugin(after-only): after hook: filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(after-only): after hook: id: create-once-plugin/after-only + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: call count: 1 + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: filename: Cannot access `context.filename` in `createOnce` + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): before hook: filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): after hook: filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: id: Cannot access `context.id` in `createOnce` + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): before hook: id: create-once-plugin/always-run + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): after hook: id: create-once-plugin/always-run + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: options: Cannot access `context.options` in `createOnce` + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: physicalFilename: Cannot access `context.physicalFilename` in `createOnce` + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: report: Cannot report errors in `createOnce` + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: this === rule: true + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(before-only): before hook: filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(before-only): before hook: id: create-once-plugin/before-only + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(skip-run): before hook: filename: files/1.js + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(skip-run): before hook: id: create-once-plugin/skip-run + ,-[files/1.js:1:1] + 1 | let x; + : ^ + `---- + + x create-once-plugin(after-only): ident visit fn "x": filename: files/1.js + ,-[files/1.js:1:5] + 1 | let x; + : ^ + `---- + + x create-once-plugin(always-run): ident visit fn "x": filename: files/1.js + ,-[files/1.js:1:5] + 1 | let x; + : ^ + `---- + + x create-once-plugin(before-only): ident visit fn "x": filename: files/1.js + ,-[files/1.js:1:5] + 1 | let x; + : ^ + `---- + + x create-once-plugin(no-hooks): ident visit fn "x": filename: files/1.js + ,-[files/1.js:1:5] + 1 | let x; + : ^ + `---- + + x create-once-plugin(after-only): after hook: filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(after-only): after hook: id: create-once-plugin/after-only + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: call count: 1 + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: filename: Cannot access `context.filename` in `createOnce` + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): before hook: filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): after hook: filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: id: Cannot access `context.id` in `createOnce` + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): before hook: id: create-once-plugin/always-run + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): after hook: id: create-once-plugin/always-run + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: options: Cannot access `context.options` in `createOnce` + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: physicalFilename: Cannot access `context.physicalFilename` in `createOnce` + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: report: Cannot report errors in `createOnce` + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): createOnce: this === rule: true + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(before-only): before hook: filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(before-only): before hook: id: create-once-plugin/before-only + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(skip-run): before hook: filename: files/2.js + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(skip-run): before hook: id: create-once-plugin/skip-run + ,-[files/2.js:1:1] + 1 | let y; + : ^ + `---- + + x create-once-plugin(after-only): ident visit fn "y": filename: files/2.js + ,-[files/2.js:1:5] + 1 | let y; + : ^ + `---- + + x create-once-plugin(always-run): ident visit fn "y": filename: files/2.js + ,-[files/2.js:1:5] + 1 | let y; + : ^ + `---- + + x create-once-plugin(before-only): ident visit fn "y": filename: files/2.js + ,-[files/2.js:1:5] + 1 | let y; + : ^ + `---- + + x create-once-plugin(no-hooks): ident visit fn "y": filename: files/2.js + ,-[files/2.js:1:5] + 1 | let y; + : ^ + `---- + +Found 0 warnings and 42 errors. +Finished in Xms on 2 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_disable_directives/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_disable_directives/output.snap.md new file mode 100644 index 0000000000000..524439431657f --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_disable_directives/output.snap.md @@ -0,0 +1,48 @@ +# Exit code +1 + +# stdout +``` + + x test-plugin(no-var): Use let or const instead of var + ,-[files/index.js:1:1] + 1 | var shouldError = 1; + : ^^^^^^^^^^^^^^^^^^^^ + 2 | + `---- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:10:1] + 9 | // should trigger an error + 10 | debugger; + : ^^^^^^^^^ + 11 | + `---- + help: Remove the debugger statement + + x test-plugin(no-var): Use let or const instead of var + ,-[files/index.js:16:1] + 15 | /* oxlint-disable-next-line test-plugin */ // `test-plugin` should be `test-plugin/no-var` + 16 | var incorrectlyDisabled = 4; + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 | + `---- + + x test-plugin(no-var): Use let or const instead of var + ,-[files/index.js:19:1] + 18 | /* oxlint-disable-next-line no-var */ // `no-var` should be `test-plugin/no-var` + 19 | var anotherIncorrectlyDisabled = 4; + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 | + `---- + + x test-plugin(no-var): Use let or const instead of var + ,-[files/index.js:22:1] + 21 | // This var should trigger an error again + 22 | var shouldErrorAgain = 3; + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + +Found 0 warnings and 5 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_import_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_import_error/output.snap.md new file mode 100644 index 0000000000000..25f09cc50893a --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_import_error/output.snap.md @@ -0,0 +1,12 @@ +# Exit code +1 + +# stdout +``` +Failed to parse configuration file. + + x Failed to load JS plugin: ./plugin.js + | Error: whoops! + | at /apps/oxlint/test/fixtures/custom_plugin_import_error/plugin.js:1:7 + +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/output.snap.md new file mode 100644 index 0000000000000..115a20cb8e686 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/output.snap.md @@ -0,0 +1,14 @@ +# Exit code +1 + +# stdout +``` + + x Error running JS plugin. + | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/files/index.js + | Error: Whoops! + | at after (/apps/oxlint/test/fixtures/custom_plugin_lint_after_hook_error/plugin.js:10:19) + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/output.snap.md new file mode 100644 index 0000000000000..047b1ced1c8ab --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/output.snap.md @@ -0,0 +1,14 @@ +# Exit code +1 + +# stdout +``` + + x Error running JS plugin. + | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/files/index.js + | Error: Whoops! + | at before (/apps/oxlint/test/fixtures/custom_plugin_lint_before_hook_error/plugin.js:10:19) + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_createOnce_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_createOnce_error/output.snap.md new file mode 100644 index 0000000000000..3fd969feae4f4 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_createOnce_error/output.snap.md @@ -0,0 +1,12 @@ +# Exit code +1 + +# stdout +``` +Failed to parse configuration file. + + x Failed to load JS plugin: ./plugin.js + | Error: Whoops! + | at Object.createOnce (/apps/oxlint/test/fixtures/custom_plugin_lint_createOnce_error/plugin.js:8:15) + +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_create_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_create_error/output.snap.md new file mode 100644 index 0000000000000..4c0f763464e73 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_create_error/output.snap.md @@ -0,0 +1,14 @@ +# Exit code +1 + +# stdout +``` + + x Error running JS plugin. + | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_create_error/files/index.js + | Error: Whoops! + | at Object.create (/apps/oxlint/test/fixtures/custom_plugin_lint_create_error/plugin.js:8:15) + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/output.snap.md new file mode 100644 index 0000000000000..29928949b4b57 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/output.snap.md @@ -0,0 +1,15 @@ +# Exit code +1 + +# stdout +``` + + x Error running JS plugin. + | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/files/index.js + | Error: Whoops! + | at Object.fix (/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/plugin.js:14:23) + | at Identifier (/apps/oxlint/test/fixtures/custom_plugin_lint_fix_error/plugin.js:10:21) + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/output.snap.md new file mode 100644 index 0000000000000..a1170813ad592 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/output.snap.md @@ -0,0 +1,14 @@ +# Exit code +1 + +# stdout +``` + + x Error running JS plugin. + | File path: /apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/files/index.js + | Error: Whoops! + | at Identifier (/apps/oxlint/test/fixtures/custom_plugin_lint_visit_error/plugin.js:10:19) + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_missing_rule/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_missing_rule/output.snap.md new file mode 100644 index 0000000000000..efbc7e8cb390c --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_missing_rule/output.snap.md @@ -0,0 +1,10 @@ +# Exit code +1 + +# stdout +``` +Failed to parse configuration file. + + x Rule 'unknown-rule' not found in plugin 'basic-custom-plugin' + +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_via_overrides/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_via_overrides/output.snap.md new file mode 100644 index 0000000000000..e22acbcb51389 --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_via_overrides/output.snap.md @@ -0,0 +1,22 @@ +# Exit code +1 + +# stdout +``` + + x basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + +Found 1 warning and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/custom_plugin_via_overrides_missing_rule/output.snap.md b/apps/oxlint/test/fixtures/custom_plugin_via_overrides_missing_rule/output.snap.md new file mode 100644 index 0000000000000..57597c500bc9f --- /dev/null +++ b/apps/oxlint/test/fixtures/custom_plugin_via_overrides_missing_rule/output.snap.md @@ -0,0 +1,10 @@ +# Exit code +1 + +# stdout +``` +Failed to build configuration. + + x Rule 'missing' not found in plugin 'basic-custom-plugin' + +``` diff --git a/apps/oxlint/test/fixtures/definePlugin/eslint.snap.md b/apps/oxlint/test/fixtures/definePlugin/eslint.snap.md new file mode 100644 index 0000000000000..028d9052a303d --- /dev/null +++ b/apps/oxlint/test/fixtures/definePlugin/eslint.snap.md @@ -0,0 +1,93 @@ +# Exit code +1 + +# stdout +``` + +/apps/oxlint/test/fixtures/definePlugin/files/1.js + 0:1 error create body: +this === rule: true define-plugin-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/1.js define-plugin-plugin/create-once + 0:1 error before hook: +filename: files/1.js define-plugin-plugin/create-once-before-false + 0:1 error before hook: +filename: files/1.js define-plugin-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/1.js define-plugin-plugin/create-once + 0:1 error after hook: +filename: files/1.js define-plugin-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-plugin/create + 1:5 error ident visit fn "a": +identNum: 1 +filename: files/1.js define-plugin-plugin/create-once + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-plugin/create-once-before-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-plugin/create-once-no-hooks + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-plugin/create + 1:8 error ident visit fn "b": +identNum: 2 +filename: files/1.js define-plugin-plugin/create-once + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-plugin/create-once-before-only + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-plugin/create-once-after-only + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-plugin/create-once-no-hooks + +/apps/oxlint/test/fixtures/definePlugin/files/2.js + 0:1 error create body: +this === rule: true define-plugin-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/2.js define-plugin-plugin/create-once + 0:1 error before hook: +filename: files/2.js define-plugin-plugin/create-once-before-false + 0:1 error before hook: +filename: files/2.js define-plugin-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/2.js define-plugin-plugin/create-once + 0:1 error after hook: +filename: files/2.js define-plugin-plugin/create-once-before-false + 0:1 error after hook: +filename: files/2.js define-plugin-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-plugin/create + 1:5 error ident visit fn "c": +identNum: 1 +filename: files/2.js define-plugin-plugin/create-once + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-plugin/create-once-before-false + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-plugin/create-once-before-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-plugin/create-once-no-hooks + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-plugin/create + 1:8 error ident visit fn "d": +identNum: 2 +filename: files/2.js define-plugin-plugin/create-once + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-plugin/create-once-before-false + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-plugin/create-once-before-only + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-plugin/create-once-after-only + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-plugin/create-once-no-hooks + +✖ 35 problems (35 errors, 0 warnings) + +``` diff --git a/apps/oxlint/test/fixtures/definePlugin/output.snap.md b/apps/oxlint/test/fixtures/definePlugin/output.snap.md new file mode 100644 index 0000000000000..c14537712ab38 --- /dev/null +++ b/apps/oxlint/test/fixtures/definePlugin/output.snap.md @@ -0,0 +1,264 @@ +# Exit code +1 + +# stdout +``` + + x define-plugin-plugin(create): create body: + | this === rule: true + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once): after hook: + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): after hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-before-false): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once): ident visit fn "a": + | identNum: 1 + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-no-hooks): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once): ident visit fn "b": + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create-once-no-hooks): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-plugin(create): create body: + | this === rule: true + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once): after hook: + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-false): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-false): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once): ident visit fn "c": + | identNum: 1 + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-false): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-no-hooks): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once): ident visit fn "d": + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-after-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-false): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-before-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-plugin(create-once-no-hooks): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + +Found 0 warnings and 35 errors. +Finished in Xms on 2 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/definePlugin_and_defineRule/eslint.snap.md b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/eslint.snap.md new file mode 100644 index 0000000000000..15d1ffac9e55e --- /dev/null +++ b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/eslint.snap.md @@ -0,0 +1,93 @@ +# Exit code +1 + +# stdout +``` + +/apps/oxlint/test/fixtures/definePlugin_and_defineRule/files/1.js + 0:1 error create body: +this === rule: true define-plugin-and-rule-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/1.js define-plugin-and-rule-plugin/create-once + 0:1 error before hook: +filename: files/1.js define-plugin-and-rule-plugin/create-once-before-false + 0:1 error before hook: +filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/1.js define-plugin-and-rule-plugin/create-once + 0:1 error after hook: +filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-and-rule-plugin/create + 1:5 error ident visit fn "a": +identNum: 1 +filename: files/1.js define-plugin-and-rule-plugin/create-once + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-plugin-and-rule-plugin/create-once-no-hooks + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-and-rule-plugin/create + 1:8 error ident visit fn "b": +identNum: 2 +filename: files/1.js define-plugin-and-rule-plugin/create-once + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-and-rule-plugin/create-once-before-only + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-and-rule-plugin/create-once-after-only + 1:8 error ident visit fn "b": +filename: files/1.js define-plugin-and-rule-plugin/create-once-no-hooks + +/apps/oxlint/test/fixtures/definePlugin_and_defineRule/files/2.js + 0:1 error create body: +this === rule: true define-plugin-and-rule-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/2.js define-plugin-and-rule-plugin/create-once + 0:1 error before hook: +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false + 0:1 error before hook: +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/2.js define-plugin-and-rule-plugin/create-once + 0:1 error after hook: +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false + 0:1 error after hook: +filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-and-rule-plugin/create + 1:5 error ident visit fn "c": +identNum: 1 +filename: files/2.js define-plugin-and-rule-plugin/create-once + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-plugin-and-rule-plugin/create-once-no-hooks + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-and-rule-plugin/create + 1:8 error ident visit fn "d": +identNum: 2 +filename: files/2.js define-plugin-and-rule-plugin/create-once + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-false + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-and-rule-plugin/create-once-before-only + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-and-rule-plugin/create-once-after-only + 1:8 error ident visit fn "d": +filename: files/2.js define-plugin-and-rule-plugin/create-once-no-hooks + +✖ 35 problems (35 errors, 0 warnings) + +``` diff --git a/apps/oxlint/test/fixtures/definePlugin_and_defineRule/output.snap.md b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/output.snap.md new file mode 100644 index 0000000000000..9ccba849ab270 --- /dev/null +++ b/apps/oxlint/test/fixtures/definePlugin_and_defineRule/output.snap.md @@ -0,0 +1,264 @@ +# Exit code +1 + +# stdout +``` + + x define-plugin-and-rule-plugin(create): create body: + | this === rule: true + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): after hook: + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): after hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-false): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): ident visit fn "a": + | identNum: 1 + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): ident visit fn "b": + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-plugin-and-rule-plugin(create): create body: + | this === rule: true + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): after hook: + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-false): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-false): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): ident visit fn "c": + | identNum: 1 + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-false): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once): ident visit fn "d": + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-after-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-false): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-before-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-plugin-and-rule-plugin(create-once-no-hooks): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + +Found 0 warnings and 35 errors. +Finished in Xms on 2 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/defineRule/eslint.snap.md b/apps/oxlint/test/fixtures/defineRule/eslint.snap.md new file mode 100644 index 0000000000000..1c85cf9e2d49e --- /dev/null +++ b/apps/oxlint/test/fixtures/defineRule/eslint.snap.md @@ -0,0 +1,93 @@ +# Exit code +1 + +# stdout +``` + +/apps/oxlint/test/fixtures/defineRule/files/1.js + 0:1 error create body: +this === rule: true define-rule-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/1.js define-rule-plugin/create-once + 0:1 error before hook: +filename: files/1.js define-rule-plugin/create-once-before-false + 0:1 error before hook: +filename: files/1.js define-rule-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/1.js define-rule-plugin/create-once + 0:1 error after hook: +filename: files/1.js define-rule-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-rule-plugin/create + 1:5 error ident visit fn "a": +identNum: 1 +filename: files/1.js define-rule-plugin/create-once + 1:5 error ident visit fn "a": +filename: files/1.js define-rule-plugin/create-once-before-only + 1:5 error ident visit fn "a": +filename: files/1.js define-rule-plugin/create-once-after-only + 1:5 error ident visit fn "a": +filename: files/1.js define-rule-plugin/create-once-no-hooks + 1:8 error ident visit fn "b": +filename: files/1.js define-rule-plugin/create + 1:8 error ident visit fn "b": +identNum: 2 +filename: files/1.js define-rule-plugin/create-once + 1:8 error ident visit fn "b": +filename: files/1.js define-rule-plugin/create-once-before-only + 1:8 error ident visit fn "b": +filename: files/1.js define-rule-plugin/create-once-after-only + 1:8 error ident visit fn "b": +filename: files/1.js define-rule-plugin/create-once-no-hooks + +/apps/oxlint/test/fixtures/defineRule/files/2.js + 0:1 error create body: +this === rule: true define-rule-plugin/create + 0:1 error before hook: +createOnce call count: 1 +this === rule: true +filename: files/2.js define-rule-plugin/create-once + 0:1 error before hook: +filename: files/2.js define-rule-plugin/create-once-before-false + 0:1 error before hook: +filename: files/2.js define-rule-plugin/create-once-before-only + 0:1 error after hook: +identNum: 2 +filename: files/2.js define-rule-plugin/create-once + 0:1 error after hook: +filename: files/2.js define-rule-plugin/create-once-before-false + 0:1 error after hook: +filename: files/2.js define-rule-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-rule-plugin/create + 1:5 error ident visit fn "c": +identNum: 1 +filename: files/2.js define-rule-plugin/create-once + 1:5 error ident visit fn "c": +filename: files/2.js define-rule-plugin/create-once-before-false + 1:5 error ident visit fn "c": +filename: files/2.js define-rule-plugin/create-once-before-only + 1:5 error ident visit fn "c": +filename: files/2.js define-rule-plugin/create-once-after-only + 1:5 error ident visit fn "c": +filename: files/2.js define-rule-plugin/create-once-no-hooks + 1:8 error ident visit fn "d": +filename: files/2.js define-rule-plugin/create + 1:8 error ident visit fn "d": +identNum: 2 +filename: files/2.js define-rule-plugin/create-once + 1:8 error ident visit fn "d": +filename: files/2.js define-rule-plugin/create-once-before-false + 1:8 error ident visit fn "d": +filename: files/2.js define-rule-plugin/create-once-before-only + 1:8 error ident visit fn "d": +filename: files/2.js define-rule-plugin/create-once-after-only + 1:8 error ident visit fn "d": +filename: files/2.js define-rule-plugin/create-once-no-hooks + +✖ 35 problems (35 errors, 0 warnings) + +``` diff --git a/apps/oxlint/test/fixtures/defineRule/output.snap.md b/apps/oxlint/test/fixtures/defineRule/output.snap.md new file mode 100644 index 0000000000000..ad3520f880f50 --- /dev/null +++ b/apps/oxlint/test/fixtures/defineRule/output.snap.md @@ -0,0 +1,264 @@ +# Exit code +1 + +# stdout +``` + + x define-rule-plugin(create): create body: + | this === rule: true + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once): after hook: + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): after hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-before-false): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): before hook: + | filename: files/1.js + ,-[files/1.js:1:1] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once): ident visit fn "a": + | identNum: 1 + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-no-hooks): ident visit fn "a": + | filename: files/1.js + ,-[files/1.js:1:5] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once): ident visit fn "b": + | identNum: 2 + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create-once-no-hooks): ident visit fn "b": + | filename: files/1.js + ,-[files/1.js:1:8] + 1 | let a, b; + : ^ + `---- + + x define-rule-plugin(create): create body: + | this === rule: true + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once): before hook: + | createOnce call count: 1 + | this === rule: true + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once): after hook: + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-false): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-false): after hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): before hook: + | filename: files/2.js + ,-[files/2.js:1:1] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once): ident visit fn "c": + | identNum: 1 + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-false): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-no-hooks): ident visit fn "c": + | filename: files/2.js + ,-[files/2.js:1:5] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once): ident visit fn "d": + | identNum: 2 + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-after-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-false): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-before-only): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + + x define-rule-plugin(create-once-no-hooks): ident visit fn "d": + | filename: files/2.js + ,-[files/2.js:1:8] + 1 | let c, d; + : ^ + `---- + +Found 0 warnings and 35 errors. +Finished in Xms on 2 files using X threads. +``` diff --git a/apps/oxlint/test/fixtures/estree/output.snap.md b/apps/oxlint/test/fixtures/estree/output.snap.md new file mode 100644 index 0000000000000..93eeea64a91cd --- /dev/null +++ b/apps/oxlint/test/fixtures/estree/output.snap.md @@ -0,0 +1,53 @@ +# Exit code +1 + +# stdout +``` + + x estree-check(check): Visited nodes: + | * Program + | * VariableDeclaration: let + | * VariableDeclarator: (init: ObjectExpression) + | * Identifier: a + | * ObjectExpression + | * Identifier: x + | * Identifier: y + | * VariableDeclaration:exit: let + | * VariableDeclaration: const + | * VariableDeclarator: (init: BinaryExpression) + | * Identifier: b + | * BinaryExpression: * (right: BinaryExpression) + | * Identifier: x + | * BinaryExpression: + (right: Literal) + | * Literal: str + | * Literal: 123 + | * VariableDeclaration:exit: const + | * TSTypeAliasDeclaration: (typeAnnotation: TSStringKeyword) + | * Identifier: T + | * TSStringKeyword + | * TSTypeAliasDeclaration:exit: (typeAnnotation: TSStringKeyword) + | * TSTypeAliasDeclaration: (typeAnnotation: TSUnionType) + | * Identifier: U + | * TSUnionType: (types: TSStringKeyword, TSNumberKeyword) + | * TSStringKeyword + | * TSNumberKeyword + | * TSUnionType:exit: (types: TSStringKeyword, TSNumberKeyword) + | * TSTypeAliasDeclaration:exit: (typeAnnotation: TSUnionType) + | * Program:exit + ,-[files/index.ts:2:1] + 1 | // All `Identifier`s + 2 | ,-> let a = { x: y }; + 3 | | + 4 | | // No `ParenthesizedExpression`s in AST + 5 | | const b = (x * ((('str' + ((123)))))); + 6 | | + 7 | | // TS syntax + 8 | | type T = string; + 9 | | + 10 | | // No `TSParenthesizedType`s in AST + 11 | `-> type U = (((((string)) | ((number))))); + `---- + +Found 0 warnings and 1 error. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/fixes/fixes_disabled.snap.md b/apps/oxlint/test/fixtures/fixes/fixes_disabled.snap.md new file mode 100644 index 0000000000000..f52e1a3fe957d --- /dev/null +++ b/apps/oxlint/test/fixtures/fixes/fixes_disabled.snap.md @@ -0,0 +1,122 @@ +# Exit code +1 + +# stdout +``` + + x fixes-plugin(fixes): Remove debugger statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | + `---- + + x fixes-plugin(fixes): Replace "a" with "daddy" + ,-[files/index.js:3:5] + 2 | + 3 | let a = 1; + : ^ + 4 | let b = 2; + `---- + + x fixes-plugin(fixes): Replace "b" with "abacus" + ,-[files/index.js:4:5] + 3 | let a = 1; + 4 | let b = 2; + : ^ + 5 | let c = 3; + `---- + + x fixes-plugin(fixes): Prefix "c" with "magi" + ,-[files/index.js:5:5] + 4 | let b = 2; + 5 | let c = 3; + : ^ + 6 | let d = 4; + `---- + + x fixes-plugin(fixes): Prefix "d" with "damne" + ,-[files/index.js:6:5] + 5 | let c = 3; + 6 | let d = 4; + : ^ + 7 | let e = 5; + `---- + + x fixes-plugin(fixes): Postfix "e" with "lephant" + ,-[files/index.js:7:5] + 6 | let d = 4; + 7 | let e = 5; + : ^ + 8 | let f = 6; + `---- + + x fixes-plugin(fixes): Postfix "f" with "eck" + ,-[files/index.js:8:5] + 7 | let e = 5; + 8 | let f = 6; + : ^ + 9 | let g = 7; + `---- + + x fixes-plugin(fixes): Replace "g" with "numpty" + ,-[files/index.js:9:5] + 8 | let f = 6; + 9 | let g = 7; + : ^ + 10 | let h = 8; + `---- + + x fixes-plugin(fixes): Replace "h" with "dangermouse" + ,-[files/index.js:10:5] + 9 | let g = 7; + 10 | let h = 8; + : ^ + 11 | let i = 9; + `---- + + x fixes-plugin(fixes): Replace "i" with "granular" + ,-[files/index.js:11:5] + 10 | let h = 8; + 11 | let i = 9; + : ^ + 12 | let j = 10; + `---- + + x fixes-plugin(fixes): Replace "j" with "cowabunga" + ,-[files/index.js:12:5] + 11 | let i = 9; + 12 | let j = 10; + : ^ + 13 | + `---- + + x fixes-plugin(fixes): Remove debugger statement + ,-[files/index.js:14:1] + 13 | + 14 | debugger; + : ^^^^^^^^^ + `---- + +Found 0 warnings and 12 errors. +Finished in Xms on 1 file using X threads. +``` + +# Code after +``` +debugger; + +let a = 1; +let b = 2; +let c = 3; +let d = 4; +let e = 5; +let f = 6; +let g = 7; +let h = 8; +let i = 9; +let j = 10; + +debugger; + +``` diff --git a/apps/oxlint/test/fixtures/fixes/fixes_enabled.snap.md b/apps/oxlint/test/fixtures/fixes/fixes_enabled.snap.md new file mode 100644 index 0000000000000..89aca76902ca4 --- /dev/null +++ b/apps/oxlint/test/fixtures/fixes/fixes_enabled.snap.md @@ -0,0 +1,27 @@ +# Exit code +0 + +# stdout +``` +Found 0 warnings and 0 errors. +Finished in Xms on 1 file using X threads. +``` + +# Code after +``` + + +let daddy = 1; +let abacus = 2; +let magic = 3; +let damned = 4; +let elephant = 5; +let feck = 6; +let numpty = 7; +let dangermouse = 8; +let granular = 9; +let cowabunga = 10; + + + +``` diff --git a/apps/oxlint/test/fixtures/load_paths/output.snap.md b/apps/oxlint/test/fixtures/load_paths/output.snap.md new file mode 100644 index 0000000000000..d9a84c975b4f1 --- /dev/null +++ b/apps/oxlint/test/fixtures/load_paths/output.snap.md @@ -0,0 +1,52 @@ +# Exit code +1 + +# stdout +``` + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + help: Remove the debugger statement + + x plugin1(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + x plugin2(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + x plugin3(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + x plugin4(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + x plugin5(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + + x plugin6(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + +Found 1 warning and 6 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/fixtures/missing_custom_plugin/output.snap.md b/apps/oxlint/test/fixtures/missing_custom_plugin/output.snap.md new file mode 100644 index 0000000000000..e6439ae8abe4c --- /dev/null +++ b/apps/oxlint/test/fixtures/missing_custom_plugin/output.snap.md @@ -0,0 +1,11 @@ +# Exit code +1 + +# stdout +``` +Failed to parse configuration file. + + x Failed to load JS plugin: ./plugin.js + | Cannot find module './plugin.js' + +``` diff --git a/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md b/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md new file mode 100644 index 0000000000000..5c9773521ce57 --- /dev/null +++ b/apps/oxlint/test/fixtures/utf16_offsets/output.snap.md @@ -0,0 +1,58 @@ +# Exit code +1 + +# stdout +``` + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | // £ + `---- + help: Remove the debugger statement + + x utf16-plugin(no-debugger): Debugger at 0-9 + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + 2 | // £ + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:3:1] + 2 | // £ + 3 | debugger; + : ^^^^^^^^^ + 4 | // 🤨 + `---- + help: Remove the debugger statement + + x utf16-plugin(no-debugger): Debugger at 15-24 + ,-[files/index.js:3:1] + 2 | // £ + 3 | debugger; + : ^^^^^^^^^ + 4 | // 🤨 + `---- + + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[files/index.js:6:3] + 5 | { + 6 | debugger; + : ^^^^^^^^^ + 7 | } + `---- + help: Remove the debugger statement + + x utf16-plugin(no-debugger): Debugger at 35-44 + ,-[files/index.js:6:3] + 5 | { + 6 | debugger; + : ^^^^^^^^^ + 7 | } + `---- + +Found 3 warnings and 3 errors. +Finished in Xms on 1 file using X threads. +``` diff --git a/apps/oxlint/test/utils.ts b/apps/oxlint/test/utils.ts new file mode 100644 index 0000000000000..1ec3ee2c64381 --- /dev/null +++ b/apps/oxlint/test/utils.ts @@ -0,0 +1,106 @@ +import fs from 'node:fs/promises'; +import { join as pathJoin } from 'node:path'; + +import { execa } from 'execa'; +import { expect } from 'vitest'; + +export const PACKAGE_ROOT_PATH = pathJoin(import.meta.dirname, '..'); +export const FIXTURES_DIR_PATH = pathJoin(import.meta.dirname, 'fixtures'); + +const REPO_ROOT_PATH = pathJoin(PACKAGE_ROOT_PATH, '../../'); +const ROOT_URL = new URL('../../../', import.meta.url).href; +const FIXTURES_URL = new URL('./fixtures/', import.meta.url).href; + +// Options to pass to `testFixtureWithCommand`. +interface TestFixtureOptions { + // Command + command: string; + // Arguments to execute command with + args: string[]; + // Fixture name + fixtureName: string; + // Name of the snapshot file + snapshotName: string; + // Function to get extra data to include in the snapshot + getExtraSnapshotData?: (dirPath: string) => Promise<{ [key: string]: string }>; +} + +/** + * Run a test fixture. + * @param options - Options for running the test + */ +export async function testFixtureWithCommand(options: TestFixtureOptions): Promise { + const fixtureDirPath = pathJoin(FIXTURES_DIR_PATH, options.fixtureName); + + const { stdout, exitCode } = await execa(options.command, options.args, { + cwd: fixtureDirPath, + reject: false, + }); + + const snapshotPath = pathJoin(fixtureDirPath, `${options.snapshotName}.snap.md`); + + const output = normalizeStdout(stdout); + let snapshot = `# Exit code\n${exitCode}\n\n# stdout\n\`\`\`\n${output}\n\`\`\`\n`; + + if (options.getExtraSnapshotData) { + const extraSnapshots = await options.getExtraSnapshotData(fixtureDirPath); + for (const [name, data] of Object.entries(extraSnapshots)) { + snapshot += `\n# ${name}\n\`\`\`\n${data}\n\`\`\`\n`; + } + } + + let expectedSnapshot = null; + try { + expectedSnapshot = await fs.readFile(snapshotPath, 'utf8'); + } catch (err) { + if (err?.code !== 'ENOENT') throw err; + } + + if (snapshot !== expectedSnapshot) { + await fs.writeFile(snapshotPath, snapshot); + if (expectedSnapshot !== null) expect(snapshot).toBe(expectedSnapshot); + } +} + +/** + * Normalize output, so it's the same on every machine. + * + * - Remove timing + thread count info. + * - Replace start of file paths with ``. + * - Remove irrelevant lines from stack traces. + * + * @param stdout Output from process + * @returns Normalized output + */ +function normalizeStdout(stdout: string): string { + let lines = stdout.split('\n'); + + // Remove timing and thread count info which can vary between runs + lines[lines.length - 1] = lines[lines.length - 1].replace( + /^Finished in \d+(?:\.\d+)?(?:s|ms|us|ns) on (\d+) file(s?) using \d+ threads.$/, + 'Finished in Xms on $1 file$2 using X threads.', + ); + + // Remove lines from stack traces which are outside `fixtures` directory. + // Replace path to repo root in stack traces with ``. + lines = lines.flatMap((line) => { + // e.g. ` | at file:///path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js:1:1` + // e.g. ` | at whatever (file:///path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js:1:1)` + let match = line.match(/^(\s*\|\s+at (?:.+?\()?)(.+)$/); + if (match) { + const [, preamble, at] = match; + return at.startsWith(FIXTURES_URL) ? [`${preamble}/${at.slice(ROOT_URL.length)}`] : []; + } else { + // e.g. ` | File path: /path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js` + match = line.match(/^(\s*\|\s+File path: )(.+)$/); + if (match) { + const [, preamble, path] = match; + if (path.startsWith(REPO_ROOT_PATH)) return [`${preamble}/${path.slice(REPO_ROOT_PATH.length)}`]; + } + } + if (line.startsWith(REPO_ROOT_PATH)) line = `/${line.slice(REPO_ROOT_PATH.length)}`; + return [line]; + }); + + return lines.join('\n'); +}