-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-default-identifier.ts
43 lines (34 loc) · 1.05 KB
/
export-default-identifier.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
import { Rule } from 'eslint'
import { ExportDefaultDeclaration, Node } from 'estree'
interface Options {
types?: string[]
}
const rule: Rule.RuleModule = {
meta: {
docs: {
description: '`export default` must export an identifier for TypeDocs.',
url: 'https://github.com/cybersemics/eslint-plugin-export-default-identifier',
}
},
create: (context) => ({
// export default as node
ExportDefaultDeclaration: (node: Node) => {
// build fails if node is not coerced (?)
const declaration = (node as ExportDefaultDeclaration).declaration
// get allowable types
// default to Identifier
const options = {
types: ["Identifier"],
...context.options[0]
}
// fail if export default is not an allowed node type
if (declaration && !options.types.includes(declaration.type)) {
context.report({
message: `Cannot export ${declaration.type}. Must export identifier as default export for TypeDocs.`,
node,
})
}
},
})
}
export = rule