diff --git a/Gulpfile.ts b/Gulpfile.ts index 57da2b62aa812..630490b358bda 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -918,37 +918,20 @@ gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", s return gulp.src([serverFile, serverFile + ".map"]).pipe(gulp.dest("../TypeScript-Sublime-Plugin/tsserver/")); }); - -const tslintRuleDir = "scripts/tslint"; -const tslintRules = [ - "nextLineRule", - "preferConstRule", - "booleanTriviaRule", - "typeOperatorSpacingRule", - "noInOperatorRule", - "noIncrementDecrementRule", - "objectLiteralSurroundingSpaceRule", -]; -const tslintRulesFiles = tslintRules.map(function(p) { - return path.join(tslintRuleDir, p + ".ts"); -}); -const tslintRulesOutFiles = tslintRules.map(function(p, i) { - const pathname = path.join(builtLocalDirectory, "tslint", p + ".js"); - gulp.task(pathname, false, [], () => { - const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ false); - return gulp.src(tslintRulesFiles[i]) - .pipe(newer(pathname)) - .pipe(sourcemaps.init()) - .pipe(tsc(settings)) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(path.join(builtLocalDirectory, "tslint"))); - }); - return pathname; +gulp.task("build-rules", "Compiles tslint rules to js", () => { + const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ false); + const dest = path.join(builtLocalDirectory, "tslint"); + return gulp.src("scripts/tslint/**/*.ts") + .pipe(newer({ + dest, + ext: ".js" + })) + .pipe(sourcemaps.init()) + .pipe(tsc(settings)) + .pipe(sourcemaps.write(".")) + .pipe(gulp.dest(dest)); }); -gulp.task("build-rules", "Compiles tslint rules to js", tslintRulesOutFiles); - - function getLinterOptions() { return { configuration: require("./tslint.json"), diff --git a/Jakefile.js b/Jakefile.js index 3ccca83333314..27631ccbf1ba7 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -990,6 +990,7 @@ var tslintRules = [ "noInOperatorRule", "noIncrementDecrementRule", "objectLiteralSurroundingSpaceRule", + "noTypeAssertionWhitespaceRule" ]; var tslintRulesFiles = tslintRules.map(function(p) { return path.join(tslintRuleDir, p + ".ts"); diff --git a/scripts/tslint/noTypeAssertionWhitespaceRule.ts b/scripts/tslint/noTypeAssertionWhitespaceRule.ts new file mode 100644 index 0000000000000..e75964b9e7e99 --- /dev/null +++ b/scripts/tslint/noTypeAssertionWhitespaceRule.ts @@ -0,0 +1,25 @@ +import * as Lint from "tslint/lib/lint"; +import * as ts from "typescript"; + + +export class Rule extends Lint.Rules.AbstractRule { + public static TRAILING_FAILURE_STRING = "Excess trailing whitespace found around type assertion."; + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new TypeAssertionWhitespaceWalker(sourceFile, this.getOptions())); + } +} + +class TypeAssertionWhitespaceWalker extends Lint.RuleWalker { + public visitNode(node: ts.Node) { + if (node.kind === ts.SyntaxKind.TypeAssertionExpression) { + const refined = node as ts.TypeAssertion; + const leftSideWhitespaceStart = refined.type.getEnd() + 1; + const rightSideWhitespaceEnd = refined.expression.getStart(); + if (leftSideWhitespaceStart !== rightSideWhitespaceEnd) { + this.addFailure(this.createFailure(leftSideWhitespaceStart, rightSideWhitespaceEnd, Rule.TRAILING_FAILURE_STRING)); + } + } + super.visitNode(node); + } +} diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c36dff481f5c..997c3ca2c512f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2667,7 +2667,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge isNameOfExportedDeclarationInNonES6Module(node.operand); if (internalExportChanged) { - emitAliasEqual( node.operand); + emitAliasEqual(node.operand); } write(tokenToString(node.operator)); @@ -2722,7 +2722,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } else if (internalExportChanged) { - emitAliasEqual( node.operand); + emitAliasEqual(node.operand); emit(node.operand); if (node.operator === SyntaxKind.PlusPlusToken) { write(" += 1"); diff --git a/src/services/formatting/rulesMap.ts b/src/services/formatting/rulesMap.ts index 703ca566bd20b..65c30908863c0 100644 --- a/src/services/formatting/rulesMap.ts +++ b/src/services/formatting/rulesMap.ts @@ -19,7 +19,7 @@ namespace ts.formatting { public Initialize(rules: Rule[]) { this.mapRowLength = SyntaxKind.LastToken + 1; - this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); + this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map const rulesBucketConstructionStateList: RulesBucketConstructionState[] = new Array(this.map.length); // new Array(this.map.length); diff --git a/src/services/services.ts b/src/services/services.ts index 3b8be487aba9f..40467317f5917 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1082,7 +1082,7 @@ namespace ts { // fall through case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: { - const decl = node; + const decl = node; if (isBindingPattern(decl.name)) { forEachChild(decl.name, visit); break; @@ -2040,7 +2040,7 @@ namespace ts { function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]): CompilerOptions { // Lazily create this value to fix module loading errors. commandLineOptionsStringToEnum = commandLineOptionsStringToEnum || filter(optionDeclarations, o => - typeof o.type === "object" && !forEachValue(> o.type, v => typeof v !== "number")); + typeof o.type === "object" && !forEachValue(>o.type, v => typeof v !== "number")); options = clone(options); diff --git a/tslint.json b/tslint.json index ee116c6fcb0c5..6059c1d4e7b09 100644 --- a/tslint.json +++ b/tslint.json @@ -45,6 +45,7 @@ "prefer-const": true, "no-in-operator": true, "no-increment-decrement": true, - "object-literal-surrounding-space": true + "object-literal-surrounding-space": true, + "no-type-assertion-whitespace": true } }