mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
138 lines
16 KiB
JavaScript
138 lines
16 KiB
JavaScript
|
'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);
|
||
|
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
|
||
|
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;}}
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'problem',
|
||
|
docs: {
|
||
|
url: (0, _docsUrl2['default'])('named') },
|
||
|
|
||
|
schema: [
|
||
|
{
|
||
|
type: 'object',
|
||
|
properties: {
|
||
|
commonjs: {
|
||
|
type: 'boolean' } },
|
||
|
|
||
|
|
||
|
additionalProperties: false }] },
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
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) {
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
var deepLookup = imports.hasDeep(im[key].name);
|
||
|
|
||
|
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(' -> ');
|
||
|
|
||
|
context.report(im[key], String(im[key].name) + ' not found via ' + String(deepPath));
|
||
|
} else {
|
||
|
context.report(im[key], im[key].name + ' not found in \'' + node.source.value + '\'');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (variableExports.errors.length) {
|
||
|
variableExports.reportErrors(context, node);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
variableImports.forEach(function (im) {
|
||
|
if (im.type !== 'Property' || !im.key || im.key.type !== 'Identifier') {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var deepLookup = variableExports.hasDeep(im.key.name);
|
||
|
|
||
|
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 + '\'');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
ImportDeclaration: checkSpecifiers.bind(null, 'imported', 'ImportSpecifier'),
|
||
|
|
||
|
ExportNamedDeclaration: checkSpecifiers.bind(null, 'local', 'ExportSpecifier'),
|
||
|
|
||
|
VariableDeclarator: checkRequire };
|
||
|
|
||
|
}return create;}() };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uYW1lZC5qcyJdLCJuYW1lcyI6WyJwYXRoIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsInByb3BlcnRpZXMiLCJjb21tb25qcyIsImFkZGl0aW9uYWxQcm9wZXJ0aWVzIiwiY3JlYXRlIiwiY29udGV4dCIsIm9wdG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