securityos/node_modules/eslint-plugin-import/lib/rules/no-default-export.js

43 lines
6.1 KiB
JavaScript

'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Style guide',
description: 'Forbid default exports.',
url: (0, _docsUrl2['default'])('no-default-export') },
schema: [] },
create: function () {function create(context) {
// ignore non-modules
if (context.parserOptions.sourceType !== 'module') {
return {};
}
var preferNamed = 'Prefer named exports.';
var noAliasDefault = function () {function noAliasDefault(_ref) {var local = _ref.local;return 'Do not alias `' + String(local.name) + '` as `default`. Just export `' + String(local.name) + '` itself instead.';}return noAliasDefault;}();
return {
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) {var _ref2 =
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref2.loc;
context.report({ node: node, message: preferNamed, loc: loc });
}return ExportDefaultDeclaration;}(),
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) {
node.specifiers.
filter(function (specifier) {return (specifier.exported.name || specifier.exported.value) === 'default';}).
forEach(function (specifier) {var _ref3 =
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref3.loc;
if (specifier.type === 'ExportDefaultSpecifier') {
context.report({ node: node, message: preferNamed, loc: loc });
} else if (specifier.type === 'ExportSpecifier') {
context.report({ node: node, message: noAliasDefault(specifier), loc: loc });
}
});
}return ExportNamedDeclaration;}() };
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZWZhdWx0LWV4cG9ydC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiY2F0ZWdvcnkiLCJkZXNjcmlwdGlvbiIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleH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