github-pages-deploy-action/node_modules/eslint-plugin-import/lib/rules/no-anonymous-default-export.js
2020-03-06 22:45:40 -05:00

108 lines
11 KiB
JavaScript

'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
*/
const 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: node => !node.declaration.id
},
FunctionDeclaration: {
option: 'allowAnonymousFunction',
description: 'If `false`, will report default export of an anonymous function',
message: 'Unexpected default export of anonymous function',
forbid: node => !node.declaration.id
},
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'
}
};
const schemaProperties = Object.keys(defs).map(key => defs[key]).reduce((acc, def) => {
acc[def.option] = {
description: def.description,
type: 'boolean'
};
return acc;
}, {});
const defaults = Object.keys(defs).map(key => defs[key]).reduce((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 (context) {
const options = Object.assign({}, defaults, context.options[0]);
return {
'ExportDefaultDeclaration': node => {
const 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, message: def.message });
}
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbm9ueW1vdXMtZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsiZGVmcyIsIkFycmF5RXhwcmVzc2lvbiIsIm9wdGlvbiIsImRlc2NyaXB0aW9uIiwibWVzc2FnZSIsIkFycm93RnVuY3Rpb25FeHByZXNzaW9uIiwiQ2FsbEV4cHJlc3Npb24iLCJkZWZhdWx0IiwiQ2xhc3NEZWNsYXJhdGlvbiIsImZvcmJpZCIsIm5vZGUiLCJkZWNsYXJhdGlvbiIsImlkIiwiRnVuY3Rpb25EZWNsYXJhdGlvbiIsIkxpdGVyYWwiLCJPYmplY3RFeHByZXNzaW9uIiwiVGVtcGxhdGVMaXRlcmFsIiwic2NoZW1hUHJvcGVydGllcyIsIk9iamVjdCIsImtleXMiLCJtYXAiLCJrZXkiLCJyZWR1Y2UiLCJhY2MiLCJkZWYiLCJ0eXBlIiwiZGVmYXVsdHMiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiY3JlYXRlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJhc3NpZ24iLCJyZXBvcnQiXSwibWFwcGluZ3MiOiI7O0FBS0E7Ozs7QUFDQTs7Ozs7O0FBTkE7Ozs7O0FBUUEsTUFBTUEsT0FBTztBQUNYQyxtQkFBaUI7QUFDZkMsWUFBUSxZQURPO0FBRWZDLGlCQUFhL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