exports-last.js 4.2 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) {let 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 (context) {
  14. return {
  15. Program: function (_ref2) {let body = _ref2.body;
  16. const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
  17. if (isNonExportStatement(item)) {
  18. return index;
  19. }
  20. return acc;
  21. }, -1);
  22. if (lastNonExportStatementIndex !== -1) {
  23. body.slice(0, lastNonExportStatementIndex).forEach(function checkNonExport(node) {
  24. if (!isNonExportStatement(node)) {
  25. context.report({
  26. node,
  27. message: 'Export statements should appear at the end of the file' });
  28. }
  29. });
  30. }
  31. } };
  32. } };
  33. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHBvcnRzLWxhc3QuanMiXSwibmFtZXMiOlsiaXNOb25FeHBvcnRTdGF0ZW1lbnQiLCJ0eXBlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsIlByb2dyYW0iLCJib2R5IiwibGFzdE5vbkV4cG9ydFN0YXRlbWVudEluZGV4IiwicmVkdWNlIiwiZmluZExhc3RJbmRleCIsImFjYyIsIml0ZW0iLCJpbmRleCIsInNsaWNlIiwiZm9yRWFjaCIsImNoZWNrTm9uRXhwb3J0Iiwibm9kZSIsInJlcG9ydCIsIm1lc3NhZ2UiXSw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