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

139 lines
16 KiB
JavaScript
Raw Normal View History

'use strict';var _declaredScope = require('eslint-module-utils/declaredScope');var _declaredScope2 = _interopRequireDefault(_declaredScope);
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
2022-11-10 10:43:16 +00:00
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;
2022-11-10 10:43:16 +00:00
return metadata.doc.tags.find(function (t) {return t.title === 'deprecated';});
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
2022-11-10 10:43:16 +00:00
url: (0, _docsUrl2['default'])('no-deprecated') },
schema: [] },
2022-11-10 10:43:16 +00:00
create: function () {function create(context) {
var deprecated = new Map();
var namespaces = new Map();
2022-11-10 10:43:16 +00:00
function checkSpecifiers(node) {
if (node.type !== 'ImportDeclaration') return;
if (node.source == null) return; // local export, ignore
2022-11-10 10:43:16 +00:00
var imports = _ExportMap2['default'].get(node.source.value, context);
if (imports == null) return;
2022-11-10 10:43:16 +00:00
var moduleDeprecation = imports.doc && imports.doc.tags.find(function (t) {return t.title === 'deprecated';});
if (moduleDeprecation) {
context.report({ node: node, message: message(moduleDeprecation) });
}
2022-11-10 10:43:16 +00:00
if (imports.errors.length) {
imports.reportErrors(context, node);
return;
}
2022-11-10 10:43:16 +00:00
node.specifiers.forEach(function (im) {
var imported = void 0;var local = void 0;
switch (im.type) {
2022-11-10 10:43:16 +00:00
case 'ImportNamespaceSpecifier':{
if (!imports.size) return;
namespaces.set(im.local.name, imports);
return;
}
2022-11-10 10:43:16 +00:00
case 'ImportDefaultSpecifier':
imported = 'default';
local = im.local.name;
break;
2022-11-10 10:43:16 +00:00
case 'ImportSpecifier':
imported = im.imported.name;
local = im.local.name;
break;
2022-11-10 10:43:16 +00:00
default:return; // can't handle this one
}
2022-11-10 10:43:16 +00:00
// unknown thing can't be deprecated
var exported = imports.get(imported);
if (exported == null) return;
2022-11-10 10:43:16 +00:00
// capture import of deep namespace
if (exported.namespace) namespaces.set(local, exported.namespace);
2022-11-10 10:43:16 +00:00
var deprecation = getDeprecation(imports.get(imported));
if (!deprecation) return;
2022-11-10 10:43:16 +00:00
context.report({ node: im, message: message(deprecation) });
2022-11-10 10:43:16 +00:00
deprecated.set(local, deprecation);
2022-11-10 10:43:16 +00:00
});
}
2022-11-10 10:43:16 +00:00
return {
'Program': function () {function Program(_ref) {var body = _ref.body;return body.forEach(checkSpecifiers);}return Program;}(),
2022-11-10 10:43:16 +00:00
'Identifier': function () {function Identifier(node) {
if (node.parent.type === 'MemberExpression' && node.parent.property === node) {
return; // handled by MemberExpression
}
2022-11-10 10:43:16 +00:00
// ignore specifier identifiers
if (node.parent.type.slice(0, 6) === 'Import') return;
2022-11-10 10:43:16 +00:00
if (!deprecated.has(node.name)) return;
2022-11-10 10:43:16 +00:00
if ((0, _declaredScope2['default'])(context, node.name) !== 'module') return;
context.report({
node: node,
message: message(deprecated.get(node.name)) });
2022-11-10 10:43:16 +00:00
}return Identifier;}(),
2022-11-10 10:43:16 +00:00
'MemberExpression': function () {function MemberExpression(dereference) {
if (dereference.object.type !== 'Identifier') return;
if (!namespaces.has(dereference.object.name)) return;
2022-11-10 10:43:16 +00:00
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') return;
2022-11-10 10:43:16 +00:00
// 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') {
2022-11-10 10:43:16 +00:00
// ignore computed parts for now
if (dereference.computed) return;
2022-11-10 10:43:16 +00:00
var metadata = namespace.get(dereference.property.name);
2022-11-10 10:43:16 +00:00
if (!metadata) break;
var deprecation = getDeprecation(metadata);
2022-11-10 10:43:16 +00:00
if (deprecation) {
context.report({ node: dereference.property, message: message(deprecation) });
}
2022-11-10 10:43:16 +00:00
// stash and pop
namepath.push(dereference.property.name);
namespace = metadata.namespace;
dereference = dereference.parent;
}
}return MemberExpression;}() };
2022-11-10 10:43:16 +00:00
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJkZXByZWNhdGVkIiwiTWFwIiwibmFtZXNwYWNlcyIsImNoZWNrU3BlY2lmaWVycyIsIm5vZGUiLCJzb3VyY2UiLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInZhbHVlIiwibW9kdWxlRGVwcmVjYXRpb24iLCJyZXBvcnQiLCJlcnJvcnMiLCJsZW5ndGgiLCJyZXBvcnRFcnJvcnMiLCJzcGVjaWZpZXJzIiwiZm9yRWFjaCIsImltIiwiaW1wb3J0ZWQiLCJsb2NhbCIsInNpemUiLCJzZXQiLCJuYW1lIiwiZXhwb3J0ZWQiLCJuYW1lc3BhY2UiLCJib2R5IiwicGFyZW50IiwicHJvcGVydHkiLCJzbGljZSIsImhhcyIsImRlcmVmZXJlbmNlIiwib2JqZWN0IiwibmFtZXBhdGgiLCJjb21wdXRlZCIsInB1c2giXSwibWFwcGluZ3MiOiJhQUFBLGtFO0FBQ0EseUM7QUFDQSxxQzs7QUFFQSxTQUFTQSxPQUFULEN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