139 lines
16 KiB
JavaScript
139 lines
16 KiB
JavaScript
'use strict';var _declaredScope = require('eslint-module-utils/declaredScope');var _declaredScope2 = _interopRequireDefault(_declaredScope);
|
|
var _builder = require('../exportMap/builder');var _builder2 = _interopRequireDefault(_builder);
|
|
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 message(deprecation) {
|
|
return 'Deprecated' + (deprecation.description ? ': ' + String(deprecation.description) : '.');
|
|
}
|
|
|
|
function getDeprecation(metadata) {
|
|
if (!metadata || !metadata.doc) {return;}
|
|
|
|
return metadata.doc.tags.find(function (t) {return t.title === 'deprecated';});
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
category: 'Helpful warnings',
|
|
description: 'Forbid imported names marked with `@deprecated` documentation tag.',
|
|
url: (0, _docsUrl2['default'])('no-deprecated') },
|
|
|
|
schema: [] },
|
|
|
|
|
|
create: function () {function create(context) {
|
|
var deprecated = new Map();
|
|
var namespaces = new Map();
|
|
|
|
function checkSpecifiers(node) {
|
|
if (node.type !== 'ImportDeclaration') {return;}
|
|
if (node.source == null) {return;} // local export, ignore
|
|
|
|
var imports = _builder2['default'].get(node.source.value, context);
|
|
if (imports == null) {return;}
|
|
|
|
var moduleDeprecation = imports.doc && imports.doc.tags.find(function (t) {return t.title === 'deprecated';});
|
|
if (moduleDeprecation) {
|
|
context.report({ node: node, message: message(moduleDeprecation) });
|
|
}
|
|
|
|
if (imports.errors.length) {
|
|
imports.reportErrors(context, node);
|
|
return;
|
|
}
|
|
|
|
node.specifiers.forEach(function (im) {
|
|
var imported = void 0;var local = void 0;
|
|
switch (im.type) {
|
|
|
|
case 'ImportNamespaceSpecifier':{
|
|
if (!imports.size) {return;}
|
|
namespaces.set(im.local.name, imports);
|
|
return;
|
|
}
|
|
|
|
case 'ImportDefaultSpecifier':
|
|
imported = 'default';
|
|
local = im.local.name;
|
|
break;
|
|
|
|
case 'ImportSpecifier':
|
|
imported = im.imported.name;
|
|
local = im.local.name;
|
|
break;
|
|
|
|
default:return; // can't handle this one
|
|
}
|
|
|
|
// unknown thing can't be deprecated
|
|
var exported = imports.get(imported);
|
|
if (exported == null) {return;}
|
|
|
|
// capture import of deep namespace
|
|
if (exported.namespace) {namespaces.set(local, exported.namespace);}
|
|
|
|
var deprecation = getDeprecation(imports.get(imported));
|
|
if (!deprecation) {return;}
|
|
|
|
context.report({ node: im, message: message(deprecation) });
|
|
|
|
deprecated.set(local, deprecation);
|
|
|
|
});
|
|
}
|
|
|
|
return {
|
|
Program: function () {function Program(_ref) {var body = _ref.body;return body.forEach(checkSpecifiers);}return Program;}(),
|
|
|
|
Identifier: function () {function Identifier(node) {
|
|
if (node.parent.type === 'MemberExpression' && node.parent.property === node) {
|
|
return; // handled by MemberExpression
|
|
}
|
|
|
|
// ignore specifier identifiers
|
|
if (node.parent.type.slice(0, 6) === 'Import') {return;}
|
|
|
|
if (!deprecated.has(node.name)) {return;}
|
|
|
|
if ((0, _declaredScope2['default'])(context, node.name) !== 'module') {return;}
|
|
context.report({
|
|
node: node,
|
|
message: message(deprecated.get(node.name)) });
|
|
|
|
}return Identifier;}(),
|
|
|
|
MemberExpression: function () {function MemberExpression(dereference) {
|
|
if (dereference.object.type !== 'Identifier') {return;}
|
|
if (!namespaces.has(dereference.object.name)) {return;}
|
|
|
|
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') {return;}
|
|
|
|
// go deep
|
|
var namespace = namespaces.get(dereference.object.name);
|
|
var namepath = [dereference.object.name];
|
|
// while property is namespace and parent is member expression, keep validating
|
|
while (namespace instanceof _exportMap2['default'] && dereference.type === 'MemberExpression') {
|
|
// ignore computed parts for now
|
|
if (dereference.computed) {return;}
|
|
|
|
var metadata = namespace.get(dereference.property.name);
|
|
|
|
if (!metadata) {break;}
|
|
var deprecation = getDeprecation(metadata);
|
|
|
|
if (deprecation) {
|
|
context.report({ node: dereference.property, message: message(deprecation) });
|
|
}
|
|
|
|
// stash and pop
|
|
namepath.push(dereference.property.name);
|
|
namespace = metadata.namespace;
|
|
dereference = dereference.parent;
|
|
}
|
|
}return MemberExpression;}() };
|
|
|
|
}return create;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsImRlcHJlY2F0ZWQiLCJNYXAiLCJuYW1lc3BhY2VzIiwiY2hlY2tTcGVjaWZpZXJzIiwibm9kZSIsInNvdXJjZSIsImltcG9ydHMiLCJFeHBvcnRNYXBCdWlsZGVyIiwiZ2V0IiwidmFsdWUiLCJtb2R1bGVEZXByZWNhdGlvbiIsInJlcG9ydCIsImVycm9ycyIsImxlbmd0aCIsInJlcG9ydEVycm9ycyIsInNwZWNpZmllcnMiLCJmb3JFYWNoIiwiaW0iLCJpbXBvcnRlZCIsImxvY2FsIiwic2l6ZSIsInNldCIsIm5hbWUiLCJleHBvcnRlZCIsIm5hbWVzcGFjZSIsIlByb2dyYW0iLCJib2R5IiwiSWRlbnRpZmllciIsInBhcmVudCIsInByb3BlcnR5Iiwic2xpY2UiLCJoYXMiLCJNZW1iZXJFeHByZXNzaW9uIiwiZGVyZWZlcmVuY2UiLCJvYmplY3QiLCJuYW1lcGF0aCIsI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