diff --git a/build/gulpfile.hygiene.js b/build/gulpfile.hygiene.js index a919677467..dc2163c1c0 100644 --- a/build/gulpfile.hygiene.js +++ b/build/gulpfile.hygiene.js @@ -189,20 +189,10 @@ const tslintBaseFilter = [ '!extensions/vscode-api-tests/testWorkspace2/**', '!extensions/**/*.test.ts', '!extensions/html-language-features/server/lib/jquery.d.ts', - // {{SQL CARBON EDIT}} - '!extensions/big-data-cluster/src/bigDataCluster/controller/apiGenerated.ts' + '!extensions/big-data-cluster/src/bigDataCluster/controller/apiGenerated.ts' // {{SQL CARBON EDIT}} ]; -// {{SQL CARBON EDIT}} -// const useStrictFilter = [ -// 'src/**' -// ]; - -const sqlFilter = [ - 'src/sql/**' -]; - -// {{SQL CARBON EDIT}} +const sqlFilter = ['src/sql/**']; // {{SQL CARBON EDIT}} const tslintCoreFilter = [ 'src/**/*.ts', @@ -336,23 +326,6 @@ function hygiene(some) { this.emit('data', file); }); - // {{SQL CARBON EDIT}} - // Check for unnecessary 'use strict' lines. These are automatically added by the alwaysStrict compiler option so don't need to be added manually - // const useStrict = es.through(function (file) { - // const lines = file.__lines; - // // Only take the first 10 lines to reduce false positives- the compiler will throw an error if it's not the first non-comment line in a file - // // (10 is used to account for copyright and extraneous newlines) - // lines.slice(0, 10).forEach((line, i) => { - // if (/\s*'use\s*strict\s*'/.test(line)) { - // console.error(file.relative + '(' + (i + 1) + ',1): Unnecessary \'use strict\' - this is already added by the compiler'); - // errorCount++; - // } - // }); - - // this.emit('data', file); - // }); - // {{SQL CARBON EDIT}} END - const formatting = es.map(function (file, cb) { tsfmt.processString(file.path, file.contents.toString('utf8'), { verify: false, diff --git a/build/lib/tslint/noUselessStrictRule.js b/build/lib/tslint/noUselessStrictRule.js new file mode 100644 index 0000000000..925b64133e --- /dev/null +++ b/build/lib/tslint/noUselessStrictRule.js @@ -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'); + } + } +} diff --git a/build/lib/tslint/noUselessStrictRule.ts b/build/lib/tslint/noUselessStrictRule.ts new file mode 100644 index 0000000000..64710178dc --- /dev/null +++ b/build/lib/tslint/noUselessStrictRule.ts @@ -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'); + } + } +} diff --git a/tslint.json b/tslint.json index 982ba03025..c2333565cf 100644 --- a/tslint.json +++ b/tslint.json @@ -228,7 +228,8 @@ "no-new-buffer": true, "translation-remind": true, "no-standalone-editor": true, - "no-nls-in-standalone-editor": true + "no-nls-in-standalone-editor": true, + "no-useless-strict": true }, "defaultSeverity": "warning" }