mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-11-29 19:05:22 +01:00
104 lines
11 KiB
JavaScript
104 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbm9ueW1vdXMtZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsiZGVmcyIsIkFycmF5RXhwcmVzc2lvbiIsIm9wdGlvbiIsImRlc2NyaXB0aW9uIiwibWVzc2FnZSIsIkFycm93RnV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