mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
108 lines
11 KiB
JavaScript
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hbm9ueW1vdXMtZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsiZGVmcyIsIkFycmF5RXhwcmVzc2lvbiIsIm9wd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