exports-last.js 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  2. function isNonExportStatement(_ref) {var type = _ref.type;
  3. return type !== 'ExportDefaultDeclaration' &&
  4. type !== 'ExportNamedDeclaration' &&
  5. type !== 'ExportAllDeclaration';
  6. }
  7. module.exports = {
  8. meta: {
  9. type: 'suggestion',
  10. docs: {
  11. url: (0, _docsUrl2['default'])('exports-last') },
  12. schema: [] },
  13. create: function () {function create(context) {
  14. return {
  15. Program: function () {function Program(_ref2) {var body = _ref2.body;
  16. var lastNonExportStatementIndex = body.reduce(function () {function findLastIndex(acc, item, index) {
  17. if (isNonExportStatement(item)) {
  18. return index;
  19. }
  20. return acc;
  21. }return findLastIndex;}(), -1);
  22. if (lastNonExportStatementIndex !== -1) {
  23. body.slice(0, lastNonExportStatementIndex).forEach(function () {function checkNonExport(node) {
  24. if (!isNonExportStatement(node)) {
  25. context.report({
  26. node: node,
  27. message: 'Export statements should appear at the end of the file' });
  28. }
  29. }return checkNonExport;}());
  30. }
  31. }return Program;}() };
  32. }return create;}() };
  33. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHBvcnRzLWxhc3QuanMiXSwibmFtZXMiOlsiaXNOb25FeHBvcnRTdGF0ZW1lbnQiLCJ0eXBlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsIlByb2dyYW0iLCJib2R5IiwibGFzdE5vbkV4cG9ydFN0YXRlbWVudEluZGV4IiwicmVkdWNlIiwiZmluZExhc3RJbmRleCIsImFjYyIsIml0ZW0iLCJpbmRleCIsInNsaWNlIiwiZm9yRWFjaCIsImNoZWNr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