2022-11-10 10:43:16 +00:00
|
|
|
'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _path = require('path');var path = _interopRequireWildcard(_path);
|
2020-08-25 23:57:08 +00:00
|
|
|
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
|
2022-11-10 10:43:16 +00:00
|
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj['default'] = obj;return newObj;}}
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: 'problem',
|
|
|
|
docs: {
|
2022-11-10 10:43:16 +00:00
|
|
|
url: (0, _docsUrl2['default'])('named') },
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
commonjs: {
|
|
|
|
type: 'boolean' } },
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
additionalProperties: false }] },
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
create: function () {function create(context) {
|
|
|
|
var options = context.options[0] || {};
|
|
|
|
|
|
|
|
function checkSpecifiers(key, type, node) {
|
|
|
|
// ignore local exports and type imports/exports
|
|
|
|
if (
|
|
|
|
node.source == null ||
|
|
|
|
node.importKind === 'type' ||
|
|
|
|
node.importKind === 'typeof' ||
|
|
|
|
node.exportKind === 'type')
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node.specifiers.some(function (im) {return im.type === type;})) {
|
|
|
|
return; // no named imports/exports
|
|
|
|
}
|
|
|
|
|
|
|
|
var imports = _ExportMap2['default'].get(node.source.value, context);
|
|
|
|
if (imports == null || imports.parseGoal === 'ambiguous') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imports.errors.length) {
|
|
|
|
imports.reportErrors(context, node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node.specifiers.forEach(function (im) {
|
|
|
|
if (
|
|
|
|
im.type !== type
|
|
|
|
// ignore type imports
|
|
|
|
|| im.importKind === 'type' || im.importKind === 'typeof')
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
var name = im[key].name || im[key].value;
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
var deepLookup = imports.hasDeep(name);
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
if (!deepLookup.found) {
|
|
|
|
if (deepLookup.path.length > 1) {
|
|
|
|
var deepPath = deepLookup.path.
|
|
|
|
map(function (i) {return path.relative(path.dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()), i.path);}).
|
|
|
|
join(' -> ');
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
context.report(im[key], String(name) + ' not found via ' + String(deepPath));
|
|
|
|
} else {
|
|
|
|
context.report(im[key], name + ' not found in \'' + node.source.value + '\'');
|
|
|
|
}
|
2020-08-25 23:57:08 +00:00
|
|
|
}
|
2022-11-10 10:43:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkRequire(node) {
|
|
|
|
if (
|
|
|
|
!options.commonjs ||
|
|
|
|
node.type !== 'VariableDeclarator'
|
|
|
|
// return if it's not an object destructure or it's an empty object destructure
|
|
|
|
|| !node.id || node.id.type !== 'ObjectPattern' || node.id.properties.length === 0
|
|
|
|
// return if there is no call expression on the right side
|
|
|
|
|| !node.init || node.init.type !== 'CallExpression')
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var call = node.init;var _call$arguments = _slicedToArray(
|
|
|
|
call.arguments, 1),source = _call$arguments[0];
|
|
|
|
var variableImports = node.id.properties;
|
|
|
|
var variableExports = _ExportMap2['default'].get(source.value, context);
|
|
|
|
|
|
|
|
if (
|
|
|
|
// return if it's not a commonjs require statement
|
|
|
|
call.callee.type !== 'Identifier' || call.callee.name !== 'require' || call.arguments.length !== 1
|
|
|
|
// return if it's not a string source
|
|
|
|
|| source.type !== 'Literal' ||
|
|
|
|
variableExports == null ||
|
|
|
|
variableExports.parseGoal === 'ambiguous')
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variableExports.errors.length) {
|
|
|
|
variableExports.reportErrors(context, node);
|
|
|
|
return;
|
2020-08-25 23:57:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
variableImports.forEach(function (im) {
|
|
|
|
if (im.type !== 'Property' || !im.key || im.key.type !== 'Identifier') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var deepLookup = variableExports.hasDeep(im.key.name);
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
if (!deepLookup.found) {
|
|
|
|
if (deepLookup.path.length > 1) {
|
|
|
|
var deepPath = deepLookup.path.
|
|
|
|
map(function (i) {return path.relative(path.dirname(context.getFilename()), i.path);}).
|
|
|
|
join(' -> ');
|
|
|
|
|
|
|
|
context.report(im.key, String(im.key.name) + ' not found via ' + String(deepPath));
|
|
|
|
} else {
|
|
|
|
context.report(im.key, im.key.name + ' not found in \'' + source.value + '\'');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
return {
|
|
|
|
ImportDeclaration: checkSpecifiers.bind(null, 'imported', 'ImportSpecifier'),
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
ExportNamedDeclaration: checkSpecifiers.bind(null, 'local', 'ExportSpecifier'),
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
VariableDeclarator: checkRequire };
|
2020-08-25 23:57:08 +00:00
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
}return create;}() };
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uYW1lZC5qcyJdLCJuYW1lcyI6WyJwYXRoIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsInByb3BlcnRpZXMiLCJjb21tb25qcyIsImFkZGl0aW9uYWxQcm9wZXJ0aWVzIiwiY3JlYXRlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJjaGVja1NwZWNpZmllcnMiLCJrZXkiLCJub2RlIiwic291cmNlIiwiaW1wb3J0S2luZCIsImV4cG9ydEtpbmQiLCJzcGVjaWZpZXJzIiwic29tZSIsImltIiwiaW1wb3J0cyIsIkV4cG9ydHMiLCJnZXQiLCJ2YWx1ZSIsInB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