mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-08-25 08:08:00 +00:00
96 lines
8.6 KiB
JavaScript
96 lines
8.6 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'suggestion',
|
||
|
docs: {
|
||
|
url: (0, _docsUrl2.default)('prefer-default-export') },
|
||
|
|
||
|
schema: [] },
|
||
|
|
||
|
|
||
|
create: function (context) {
|
||
|
let specifierExportCount = 0;
|
||
|
let hasDefaultExport = false;
|
||
|
let hasStarExport = false;
|
||
|
let hasTypeExport = false;
|
||
|
let namedExportNode = null;
|
||
|
|
||
|
function captureDeclaration(identifierOrPattern) {
|
||
|
if (identifierOrPattern.type === 'ObjectPattern') {
|
||
|
// recursively capture
|
||
|
identifierOrPattern.properties.
|
||
|
forEach(function (property) {
|
||
|
captureDeclaration(property.value);
|
||
|
});
|
||
|
} else if (identifierOrPattern.type === 'ArrayPattern') {
|
||
|
identifierOrPattern.elements.
|
||
|
forEach(captureDeclaration);
|
||
|
} else {
|
||
|
// assume it's a single standard identifier
|
||
|
specifierExportCount++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
'ExportDefaultSpecifier': function () {
|
||
|
hasDefaultExport = true;
|
||
|
},
|
||
|
|
||
|
'ExportSpecifier': function (node) {
|
||
|
if (node.exported.name === 'default') {
|
||
|
hasDefaultExport = true;
|
||
|
} else {
|
||
|
specifierExportCount++;
|
||
|
namedExportNode = node;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
'ExportNamedDeclaration': function (node) {
|
||
|
// if there are specifiers, node.declaration should be null
|
||
|
if (!node.declaration) return;const
|
||
|
|
||
|
type = node.declaration.type;
|
||
|
|
||
|
if (
|
||
|
type === 'TSTypeAliasDeclaration' ||
|
||
|
type === 'TypeAlias' ||
|
||
|
type === 'TSInterfaceDeclaration' ||
|
||
|
type === 'InterfaceDeclaration')
|
||
|
{
|
||
|
specifierExportCount++;
|
||
|
hasTypeExport = true;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (node.declaration.declarations) {
|
||
|
node.declaration.declarations.forEach(function (declaration) {
|
||
|
captureDeclaration(declaration.id);
|
||
|
});
|
||
|
} else
|
||
|
{
|
||
|
// captures 'export function foo() {}' syntax
|
||
|
specifierExportCount++;
|
||
|
}
|
||
|
|
||
|
namedExportNode = node;
|
||
|
},
|
||
|
|
||
|
'ExportDefaultDeclaration': function () {
|
||
|
hasDefaultExport = true;
|
||
|
},
|
||
|
|
||
|
'ExportAllDeclaration': function () {
|
||
|
hasStarExport = true;
|
||
|
},
|
||
|
|
||
|
'Program:exit': function () {
|
||
|
if (specifierExportCount === 1 && !hasDefaultExport && !hasStarExport && !hasTypeExport) {
|
||
|
context.report(namedExportNode, 'Prefer default export.');
|
||
|
}
|
||
|
} };
|
||
|
|
||
|
} };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9wcmVmZXItZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJzcGVjaWZpZXJFeHBvcnRDb3VudCIsImhhc0RlZmF1bHRFeHBvcnQiLCJoYXNTdGFyRXhwb3J0IiwiaGFzVHlwZUV4cG9ydCIsIm5hbWVkRXhwb3J0Tm9kZSIsImNhcHR1cmVEZWNsYXJhdGlvbiIsImlkZW50aWZpZXJPclBhdHRlcm4iLCJwcm9wZXJ0aWVzIiwiZm9yRWFjaCIsInByb3BlcnR5IiwidmFsdWUiLCJlbGVtZW50cyIsIm5vZGUiLCJleHBvcnRlZCIsIm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