no-default-export.js 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  2. module.exports = {
  3. meta: {
  4. type: 'suggestion',
  5. docs: {
  6. url: (0, _docsUrl2.default)('no-default-export') },
  7. schema: [] },
  8. create(context) {
  9. // ignore non-modules
  10. if (context.parserOptions.sourceType !== 'module') {
  11. return {};
  12. }
  13. const preferNamed = 'Prefer named exports.';
  14. const noAliasDefault = (_ref) => {let local = _ref.local;return (
  15. `Do not alias \`${local.name}\` as \`default\`. Just export ` +
  16. `\`${local.name}\` itself instead.`);};
  17. return {
  18. ExportDefaultDeclaration(node) {
  19. context.report({ node, message: preferNamed });
  20. },
  21. ExportNamedDeclaration(node) {
  22. node.specifiers.forEach(specifier => {
  23. if (specifier.type === 'ExportDefaultSpecifier' &&
  24. specifier.exported.name === 'default') {
  25. context.report({ node, message: preferNamed });
  26. } else if (specifier.type === 'ExportSpecifier' &&
  27. specifier.exported.name === 'default') {
  28. context.report({ node, message: noAliasDefault(specifier) });
  29. }
  30. });
  31. } };
  32. } };
  33. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZWZhdWx0LWV4cG9ydC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsInBhcnNlck9wdGlvbnMiLCJzb3VyY2VUeXBlIiwicHJlZmVyTmFtZWQiLCJub0FsaWFzRGVmYXVsdCIsImxvY2FsIiwibmFtZSIsIkV4cG9ydERlZmF1bHREZWNsYXJhdGlvbiIsIm5vZGUiLCJyZXBvcnQiLCJtZXNzYWdlIiwiRXhwb3J0TmFtZWREZWN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