@forge/lint
5.15.2-next.55.16.0-next.6
out/lint/linters/deprecated-api-module-linter/deprecated-api-module-visitor.js+
out/lint/linters/deprecated-api-module-linter/deprecated-api-module-visitor.jsNew file+77
Index: package/out/lint/linters/deprecated-api-module-linter/deprecated-api-module-visitor.js
===================================================================
--- package/out/lint/linters/deprecated-api-module-linter/deprecated-api-module-visitor.js
+++ package/out/lint/linters/deprecated-api-module-linter/deprecated-api-module-visitor.js
@@ -0,0 +1,77 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.DeprecatedApiModuleVisitor = void 0;
+const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
+const deprecated_api_module_interface_1 = require("./deprecated-api-module-interface");
+class DeprecatedApiModuleVisitor {
+ namespaceNames = new Set();
+ visit(node, _parent, onMatchCallback) {
+ if (node.type === typescript_estree_1.AST_NODE_TYPES.ImportDeclaration && node.source.value === deprecated_api_module_interface_1.FORGE_API_PACKAGE) {
+ this.visitImportDeclaration(node, onMatchCallback);
+ return;
+ }
+ if (node.type === typescript_estree_1.AST_NODE_TYPES.MemberExpression) {
+ this.visitMemberExpression(node, onMatchCallback);
+ return;
+ }
+ if (node.type === typescript_estree_1.AST_NODE_TYPES.VariableDeclarator) {
+ this.visitVariableDeclarator(node, onMatchCallback);
+ }
+ }
+ visitImportDeclaration(node, onMatchCallback) {
+ for (const specifier of node.specifiers) {
+ if (specifier.type === typescript_estree_1.AST_NODE_TYPES.ImportSpecifier &&
+ specifier.imported.type === typescript_estree_1.AST_NODE_TYPES.Identifier &&
+ specifier.imported.name === deprecated_api_module_interface_1.DEPRECATED_STORAGE_EXPORT_NAME &&
+ specifier.local.loc) {
+ onMatchCallback({
+ line: specifier.local.loc.start.line,
+ column: specifier.local.loc.start.column
+ });
+ }
+ if (specifier.type === typescript_estree_1.AST_NODE_TYPES.ImportNamespaceSpecifier) {
+ this.namespaceNames.add(specifier.local.name);
+ }
+ }
+ }
+ visitMemberExpression(node, onMatchCallback) {
+ if (node.object.type !== typescript_estree_1.AST_NODE_TYPES.Identifier || !this.namespaceNames.has(node.object.name)) {
+ return;
+ }
+ const isStorageDotAccess = !node.computed &&
+ node.property.type === typescript_estree_1.AST_NODE_TYPES.Identifier &&
+ node.property.name === deprecated_api_module_interface_1.DEPRECATED_STORAGE_EXPORT_NAME;
+ const isStorageBracketAccess = node.computed &&
+ node.property.type === typescript_estree_1.AST_NODE_TYPES.Literal &&
+ node.property.value === deprecated_api_module_interface_1.DEPRECATED_STORAGE_EXPORT_NAME;
+ if ((isStorageDotAccess || isStorageBracketAccess) && node.property.loc) {
+ onMatchCallback({
+ line: node.property.loc.start.line,
+ column: node.property.loc.start.column
+ });
+ }
+ }
+ visitVariableDeclarator(node, onMatchCallback) {
+ if (node.init?.type !== typescript_estree_1.AST_NODE_TYPES.Identifier || !this.namespaceNames.has(node.init.name)) {
+ return;
+ }
+ if (node.id.type === typescript_estree_1.AST_NODE_TYPES.Identifier) {
+ this.namespaceNames.add(node.id.name);
+ return;
+ }
+ if (node.id.type === typescript_estree_1.AST_NODE_TYPES.ObjectPattern) {
+ for (const prop of node.id.properties) {
+ if (prop.type === typescript_estree_1.AST_NODE_TYPES.Property &&
+ prop.key.type === typescript_estree_1.AST_NODE_TYPES.Identifier &&
+ prop.key.name === deprecated_api_module_interface_1.DEPRECATED_STORAGE_EXPORT_NAME &&
+ prop.key.loc) {
+ onMatchCallback({
+ line: prop.key.loc.start.line,
+ column: prop.key.loc.start.column
+ });
+ }
+ }
+ }
+ }
+}
+exports.DeprecatedApiModuleVisitor = DeprecatedApiModuleVisitor;