-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathno-svelte-internal.ts
59 lines (56 loc) · 1.36 KB
/
no-svelte-internal.ts
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
import { createRule } from '../utils';
import type { TSESTree } from '@typescript-eslint/types';
export default createRule('no-svelte-internal', {
meta: {
docs: {
description: 'svelte/internal will be removed in Svelte 6.',
category: 'Best Practices',
// TODO Switch to recommended in the major version.
// recommended: true,
recommended: false
},
schema: [],
messages: {
unexpected: 'Using svelte/internal is prohibited. This will be removed in Svelte 6.'
},
type: 'problem'
},
create(context) {
function report(node: TSESTree.Node) {
context.report({
node,
messageId: 'unexpected'
});
}
function isSvelteInternal(value: string) {
return value === 'svelte/internal' || value.startsWith('svelte/internal/');
}
return {
ImportDeclaration(node) {
if (node.source && isSvelteInternal(node.source.value)) {
report(node);
}
},
ImportExpression(node) {
if (
node.source &&
node.source.type === 'Literal' &&
typeof node.source.value === 'string' &&
isSvelteInternal(node.source.value)
) {
report(node);
}
},
ExportNamedDeclaration(node) {
if (node.source && isSvelteInternal(node.source.value)) {
report(node);
}
},
ExportAllDeclaration(node) {
if (node.source && isSvelteInternal(node.source.value)) {
report(node);
}
}
};
}
});