Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/src/rules/exports-last.js
829 views
1
import docsUrl from '../docsUrl';
2
3
function isNonExportStatement({ type }) {
4
return type !== 'ExportDefaultDeclaration' &&
5
type !== 'ExportNamedDeclaration' &&
6
type !== 'ExportAllDeclaration';
7
}
8
9
module.exports = {
10
meta: {
11
type: 'suggestion',
12
docs: {
13
url: docsUrl('exports-last'),
14
},
15
schema: [],
16
},
17
18
create(context) {
19
return {
20
Program({ body }) {
21
const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
22
if (isNonExportStatement(item)) {
23
return index;
24
}
25
return acc;
26
}, -1);
27
28
if (lastNonExportStatementIndex !== -1) {
29
body.slice(0, lastNonExportStatementIndex).forEach(function checkNonExport(node) {
30
if (!isNonExportStatement(node)) {
31
context.report({
32
node,
33
message: 'Export statements should appear at the end of the file',
34
});
35
}
36
});
37
}
38
},
39
};
40
},
41
};
42
43