the-forest/client/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js

139 lines
16 KiB
JavaScript
Raw Normal View History

2024-09-17 20:35:18 -04:00
'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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5Iiw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