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

39 lines
5.7 KiB
JavaScript
Raw Normal View History

2022-06-23 02:27:43 +02:00
'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: {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZWZhdWx0LWV4cG9ydC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsInBhcnNlck9wdGlvbnMiLCJzb3VyY2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