mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* 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
61 lines
1.9 KiB
JavaScript
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],
|
|
},
|
|
],
|
|
});
|