From 9213215d6df8944509737d074df82ecb072306da Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 6 Feb 2025 14:04:04 +0100 Subject: [PATCH] feat(unstable): add test for lint plugin destroy hook (#27981) Noticed that we didn't test the `destroy()` hook of lint plugins. This PR adds a test for that. --- .../lint/lint_plugin_lifecycle/__test__.jsonc | 8 +++++++ tests/specs/lint/lint_plugin_lifecycle/a.ts | 1 + .../lint/lint_plugin_lifecycle/deno.json | 5 ++++ .../specs/lint/lint_plugin_lifecycle/lint.out | 5 ++++ .../lint/lint_plugin_lifecycle/plugin.ts | 23 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 tests/specs/lint/lint_plugin_lifecycle/__test__.jsonc create mode 100644 tests/specs/lint/lint_plugin_lifecycle/a.ts create mode 100644 tests/specs/lint/lint_plugin_lifecycle/deno.json create mode 100644 tests/specs/lint/lint_plugin_lifecycle/lint.out create mode 100644 tests/specs/lint/lint_plugin_lifecycle/plugin.ts diff --git a/tests/specs/lint/lint_plugin_lifecycle/__test__.jsonc b/tests/specs/lint/lint_plugin_lifecycle/__test__.jsonc new file mode 100644 index 00000000000000..6e5dd5713bfd35 --- /dev/null +++ b/tests/specs/lint/lint_plugin_lifecycle/__test__.jsonc @@ -0,0 +1,8 @@ +{ + "steps": [ + { + "args": "lint a.ts", + "output": "lint.out" + } + ] +} diff --git a/tests/specs/lint/lint_plugin_lifecycle/a.ts b/tests/specs/lint/lint_plugin_lifecycle/a.ts new file mode 100644 index 00000000000000..0366a968a76b74 --- /dev/null +++ b/tests/specs/lint/lint_plugin_lifecycle/a.ts @@ -0,0 +1 @@ +const _a = "foo"; diff --git a/tests/specs/lint/lint_plugin_lifecycle/deno.json b/tests/specs/lint/lint_plugin_lifecycle/deno.json new file mode 100644 index 00000000000000..57b9dcb3647975 --- /dev/null +++ b/tests/specs/lint/lint_plugin_lifecycle/deno.json @@ -0,0 +1,5 @@ +{ + "lint": { + "plugins": ["./plugin.ts"] + } +} diff --git a/tests/specs/lint/lint_plugin_lifecycle/lint.out b/tests/specs/lint/lint_plugin_lifecycle/lint.out new file mode 100644 index 00000000000000..f3d079a57f0823 --- /dev/null +++ b/tests/specs/lint/lint_plugin_lifecycle/lint.out @@ -0,0 +1,5 @@ +create: test-plugin/my-rule +create: test-plugin/my-rule-2 +destroy: test-plugin/my-rule +destroy: test-plugin/my-rule-2 +Checked 1 file diff --git a/tests/specs/lint/lint_plugin_lifecycle/plugin.ts b/tests/specs/lint/lint_plugin_lifecycle/plugin.ts new file mode 100644 index 00000000000000..e76cdd00b127f5 --- /dev/null +++ b/tests/specs/lint/lint_plugin_lifecycle/plugin.ts @@ -0,0 +1,23 @@ +export default { + name: "test-plugin", + rules: { + "my-rule": { + create(ctx) { + console.log(`create: ${ctx.id}`); + return {}; + }, + destroy(ctx) { + console.log(`destroy: ${ctx.id}`); + }, + }, + "my-rule-2": { + create(ctx) { + console.log(`create: ${ctx.id}`); + return {}; + }, + destroy(ctx) { + console.log(`destroy: ${ctx.id}`); + }, + }, + }, +};