Files
azuredatastudio/build/lib/tslint/noDomGlobalsRule.ts
Anthony Dresser 658cf51887 Merge from vscode 0f73473c08055054f317c1c94502f7f39fdbb164 (#6892)
* Merge from vscode 0f73473c08055054f317c1c94502f7f39fdbb164

* fix tslinting
2019-08-22 22:07:01 -07:00

46 lines
1.3 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as ts from 'typescript';
import * as Lint from 'tslint';
import * as minimatch from 'minimatch';
import { AbstractGlobalsRuleWalker } from './abstractGlobalsRule';
interface NoDOMGlobalsRuleConfig {
target: string;
allowed: string[];
}
export class Rule extends Lint.Rules.TypedRule {
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
const configs = <NoDOMGlobalsRuleConfig[]>this.getOptions().ruleArguments;
for (const config of configs) {
if (minimatch(sourceFile.fileName, config.target)) {
return this.applyWithWalker(new NoDOMGlobalsRuleWalker(sourceFile, program, this.getOptions(), config));
}
}
return [];
}
}
class NoDOMGlobalsRuleWalker extends AbstractGlobalsRuleWalker {
getDefinitionPattern(): string {
return 'lib.dom.d.ts';
}
getDisallowedGlobals(): string[] {
// intentionally not complete
return [
"window",
"document",
"HTMLElement"
];
}
}