mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Implement use strict linting (#7223)
* implement use strict linting * commit changes * add additional check for strict
This commit is contained in:
28
build/lib/tslint/noUselessStrictRule.js
Normal file
28
build/lib/tslint/noUselessStrictRule.js
Normal file
@@ -0,0 +1,28 @@
|
||||
"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 Rule extends Lint.Rules.TypedRule {
|
||||
applyWithProgram(sourceFile, program) {
|
||||
if (program.getCompilerOptions().alwaysStrict) {
|
||||
return this.applyWithWalker(new NoUselessStrictRuleWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
exports.Rule = Rule;
|
||||
class NoUselessStrictRuleWalker extends Lint.RuleWalker {
|
||||
visitStringLiteral(node) {
|
||||
this.checkStringLiteral(node);
|
||||
super.visitStringLiteral(node);
|
||||
}
|
||||
checkStringLiteral(node) {
|
||||
const text = node.getText();
|
||||
if (text === '\'use strict\'' || text === '"use strict"') {
|
||||
this.addFailureAtNode(node, 'use strict directive is unnecessary');
|
||||
}
|
||||
}
|
||||
}
|
||||
30
build/lib/tslint/noUselessStrictRule.ts
Normal file
30
build/lib/tslint/noUselessStrictRule.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as Lint from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export class Rule extends Lint.Rules.TypedRule {
|
||||
public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
|
||||
if (program.getCompilerOptions().alwaysStrict) {
|
||||
return this.applyWithWalker(new NoUselessStrictRuleWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class NoUselessStrictRuleWalker extends Lint.RuleWalker {
|
||||
protected visitStringLiteral(node: ts.StringLiteral): void {
|
||||
this.checkStringLiteral(node);
|
||||
super.visitStringLiteral(node);
|
||||
}
|
||||
|
||||
private checkStringLiteral(node: ts.StringLiteral): void {
|
||||
const text = node.getText();
|
||||
if (text === '\'use strict\'' || text === '"use strict"') {
|
||||
this.addFailureAtNode(node, 'use strict directive is unnecessary');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user