-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ts-modules-only-named.ts
44 lines (39 loc) · 1.12 KB
/
ts-modules-only-named.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file Rule to force there to be only named exports at the top level.
*
*/
import { normalize, relative } from "node:path";
import { createRule } from "../utils";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
export default createRule({
name: "ts-modules-only-named",
meta: {
type: "suggestion",
docs: {
description: "force there to be only named exports at the top level",
},
messages: {
NoDefaultExports: "Exports at top level should be named",
},
schema: [],
fixable: "code",
},
defaultOptions: [],
create(context) {
if (relative(normalize(context.filename), normalize(context.settings.main as string)) !== "") {
return {};
}
return {
// throw error if an export default declaration is seen
ExportDefaultDeclaration: (node): void =>
context.report({
node,
messageId: "NoDefaultExports",
}),
};
},
});