From 998acce592a1f7d3966009b0c375b4fbc4645fe1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 Jun 2016 13:35:29 -0700 Subject: [PATCH] Check for exactly one space --- scripts/tslint/objectLiteralSurroundingSpaceRule.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts index 4178ee99515..b527746bf51 100644 --- a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts +++ b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts @@ -5,6 +5,8 @@ import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { public static LEADING_FAILURE_STRING = "No leading whitespace found on single-line object literal."; public static TRAILING_FAILURE_STRING = "No trailing whitespace found on single-line object literal."; + public static LEADING_EXCESS_FAILURE_STRING = "Excess leading whitespace found on single-line object literal."; + public static TRAILING_EXCESS_FAILURE_STRING = "Excess trailing whitespace found on single-line object literal."; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new ObjectLiteralSpaceWalker(sourceFile, this.getOptions())); @@ -21,10 +23,18 @@ class ObjectLiteralSpaceWalker extends Lint.RuleWalker { const failure = this.createFailure(node.pos, node.getWidth(), Rule.LEADING_FAILURE_STRING); this.addFailure(failure); } + if (text.charAt(2) === " ") { + const failure = this.createFailure(node.pos + 2, 1, Rule.LEADING_EXCESS_FAILURE_STRING); + this.addFailure(failure); + } if (text.charAt(text.length - 2) !== " ") { const failure = this.createFailure(node.pos, node.getWidth(), Rule.TRAILING_FAILURE_STRING); this.addFailure(failure); } + if (text.charAt(text.length - 3) === " ") { + const failure = this.createFailure(node.pos + node.getWidth() - 3, 1, Rule.TRAILING_EXCESS_FAILURE_STRING); + this.addFailure(failure); + } } } super.visitNode(node);