-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathno_sync_import_from_plugin.test.js
More file actions
95 lines (90 loc) · 2.32 KB
/
no_sync_import_from_plugin.test.js
File metadata and controls
95 lines (90 loc) · 2.32 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
const { RuleTester } = require('eslint');
const rule = require('./no_sync_import_from_plugin');
const dedent = require('dedent');
const ruleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
});
const ERR = { messageId: 'noSyncImportFromPlugin' };
ruleTester.run('@kbn/eslint/no_sync_import_from_plugin', rule, {
valid: [
{
code: dedent`
import type { PluginInitializerContext } from '@kbn/core/server';
import type { MyPluginSetup } from './plugin';
export const plugin = async (ctx: PluginInitializerContext) => {
const { MyPlugin } = await import('./plugin');
return new MyPlugin(ctx);
};
`,
},
{
code: dedent`
import { config } from './config';
export const plugin = async () => {
const { Plugin } = await import('./plugin');
return new Plugin();
};
export { config };
`,
},
{
code: dedent`
export type { FooSetup } from './plugin';
`,
},
{
code: dedent`
import type { Foo } from './other';
`,
},
{
code: dedent`
const m = await import('./plugin');
`,
},
],
invalid: [
{
code: `import { FooPlugin } from './plugin';`,
errors: [ERR],
},
{
code: dedent`
import type { Setup } from './plugin';
import { FooPlugin } from './plugin';
`,
errors: [ERR],
},
{
code: `import './plugin';`,
errors: [ERR],
},
{
code: `export { FooPlugin } from './plugin';`,
errors: [ERR],
},
{
code: `export * from './plugin';`,
errors: [ERR],
},
{
code: `require('./plugin');`,
errors: [ERR],
},
],
});