fix(lint): Deno.lint.runPlugin throws in deno run (#28063)

This commit changes `Deno.lint.runPlugin` to throw
in non-`deno test` subcommand, instead of returning
`undefined`.
This commit is contained in:
Bartek Iwańczuk 2025-02-12 10:18:55 +01:00 committed by GitHub
parent 3ff9ca2533
commit d29f9f99dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 2 deletions

View file

@ -1487,7 +1487,9 @@ declare namespace Deno {
}
/**
* This API is a noop in `deno run`...
* This API is useful for testing lint plugins.
*
* It throws an error if it's not used in `deno test` subcommand.
* @category Linter
* @experimental
*/

View file

@ -585,7 +585,11 @@ const finalDenoNs = {
test: () => {},
bench: () => {},
lint: {
runPlugin: () => {},
runPlugin: () => {
throw new Error(
"`Deno.lint.runPlugin` is only available in `deno test` subcommand.",
);
},
},
};

View file

@ -0,0 +1,13 @@
{
"steps": [
{
"args": "run main.ts",
"output": "run.out",
"exitCode": 1
},
{
"args": "test main.ts",
"output": "test.out"
}
]
}

View file

@ -0,0 +1,12 @@
const plugin = {
name: "test-plugin",
rules: {
testRule: {
create() {
return {};
},
},
},
};
Deno.lint.runPlugin(plugin, "source.ts", "export default {}");

View file

@ -0,0 +1,5 @@
error: Uncaught (in promise) Error: `Deno.lint.runPlugin` is only available in `deno test` subcommand.
Deno.lint.runPlugin(plugin, "source.ts", "export default {}");
^
at Object.runPlugin ([WILDCARD])
at [WILDCARD]main.ts:12:11

View file

@ -0,0 +1,5 @@
Check [WILDCARD]main.ts
running 0 tests from ./main.ts
ok | 0 passed | 0 failed [WILDCARD]