103 lines
12 KiB
JavaScript
103 lines
12 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
var _hasown = require('hasown');var _hasown2 = _interopRequireDefault(_hasown);
|
||
|
var _object = require('object.values');var _object2 = _interopRequireDefault(_object);
|
||
|
var _object3 = require('object.fromentries');var _object4 = _interopRequireDefault(_object3);
|
||
|
|
||
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} /**
|
||
|
* @fileoverview Rule to disallow anonymous default exports.
|
||
|
* @author Duncan Beevers
|
||
|
*/var defs = { ArrayExpression: {
|
||
|
option: 'allowArray',
|
||
|
description: 'If `false`, will report default export of an array',
|
||
|
message: 'Assign array to a variable before exporting as module default' },
|
||
|
|
||
|
ArrowFunctionExpression: {
|
||
|
option: 'allowArrowFunction',
|
||
|
description: 'If `false`, will report default export of an arrow function',
|
||
|
message: 'Assign arrow function to a variable before exporting as module default' },
|
||
|
|
||
|
CallExpression: {
|
||
|
option: 'allowCallExpression',
|
||
|
description: 'If `false`, will report default export of a function call',
|
||
|
message: 'Assign call result to a variable before exporting as module default',
|
||
|
'default': true },
|
||
|
|
||
|
ClassDeclaration: {
|
||
|
option: 'allowAnonymousClass',
|
||
|
description: 'If `false`, will report default export of an anonymous class',
|
||
|
message: 'Unexpected default export of anonymous class',
|
||
|
forbid: function () {function forbid(node) {return !node.declaration.id;}return forbid;}() },
|
||
|
|
||
|
FunctionDeclaration: {
|
||
|
option: 'allowAnonymousFunction',
|
||
|
description: 'If `false`, will report default export of an anonymous function',
|
||
|
message: 'Unexpected default export of anonymous function',
|
||
|
forbid: function () {function forbid(node) {return !node.declaration.id;}return forbid;}() },
|
||
|
|
||
|
Literal: {
|
||
|
option: 'allowLiteral',
|
||
|
description: 'If `false`, will report default export of a literal',
|
||
|
message: 'Assign literal to a variable before exporting as module default' },
|
||
|
|
||
|
ObjectExpression: {
|
||
|
option: 'allowObject',
|
||
|
description: 'If `false`, will report default export of an object expression',
|
||
|
message: 'Assign object to a variable before exporting as module default' },
|
||
|
|
||
|
TemplateLiteral: {
|
||
|
option: 'allowLiteral',
|
||
|
description: 'If `false`, will report default export of a literal',
|
||
|
message: 'Assign literal to a variable before exporting as module default' },
|
||
|
|
||
|
NewExpression: {
|
||
|
option: 'allowNew',
|
||
|
description: 'If `false`, will report default export of a class instantiation',
|
||
|
message: 'Assign instance to a variable before exporting as module default' } };
|
||
|
|
||
|
|
||
|
|
||
|
var schemaProperties = (0, _object4['default'])((0, _object2['default'])(defs).map(function (def) {return [def.option, {
|
||
|
description: def.description,
|
||
|
type: 'boolean' }];}));
|
||
|
|
||
|
|
||
|
var defaults = (0, _object4['default'])((0, _object2['default'])(defs).map(function (def) {return [def.option, (0, _hasown2['default'])(def, 'default') ? def['default'] : false];}));
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'suggestion',
|
||
|
docs: {
|
||
|
category: 'Style guide',
|
||
|
description: 'Forbid anonymous values as default exports.',
|
||
|
url: (0, _docsUrl2['default'])('no-anonymous-default-export') },
|
||
|
|
||
|
|
||
|
schema: [
|
||
|
{
|
||
|
type: 'object',
|
||
|
properties: schemaProperties,
|
||
|
additionalProperties: false }] },
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
create: function () {function create(context) {
|
||
|
var options = Object.assign({}, defaults, context.options[0]);
|
||
|
|
||
|
return {
|
||
|
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) {
|
||
|
var def = defs[node.declaration.type];
|
||
|
|
||
|
// Recognized node type and allowed by configuration,
|
||
|
// and has no forbid check, or forbid check return value is truthy
|
||
|
if (def && !options[def.option] && (!def.forbid || def.forbid(node))) {
|
||
|
context.report({ node: node, message: def.message });
|
||
|
}
|
||
|
}return ExportDefaultDeclaration;}() };
|
||
|
|
||
|
}return create;}() };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJz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