mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 6e530127a1bb8ffbd1bfb77dc680c321dc0d71f5 (#6844)
This commit is contained in:
40
build/lib/tslint/abstractGlobalsRule.js
Normal file
40
build/lib/tslint/abstractGlobalsRule.js
Normal file
@@ -0,0 +1,40 @@
|
||||
"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 valueDeclaration = symbol.valueDeclaration;
|
||||
if (valueDeclaration) {
|
||||
const parent = valueDeclaration.parent;
|
||||
if (parent) {
|
||||
const sourceFile = parent.getSourceFile();
|
||||
if (sourceFile) {
|
||||
const fileName = sourceFile.fileName;
|
||||
if (fileName && fileName.indexOf(this.getDefinitionPattern()) >= 0) {
|
||||
this.addFailureAtNode(node, `Cannot use global '${node.text}' in '${this._config.target}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.visitIdentifier(node);
|
||||
}
|
||||
}
|
||||
exports.AbstractGlobalsRuleWalker = AbstractGlobalsRuleWalker;
|
||||
51
build/lib/tslint/abstractGlobalsRule.ts
Normal file
51
build/lib/tslint/abstractGlobalsRule.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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';
|
||||
|
||||
interface AbstractGlobalsRuleConfig {
|
||||
target: string;
|
||||
allowed: string[];
|
||||
}
|
||||
|
||||
export abstract class AbstractGlobalsRuleWalker extends Lint.RuleWalker {
|
||||
|
||||
constructor(file: ts.SourceFile, private program: ts.Program, opts: Lint.IOptions, private _config: AbstractGlobalsRuleConfig) {
|
||||
super(file, opts);
|
||||
}
|
||||
|
||||
protected abstract getDisallowedGlobals(): string[];
|
||||
|
||||
protected abstract getDefinitionPattern(): string;
|
||||
|
||||
visitIdentifier(node: ts.Identifier) {
|
||||
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 valueDeclaration = symbol.valueDeclaration;
|
||||
if (valueDeclaration) {
|
||||
const parent = valueDeclaration.parent;
|
||||
if (parent) {
|
||||
const sourceFile = parent.getSourceFile();
|
||||
if (sourceFile) {
|
||||
const fileName = sourceFile.fileName;
|
||||
if (fileName && fileName.indexOf(this.getDefinitionPattern()) >= 0) {
|
||||
this.addFailureAtNode(node, `Cannot use global '${node.text}' in '${this._config.target}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.visitIdentifier(node);
|
||||
}
|
||||
}
|
||||
34
build/lib/tslint/noDOMGlobalsRule.js
Normal file
34
build/lib/tslint/noDOMGlobalsRule.js
Normal file
@@ -0,0 +1,34 @@
|
||||
"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");
|
||||
const minimatch = require("minimatch");
|
||||
const abstractGlobalsRule_1 = require("./abstractGlobalsRule");
|
||||
class Rule extends Lint.Rules.TypedRule {
|
||||
applyWithProgram(sourceFile, program) {
|
||||
const configs = 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 [];
|
||||
}
|
||||
}
|
||||
exports.Rule = Rule;
|
||||
class NoDOMGlobalsRuleWalker extends abstractGlobalsRule_1.AbstractGlobalsRuleWalker {
|
||||
getDefinitionPattern() {
|
||||
return 'lib.dom.d.ts';
|
||||
}
|
||||
getDisallowedGlobals() {
|
||||
// intentionally not complete
|
||||
return [
|
||||
"window",
|
||||
"document",
|
||||
"HTMLElement"
|
||||
];
|
||||
}
|
||||
}
|
||||
45
build/lib/tslint/noDOMGlobalsRule.ts
Normal file
45
build/lib/tslint/noDOMGlobalsRule.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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"
|
||||
];
|
||||
}
|
||||
}
|
||||
40
build/lib/tslint/noNodeJSGlobalsRule.js
Normal file
40
build/lib/tslint/noNodeJSGlobalsRule.js
Normal file
@@ -0,0 +1,40 @@
|
||||
"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");
|
||||
const minimatch = require("minimatch");
|
||||
const abstractGlobalsRule_1 = require("./abstractGlobalsRule");
|
||||
class Rule extends Lint.Rules.TypedRule {
|
||||
applyWithProgram(sourceFile, program) {
|
||||
const configs = this.getOptions().ruleArguments;
|
||||
for (const config of configs) {
|
||||
if (minimatch(sourceFile.fileName, config.target)) {
|
||||
return this.applyWithWalker(new NoNodejsGlobalsRuleWalker(sourceFile, program, this.getOptions(), config));
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
exports.Rule = Rule;
|
||||
class NoNodejsGlobalsRuleWalker extends abstractGlobalsRule_1.AbstractGlobalsRuleWalker {
|
||||
getDefinitionPattern() {
|
||||
return '@types/node';
|
||||
}
|
||||
getDisallowedGlobals() {
|
||||
// https://nodejs.org/api/globals.html#globals_global_objects
|
||||
return [
|
||||
"Buffer",
|
||||
"__dirname",
|
||||
"__filename",
|
||||
"clearImmediate",
|
||||
"exports",
|
||||
"global",
|
||||
"module",
|
||||
"process",
|
||||
"setImmediate"
|
||||
];
|
||||
}
|
||||
}
|
||||
51
build/lib/tslint/noNodeJSGlobalsRule.ts
Normal file
51
build/lib/tslint/noNodeJSGlobalsRule.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 NoNodejsGlobalsConfig {
|
||||
target: string;
|
||||
allowed: string[];
|
||||
}
|
||||
|
||||
export class Rule extends Lint.Rules.TypedRule {
|
||||
|
||||
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
|
||||
const configs = <NoNodejsGlobalsConfig[]>this.getOptions().ruleArguments;
|
||||
|
||||
for (const config of configs) {
|
||||
if (minimatch(sourceFile.fileName, config.target)) {
|
||||
return this.applyWithWalker(new NoNodejsGlobalsRuleWalker(sourceFile, program, this.getOptions(), config));
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class NoNodejsGlobalsRuleWalker extends AbstractGlobalsRuleWalker {
|
||||
|
||||
getDefinitionPattern(): string {
|
||||
return '@types/node';
|
||||
}
|
||||
|
||||
getDisallowedGlobals(): string[] {
|
||||
// https://nodejs.org/api/globals.html#globals_global_objects
|
||||
return [
|
||||
"Buffer",
|
||||
"__dirname",
|
||||
"__filename",
|
||||
"clearImmediate",
|
||||
"exports",
|
||||
"global",
|
||||
"module",
|
||||
"process",
|
||||
"setImmediate"
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user