no-anonymous-default-export.js
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
var _has = require('has');var _has2 = _interopRequireDefault(_has);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' } };
var schemaProperties = Object.keys(defs).
map(function (key) {return defs[key];}).
reduce(function (acc, def) {
acc[def.option] = {
description: def.description,
type: 'boolean' };
return acc;
}, {});
var defaults = Object.keys(defs).
map(function (key) {return defs[key];}).
reduce(function (acc, def) {
acc[def.option] = (0, _has2['default'])(def, 'default') ? def['default'] : false;
return acc;
}, {});
module.exports = {
meta: {
type: 'suggestion',
docs: {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbm9ueW1vdXMtZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsiZGVmcyIsIkFycmF5RXhwcmVzc2lvbiIsIm9wdGlvbiIsImRlc2NyaXB0aW9uIiwibWVzc2FnZSIsIkFycm93RnVuY3Rpb25FeHByZXNzaW9uIiwiQ2FsbEV4cHJlc3Npb24iLCJDbGFzc0RlY2xhcmF0aW9uIiwiZm9yYmlkIiwibm9kZSIsImRlY2xhcmF0aW9uIiwiaWQiLCJGdW5jdGlvbkRlY2xhcmF0aW9uIiwiTGl0ZXJhbCIsIk9iamVjdEV4cHJlc3Npb24iLCJUZW1wbGF0ZUxpdGVyYWwiLCJzY2hlbWFQcm9wZXJ0aWVzIiwiT2JqZWN0Iiwia2V5cyIsIm1hcCIsImtleSIsInJlZHVjZSIsImFjYyIsImRlZiIsInR5cGUiLCJkZWZhdWx0cyIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwiZG9jcyIsInVybCIsInNjaG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