-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathno-export-load-in-svelte-module-in-kit-pages.ts
52 lines (49 loc) · 1.42 KB
/
no-export-load-in-svelte-module-in-kit-pages.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
import type { TSESTree } from '@typescript-eslint/types';
import { createRule } from '../utils/index.js';
export default createRule('no-export-load-in-svelte-module-in-kit-pages', {
meta: {
docs: {
description:
'disallow exporting load functions in `*.svelte` module in SvelteKit page components.',
category: 'Possible Errors',
// TODO Switch to recommended in the major version.
recommended: false
},
schema: [],
messages: {
unexpected:
'disallow exporting load functions in `*.svelte` module in SvelteKit page components.'
},
type: 'problem',
conditions: [
{
svelteKitFileTypes: ['+page.svelte', '+error.svelte', '+layout.svelte']
}
]
},
create(context) {
let isModule = false;
return {
// <script context="module">
[`Program > SvelteScriptElement > SvelteStartTag > SvelteAttribute[key.name="context"] > SvelteLiteral[value="module"]`]:
() => {
isModule = true;
},
// </script>
'Program > SvelteScriptElement:exit': () => {
isModule = false;
},
// export function load() {}
// export const load = () => {}
[`:matches(ExportNamedDeclaration > FunctionDeclaration, ExportNamedDeclaration > VariableDeclaration > VariableDeclarator) > Identifier.id[name="load"]`]:
(node: TSESTree.Identifier) => {
if (!isModule) return {};
return context.report({
node,
loc: node.loc,
messageId: 'unexpected'
});
}
};
}
});