Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Fixes whitespace check-module to properly lint and fix errors #2825

Merged
merged 4 commits into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/formatterLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import * as fs from "fs";
import * as path from "path";
import {FormatterConstructor} from "./index";
import {camelize} from "./utils";
import { FormatterConstructor } from "./index";
import { camelize } from "./utils";

const moduleDirectory = path.dirname(module.filename);
const CORE_FORMATTERS_DIRECTORY = path.resolve(moduleDirectory, ".", "formatters");
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/checkstyleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as Utils from "../utils";
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/codeFrameFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import codeFrame = require("babel-code-frame");
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/fileslistFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import {RuleFailure} from "../language/rule/rule";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

export class Formatter extends AbstractFormatter {
/* tslint:disable:object-literal-sort-keys */
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/jsonFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import {RuleFailure} from "../language/rule/rule";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as Utils from "../utils";

Expand Down
6 changes: 3 additions & 3 deletions src/formatters/msbuildFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import {camelize, dedent} from "../utils";
import { camelize, dedent } from "../utils";

export class Formatter extends AbstractFormatter {
/* tslint:disable:object-literal-sort-keys */
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/pmdFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as Utils from "../utils";
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/proseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import {RuleFailure} from "../language/rule/rule";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

export class Formatter extends AbstractFormatter {
/* tslint:disable:object-literal-sort-keys */
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/stylishFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as colors from "colors";
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/verboseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

export class Formatter extends AbstractFormatter {
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/vsoFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import {RuleFailure} from "../language/rule/rule";
import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as Utils from "../utils";

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import * as Configuration from "./configuration";
import * as Formatters from "./formatters";
import {FormatterConstructor} from "./language/formatter/formatter";
import {RuleFailure} from "./language/rule/rule";
import { FormatterConstructor } from "./language/formatter/formatter";
import { RuleFailure } from "./language/rule/rule";
import * as Linter from "./linter";
import * as Rules from "./rules";
import * as Test from "./test";
Expand Down
4 changes: 2 additions & 2 deletions src/language/formatter/abstractFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import {RuleFailure} from "../rule/rule";
import {IFormatter, IFormatterMetadata} from "./formatter";
import { RuleFailure } from "../rule/rule";
import { IFormatter, IFormatterMetadata } from "./formatter";

export abstract class AbstractFormatter implements IFormatter {
public static metadata: IFormatterMetadata;
Expand Down
2 changes: 1 addition & 1 deletion src/language/formatter/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import {RuleFailure} from "../rule/rule";
import { RuleFailure } from "../rule/rule";

export interface IFormatterMetadata {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/language/rule/abstractRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import * as ts from "typescript";

import {IWalker, WalkContext} from "../walker";
import { IWalker, WalkContext } from "../walker";
import { IOptions, IRule, IRuleMetadata, RuleFailure, RuleSeverity } from "./rule";

export abstract class AbstractRule implements IRule {
Expand Down
4 changes: 2 additions & 2 deletions src/language/rule/optionallyTypedRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import * as ts from "typescript";

import {AbstractRule} from "./abstractRule";
import {ITypedRule, RuleFailure} from "./rule";
import { AbstractRule } from "./abstractRule";
import { ITypedRule, RuleFailure } from "./rule";

export abstract class OptionallyTypedRule extends AbstractRule implements ITypedRule {
public abstract applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[];
Expand Down
4 changes: 2 additions & 2 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import * as ts from "typescript";

import {arrayify, flatMap} from "../../utils";
import {IWalker} from "../walker";
import { arrayify, flatMap } from "../../utils";
import { IWalker } from "../walker";

export interface RuleConstructor {
metadata: IRuleMetadata;
Expand Down
4 changes: 2 additions & 2 deletions src/language/rule/typedRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import * as ts from "typescript";

import { showWarningOnce } from "../../error";
import {AbstractRule} from "./abstractRule";
import {ITypedRule, RuleFailure} from "./rule";
import { AbstractRule } from "./abstractRule";
import { ITypedRule, RuleFailure } from "./rule";

export abstract class TypedRule extends AbstractRule implements ITypedRule {

Expand Down
2 changes: 1 addition & 1 deletion src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as path from "path";
import { isBlockScopedVariableDeclarationList, isPrefixUnaryExpression } from "tsutils";
import * as ts from "typescript";

import {IDisabledInterval, RuleFailure} from "./rule/rule"; // tslint:disable-line deprecation
import { IDisabledInterval, RuleFailure } from "./rule/rule"; // tslint:disable-line deprecation

export function getSourceFile(fileName: string, source: string): ts.SourceFile {
const normalizedName = path.normalize(fileName).replace(/\\/g, "/");
Expand Down
6 changes: 3 additions & 3 deletions src/language/walker/blockScopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import * as ts from "typescript";

import {IOptions} from "../rule/rule";
import {isBlockScopeBoundary} from "../utils";
import { IOptions } from "../rule/rule";
import { isBlockScopeBoundary } from "../utils";
// tslint:disable deprecation
import {ScopeAwareRuleWalker} from "./scopeAwareRuleWalker";
import { ScopeAwareRuleWalker } from "./scopeAwareRuleWalker";

/**
* @deprecated See comment on ScopeAwareRuleWalker.
Expand Down
4 changes: 2 additions & 2 deletions src/language/walker/programAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import * as ts from "typescript";

import {IOptions} from "../rule/rule";
import {RuleWalker} from "./ruleWalker";
import { IOptions } from "../rule/rule";
import { RuleWalker } from "./ruleWalker";

export class ProgramAwareRuleWalker extends RuleWalker {
private typeChecker: ts.TypeChecker;
Expand Down
6 changes: 3 additions & 3 deletions src/language/walker/ruleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import * as ts from "typescript";

import {Fix, IOptions, Replacement, RuleFailure} from "../rule/rule";
import {SyntaxWalker} from "./syntaxWalker";
import {IWalker} from "./walker";
import { Fix, IOptions, Replacement, RuleFailure } from "../rule/rule";
import { SyntaxWalker } from "./syntaxWalker";
import { IWalker } from "./walker";

export class RuleWalker extends SyntaxWalker implements IWalker {
private limit: number;
Expand Down
6 changes: 3 additions & 3 deletions src/language/walker/scopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import * as ts from "typescript";

import {IOptions} from "../rule/rule";
import {isScopeBoundary} from "../utils";
import {RuleWalker} from "./ruleWalker";
import { IOptions } from "../rule/rule";
import { isScopeBoundary } from "../utils";
import { RuleWalker } from "./ruleWalker";

/**
* @deprecated Prefer to manually maintain any contextual information.
Expand Down
6 changes: 3 additions & 3 deletions src/language/walker/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import * as ts from "typescript";

import {RuleFailure} from "../rule/rule";
import {WalkContext} from "./walkContext";
import {IWalker} from "./walker";
import { RuleFailure } from "../rule/rule";
import { WalkContext } from "./walkContext";
import { IWalker } from "./walker";

export interface IWalker {
getSourceFile(): ts.SourceFile;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/memberOrderingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as ts from "typescript";

import { showWarningOnce } from "../error";
import * as Lint from "../index";
import {flatMap, mapDefined} from "../utils";
import { flatMap, mapDefined } from "../utils";

const OPTION_ORDER = "order";
const OPTION_ALPHABETIZE = "alphabetize";
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUnsafeAnyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import {isExpression} from "tsutils";
import { isExpression } from "tsutils";
import * as ts from "typescript";
import * as Lint from "../index";

Expand Down
19 changes: 17 additions & 2 deletions src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ function walk(ctx: Lint.WalkContext<Options>) {
let position: number | undefined;
const { name, namedBindings } = importClause;
if (namedBindings !== undefined) {
if (namedBindings.kind !== ts.SyntaxKind.NamespaceImport) {
namedBindings.elements.forEach((element, idx, arr) => {
const internalName = element.name;
if (internalName !== undefined) {
if (idx === arr.length - 1) {
const token = namedBindings.getLastToken();
checkForTrailingWhitespace(token.getFullStart());
}
if (idx === 0) {
const startPos = internalName.getStart() - 1;
checkForTrailingWhitespace(startPos, startPos + 1);
}
}
});
}
position = namedBindings.getEnd();
} else if (name !== undefined) {
position = name.getEnd();
Expand Down Expand Up @@ -246,9 +261,9 @@ function walk(ctx: Lint.WalkContext<Options>) {
checkForTrailingWhitespace(equalsGreaterThanToken.getEnd());
}

function checkForTrailingWhitespace(position: number): void {
function checkForTrailingWhitespace(position: number, whiteSpacePos: number = position): void {
if (position !== sourceFile.end && !Lint.isWhiteSpace(sourceFile.text.charCodeAt(position))) {
addMissingWhitespaceErrorAt(position);
addMissingWhitespaceErrorAt(whiteSpacePos);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import * as path from "path";
import * as semver from "semver";
import * as ts from "typescript";

import {Replacement} from "./language/rule/rule";
import { Replacement } from "./language/rule/rule";
import * as Linter from "./linter";
import {LintError} from "./test/lintError";
import { LintError } from "./test/lintError";
import * as parse from "./test/parse";
import {denormalizeWinPath, mapDefined, readBufferWithDetectedEncoding} from "./utils";
import { denormalizeWinPath, mapDefined, readBufferWithDetectedEncoding } from "./utils";

const MARKUP_FILE_EXTENSION = ".lint";
const FIXES_FILE_EXTENSION = ".fix";
Expand Down
6 changes: 3 additions & 3 deletions src/test/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import * as ts from "typescript";
import {format} from "util";
import { format } from "util";

import {flatMap, mapDefined} from "../utils";
import { flatMap, mapDefined } from "../utils";
import {
CodeLine,
EndErrorLine,
Expand All @@ -28,7 +28,7 @@ import {
parseLine,
printLine,
} from "./lines";
import {errorComparator, LintError, lintSyntaxError} from "./lintError";
import { errorComparator, LintError, lintSyntaxError } from "./lintError";

let scanner: ts.Scanner | undefined;

Expand Down
2 changes: 1 addition & 1 deletion test/formatters/codeFrameFormatterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as colors from "colors";

import * as ts from "typescript";

import {IFormatter, TestUtils} from "../lint";
import { IFormatter, TestUtils } from "../lint";
import { createFailure } from "./utils";

describe("CodeFrame Formatter", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/rule-tester/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {LintError} from "../../src/test/lintError";
import { LintError } from "../../src/test/lintError";

/* tslint:disable:object-literal-sort-keys no-consecutive-blank-lines */

Expand Down
2 changes: 1 addition & 1 deletion test/ruleTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as colors from "colors";
import * as glob from "glob";
import * as path from "path";

import {consoleTestResultHandler, runTest} from "../src/test";
import { consoleTestResultHandler, runTest } from "../src/test";

/* tslint:disable:no-console */
console.log();
Expand Down
Loading