exports-last.js 4.2 KB

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