157 lines
15 KiB
JavaScript
157 lines
15 KiB
JavaScript
'use strict';
|
|
|
|
var _declaredScope = require('eslint-module-utils/declaredScope');
|
|
|
|
var _declaredScope2 = _interopRequireDefault(_declaredScope);
|
|
|
|
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 ? ': ' + deprecation.description : '.');
|
|
}
|
|
|
|
function getDeprecation(metadata) {
|
|
if (!metadata || !metadata.doc) return;
|
|
|
|
let deprecation;
|
|
if (metadata.doc.tags.some(t => t.title === 'deprecated' && (deprecation = t))) {
|
|
return deprecation;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2.default)('no-deprecated')
|
|
},
|
|
schema: []
|
|
},
|
|
|
|
create: function (context) {
|
|
const deprecated = new Map(),
|
|
namespaces = new Map();
|
|
|
|
function checkSpecifiers(node) {
|
|
if (node.type !== 'ImportDeclaration') return;
|
|
if (node.source == null) return; // local export, ignore
|
|
|
|
const imports = _ExportMap2.default.get(node.source.value, context);
|
|
if (imports == null) return;
|
|
|
|
let moduleDeprecation;
|
|
if (imports.doc && imports.doc.tags.some(t => t.title === 'deprecated' && (moduleDeprecation = t))) {
|
|
context.report({ node, message: message(moduleDeprecation) });
|
|
}
|
|
|
|
if (imports.errors.length) {
|
|
imports.reportErrors(context, node);
|
|
return;
|
|
}
|
|
|
|
node.specifiers.forEach(function (im) {
|
|
let imported, local;
|
|
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
|
|
const exported = imports.get(imported);
|
|
if (exported == null) return;
|
|
|
|
// capture import of deep namespace
|
|
if (exported.namespace) namespaces.set(local, exported.namespace);
|
|
|
|
const deprecation = getDeprecation(imports.get(imported));
|
|
if (!deprecation) return;
|
|
|
|
context.report({ node: im, message: message(deprecation) });
|
|
|
|
deprecated.set(local, deprecation);
|
|
});
|
|
}
|
|
|
|
return {
|
|
'Program': (_ref) => {
|
|
let body = _ref.body;
|
|
return body.forEach(checkSpecifiers);
|
|
},
|
|
|
|
'Identifier': function (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,
|
|
message: message(deprecated.get(node.name))
|
|
});
|
|
},
|
|
|
|
'MemberExpression': function (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;
|
|
|
|
const metadata = namespace.get(dereference.property.name);
|
|
|
|
if (!metadata) break;
|
|
const 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;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJzb21lIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJkZXByZWNhdGVkIiwiTWFwIiwibmFtZXNwYWNlcyIsImNoZWNrU3BlY2lmaWVycyIsIm5vZGUiLCJzb3VyY2UiLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInZhbHVlIiwibW9kdWxlRGVwcmVjYXRpb24iLCJyZXBvcnQiLCJlcnJvcnMiLCJsZW5ndGgiLCJyZXBvcnRFcnJvcnMiLCJzcGVjaWZpZXJzIiwiZm9yRWFjaCIsImltIiwiaW1wb3J0ZWQiLCJsb2NhbCIsInNpemUiLCJzZXQiLCJuYW1lIiwiZXhwb3J0ZWQiLCJuYW1lc3BhY2UiLCJib2R5IiwicGFyZW50IiwicHJvcGVydHkiLCJzbGljZSIsImhhcyIsImRlcmVmZXJlbmNlIiwib2JqZWN0IiwibmFtZXBhdGgiLCJjb21wdXRlZCIsInB1c2giXSwibWFwcGluZ3MiOiI7O0FBQUE7Ozs7QUFDQTs7OztBQUNBOzs7Ozs7QUFFQSxTQUFTQSxPQUFULENBQWlCQyxXQUFqQixFQUE4QjtBQUM1QixTQUFPLGdCQUFnQkEsWUFBWUM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