49 lines
4.2 KiB
JavaScript
49 lines
4.2 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
var _docsUrl = require('../docsUrl');
|
||
|
|
||
|
var _docsUrl2 = _interopRequireDefault(_docsUrl);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
function isNonExportStatement(_ref) {
|
||
|
let type = _ref.type;
|
||
|
|
||
|
return type !== 'ExportDefaultDeclaration' && type !== 'ExportNamedDeclaration' && type !== 'ExportAllDeclaration';
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'suggestion',
|
||
|
docs: {
|
||
|
url: (0, _docsUrl2.default)('exports-last')
|
||
|
}
|
||
|
},
|
||
|
|
||
|
create: function (context) {
|
||
|
return {
|
||
|
Program: function (_ref2) {
|
||
|
let body = _ref2.body;
|
||
|
|
||
|
const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
|
||
|
if (isNonExportStatement(item)) {
|
||
|
return index;
|
||
|
}
|
||
|
return acc;
|
||
|
}, -1);
|
||
|
|
||
|
if (lastNonExportStatementIndex !== -1) {
|
||
|
body.slice(0, lastNonExportStatementIndex).forEach(function checkNonExport(node) {
|
||
|
if (!isNonExportStatement(node)) {
|
||
|
context.report({
|
||
|
node,
|
||
|
message: 'Export statements should appear at the end of the file'
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHBvcnRzLWxhc3QuanMiXSwibmFtZXMiOlsiaXNOb25FeHBvcnRTdGF0ZW1lbnQiLCJ0eXBlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwiY3JlYXRlIiwiY29udGV4dCIsIlByb2dyYW0iLCJib2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