PromoCursed/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js

138 lines
16 KiB
JavaScript
Raw Normal View History

2024-08-20 23:25:37 +04:00
'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 ? ': ' + 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 = _ExportMap2['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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiw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