GoScrobble/web/node_modules/eslint-plugin-import/lib/rules/exports-last.js

41 lines
4.5 KiB
JavaScript
Raw Normal View History

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