mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-12-11 08:24:31 +01:00
107 lines
11 KiB
JavaScript
107 lines
11 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
|
||
|
var _importDeclaration = require('../importDeclaration');var _importDeclaration2 = _interopRequireDefault(_importDeclaration);
|
||
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
// Rule Definition
|
||
|
//------------------------------------------------------------------------------
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'suggestion',
|
||
|
docs: {
|
||
|
url: (0, _docsUrl2.default)('no-named-as-default-member') },
|
||
|
|
||
|
schema: [] },
|
||
|
|
||
|
|
||
|
create: function (context) {
|
||
|
|
||
|
const fileImports = new Map();
|
||
|
const allPropertyLookups = new Map();
|
||
|
|
||
|
function handleImportDefault(node) {
|
||
|
const declaration = (0, _importDeclaration2.default)(context);
|
||
|
const exportMap = _ExportMap2.default.get(declaration.source.value, context);
|
||
|
if (exportMap == null) return;
|
||
|
|
||
|
if (exportMap.errors.length) {
|
||
|
exportMap.reportErrors(context, declaration);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
fileImports.set(node.local.name, {
|
||
|
exportMap,
|
||
|
sourcePath: declaration.source.value });
|
||
|
|
||
|
}
|
||
|
|
||
|
function storePropertyLookup(objectName, propName, node) {
|
||
|
const lookups = allPropertyLookups.get(objectName) || [];
|
||
|
lookups.push({ node, propName });
|
||
|
allPropertyLookups.set(objectName, lookups);
|
||
|
}
|
||
|
|
||
|
function handlePropLookup(node) {
|
||
|
const objectName = node.object.name;
|
||
|
const propName = node.property.name;
|
||
|
storePropertyLookup(objectName, propName, node);
|
||
|
}
|
||
|
|
||
|
function handleDestructuringAssignment(node) {
|
||
|
const isDestructure =
|
||
|
node.id.type === 'ObjectPattern' &&
|
||
|
node.init != null &&
|
||
|
node.init.type === 'Identifier';
|
||
|
|
||
|
if (!isDestructure) return;
|
||
|
|
||
|
const objectName = node.init.name;
|
||
|
for (const _ref of node.id.properties) {const key = _ref.key;
|
||
|
if (key == null) continue; // true for rest properties
|
||
|
storePropertyLookup(objectName, key.name, key);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function handleProgramExit() {
|
||
|
allPropertyLookups.forEach((lookups, objectName) => {
|
||
|
const fileImport = fileImports.get(objectName);
|
||
|
if (fileImport == null) return;
|
||
|
|
||
|
for (const _ref2 of lookups) {const propName = _ref2.propName;const node = _ref2.node;
|
||
|
// the default import can have a "default" property
|
||
|
if (propName === 'default') continue;
|
||
|
if (!fileImport.exportMap.namespace.has(propName)) continue;
|
||
|
|
||
|
context.report({
|
||
|
node,
|
||
|
message:
|
||
|
`Caution: \`${objectName}\` also has a named export ` +
|
||
|
`\`${propName}\`. Check if you meant to write ` +
|
||
|
`\`import {${propName}} from '${fileImport.sourcePath}'\` ` +
|
||
|
'instead.' });
|
||
|
|
||
|
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
'ImportDefaultSpecifier': handleImportDefault,
|
||
|
'MemberExpression': handlePropLookup,
|
||
|
'VariableDeclarator': handleDestructuringAssignment,
|
||
|
'Program:exit': handleProgramExit };
|
||
|
|
||
|
} }; /**
|
||
|
* @fileoverview Rule to warn about potentially confused use of name exports
|
||
|
* @author Desmond Brand
|
||
|
* @copyright 2016 Desmond Brand. All rights reserved.
|
||
|
* See LICENSE in root directory for full license.
|
||
|
*/
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LW1lbWJlci5qcyJdLCJuYW1lcyI6WyJtb2R1bGU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