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