mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-11-26 01:16:56 +01:00
104 lines
No EOL
11 KiB
JavaScript
104 lines
No EOL
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbm9ueW1vdXMtZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsiZGVmcyIsIkFycmF5RXhwcmVzc2lvbiIsIm9wdGlvbiIsImRlc2NyaXB0aW9uIiwibWVzc2FnZSIsIkFycm93RnVuY3Rpb25FeHByZXNzaW9uIiwiQ2FsbEV4cHJlc3Npb24iLCJkZWZhdWx0IiwiQ2xhc3NEZWNsYXJhdGlvbiIsImZvcmJpZCIsIm5vZGUiLCJkZWNsYXJhdGlvbiIsImlkIiwiRnVuY3Rpb25EZWNsYXJhdGlvbiIsIkxpdGVyYWwiLCJPYmplY3RFeHByZXNzaW9uIiwiV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