mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
46 lines
2.1 KiB
JavaScript
46 lines
2.1 KiB
JavaScript
"use strict";
|
|
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Lint = require("tslint");
|
|
class AbstractGlobalsRuleWalker extends Lint.RuleWalker {
|
|
constructor(file, program, opts, _config) {
|
|
super(file, opts);
|
|
this.program = program;
|
|
this._config = _config;
|
|
}
|
|
visitIdentifier(node) {
|
|
if (this.getDisallowedGlobals().some(disallowedGlobal => disallowedGlobal === node.text)) {
|
|
if (this._config.allowed && this._config.allowed.some(allowed => allowed === node.text)) {
|
|
return; // override
|
|
}
|
|
const checker = this.program.getTypeChecker();
|
|
const symbol = checker.getSymbolAtLocation(node);
|
|
if (symbol) {
|
|
const declarations = symbol.declarations;
|
|
if (Array.isArray(declarations) && symbol.declarations.some(declaration => {
|
|
if (declaration) {
|
|
const parent = declaration.parent;
|
|
if (parent) {
|
|
const sourceFile = parent.getSourceFile();
|
|
if (sourceFile) {
|
|
const fileName = sourceFile.fileName;
|
|
if (fileName && fileName.indexOf(this.getDefinitionPattern()) >= 0) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
})) {
|
|
this.addFailureAtNode(node, `Cannot use global '${node.text}' in '${this._config.target}'`);
|
|
}
|
|
}
|
|
}
|
|
super.visitIdentifier(node);
|
|
}
|
|
}
|
|
exports.AbstractGlobalsRuleWalker = AbstractGlobalsRuleWalker;
|