/
plugin-name.js
50 lines (47 loc) 路 1.57 KB
/
plugin-name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import rule from "../../lib/rules/plugin-name.cjs";
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester.js";
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: `export default function fn() { return {} }`,
errors: [missingNameError],
},
{
code: `import { declare } from "@babel/helper-plugin-utils"; declare(() => ({}))`,
errors: [missingNameError],
},
{
code: `module.exports = function () { return {} }`,
errors: [missingNameError],
},
],
});