Files
Huáng JùnliàngandGitHub f1f5f9d97c refactor(ts): migrate babel-eslint-plugin-* to TS (#17950)
* refactor(ts): convert eslint-plugin

* refactor(ts): convert esling-plugin-development

* refactor(ts): convert eslint-plugin-development-internal

* make ts happy

* fix default rules config
2026-04-30 19:42:39 -04:00

61 lines
1.9 KiB
JavaScript

import plugin from "../../lib/index.js";
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester.js";
const rule = plugin.rules["plugin-name"];
const missingPluginError = "This file does not export a Babel plugin.";
const missingNameError = "This Babel plugin doesn't have a 'name' property.";
const ruleTester = new RuleTester();
ruleTester.run("plugin-name", rule, {
valid: [
`export default function () { return { name: "test-plugin" } }`,
`import { declare } from "@babel/helper-plugin-utils"; declare(() => { return { name: "test-plugin" } })`,
`import { declare } from "@babel/helper-plugin-utils"; declare(() => ({ name: "test-plugin" }))`,
`module.exports = function () { return { name: "foo" }; }`,
],
invalid: [
{
code: `function fn() { return { name: "foo" } }`,
errors: [missingPluginError],
},
{
code: `export function fn() { return { name: "foo" } }`,
errors: [missingPluginError],
},
{
code: `(function fn() { return { name: "foo" } })`,
errors: [missingPluginError],
},
{
code: `() => { return { name: "foo" } }`,
errors: [missingPluginError],
},
{
code: `export default function fn() {}`,
errors: [missingPluginError],
},
{
code: `var exports = 0; module[exports] = function notAnExport() { return { name: "foo" }; }`,
errors: [missingPluginError],
},
{
code: `export default function fn() { return {} }`,
errors: [missingNameError],
},
{
code: `export default function fn() { return { ...oldPlugin } }`,
errors: [missingNameError],
},
{
code: `import { declare } from "@babel/helper-plugin-utils"; declare(() => ({}))`,
errors: [missingNameError],
},
{
code: `module.exports = function () { return {} }`,
errors: [missingNameError],
},
],
});