diff --git a/Jakefile.js b/Jakefile.js index 4512aa23794..971f0be0fde 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -1104,7 +1104,8 @@ var tslintRules = [ "noInOperatorRule", "noIncrementDecrementRule", "objectLiteralSurroundingSpaceRule", - "noTypeAssertionWhitespaceRule" + "noTypeAssertionWhitespaceRule", + "noBomRule" ]; var tslintRulesFiles = tslintRules.map(function (p) { return path.join(tslintRuleDir, p + ".ts"); diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index db6abcbf17b..e79275c6392 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -2,52 +2,62 @@ import * as Lint from "tslint/lib"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { - public static FAILURE_STRING_FACTORY = (name: string, currently: string) => `Tag boolean argument as '${name}' (currently '${currently}')`; + public static FAILURE_STRING_FACTORY(name: string, currently?: string): string { + const current = currently ? ` (currently '${currently}')` : ""; + return `Tag boolean argument as '${name}'${current}`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + // Cheat to get type checker const program = ts.createProgram([sourceFile.fileName], Lint.createCompilerOptions()); const checker = program.getTypeChecker(); - return this.applyWithWalker(new BooleanTriviaWalker(checker, program.getSourceFile(sourceFile.fileName), this.getOptions())); + return this.applyWithFunction(program.getSourceFile(sourceFile.fileName), ctx => walk(ctx, checker)); } } -class BooleanTriviaWalker extends Lint.RuleWalker { - constructor(private checker: ts.TypeChecker, file: ts.SourceFile, opts: Lint.IOptions) { - super(file, opts); +function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker): void { + ts.forEachChild(ctx.sourceFile, recur); + function recur(node: ts.Node): void { + if (node.kind === ts.SyntaxKind.CallExpression) { + checkCall(node as ts.CallExpression); + } + ts.forEachChild(node, recur); } - visitCallExpression(node: ts.CallExpression) { - super.visitCallExpression(node); - if (node.arguments && node.arguments.some(arg => arg.kind === ts.SyntaxKind.TrueKeyword || arg.kind === ts.SyntaxKind.FalseKeyword)) { - const targetCallSignature = this.checker.getResolvedSignature(node); - if (!!targetCallSignature) { - const targetParameters = targetCallSignature.getParameters(); - const source = this.getSourceFile(); - for (let index = 0; index < targetParameters.length; index++) { - const param = targetParameters[index]; - const arg = node.arguments[index]; - if (!(arg && param)) { - continue; - } + function checkCall(node: ts.CallExpression): void { + if (!node.arguments || !node.arguments.some(arg => arg.kind === ts.SyntaxKind.TrueKeyword || arg.kind === ts.SyntaxKind.FalseKeyword)) { + return; + } - const argType = this.checker.getContextualType(arg); - if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) { - if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) { - continue; - } - let triviaContent: string; - const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0); - if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) { - triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/ - } + const targetCallSignature = checker.getResolvedSignature(node); + if (!targetCallSignature) { + return; + } - const paramName = param.getName(); - if (triviaContent !== paramName && triviaContent !== paramName + ":") { - this.addFailure(this.createFailure(arg.getStart(source), arg.getWidth(source), Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent))); - } - } + const targetParameters = targetCallSignature.getParameters(); + for (let index = 0; index < targetParameters.length; index++) { + const param = targetParameters[index]; + const arg = node.arguments[index]; + if (!(arg && param)) { + continue; + } + + const argType = checker.getContextualType(arg); + if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) { + if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) { + continue; + } + let triviaContent: string | undefined; + const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0); + if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) { + triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/ + } + + const paramName = param.getName(); + if (triviaContent !== paramName && triviaContent !== paramName + ":") { + ctx.addFailureAtNode(arg, Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent)); } } } } -} +} \ No newline at end of file diff --git a/scripts/tslint/nextLineRule.ts b/scripts/tslint/nextLineRule.ts index 2dee393bd84..b149d09eb38 100644 --- a/scripts/tslint/nextLineRule.ts +++ b/scripts/tslint/nextLineRule.ts @@ -9,50 +9,56 @@ export class Rule extends Lint.Rules.AbstractRule { public static ELSE_FAILURE_STRING = "'else' should not be on the same line as the preceeding block's curly brace"; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NextLineWalker(sourceFile, this.getOptions())); + const options = this.getOptions().ruleArguments; + const checkCatch = options.indexOf(OPTION_CATCH) !== -1; + const checkElse = options.indexOf(OPTION_ELSE) !== -1; + return this.applyWithFunction(sourceFile, ctx => walk(ctx, checkCatch, checkElse)); } } -class NextLineWalker extends Lint.RuleWalker { - public visitIfStatement(node: ts.IfStatement) { - const sourceFile = node.getSourceFile(); - const thenStatement = node.thenStatement; - - const elseStatement = node.elseStatement; - if (!!elseStatement) { - // find the else keyword - const elseKeyword = getFirstChildOfKind(node, ts.SyntaxKind.ElseKeyword); - if (this.hasOption(OPTION_ELSE) && !!elseKeyword) { - const thenStatementEndLoc = sourceFile.getLineAndCharacterOfPosition(thenStatement.getEnd()); - const elseKeywordLoc = sourceFile.getLineAndCharacterOfPosition(elseKeyword.getStart(sourceFile)); - if (thenStatementEndLoc.line === elseKeywordLoc.line) { - const failure = this.createFailure(elseKeyword.getStart(sourceFile), elseKeyword.getWidth(sourceFile), Rule.ELSE_FAILURE_STRING); - this.addFailure(failure); - } - } +function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boolean): void { + const { sourceFile } = ctx; + function recur(node: ts.Node): void { + switch (node.kind) { + case ts.SyntaxKind.IfStatement: + checkIf(node as ts.IfStatement); + break; + case ts.SyntaxKind.TryStatement: + checkTry(node as ts.TryStatement); + break; } - - super.visitIfStatement(node); + ts.forEachChild(node, recur); } - public visitTryStatement(node: ts.TryStatement) { - const sourceFile = node.getSourceFile(); - const catchClause = node.catchClause; + function checkIf(node: ts.IfStatement): void { + const { thenStatement, elseStatement } = node; + if (!elseStatement) { + return; + } - // "visit" try block - const tryBlock = node.tryBlock; - - if (this.hasOption(OPTION_CATCH) && !!catchClause) { - const tryClosingBrace = tryBlock.getLastToken(sourceFile); - const catchKeyword = catchClause.getFirstToken(sourceFile); - const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd()); - const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile)); - if (tryClosingBraceLoc.line === catchKeywordLoc.line) { - const failure = this.createFailure(catchKeyword.getStart(sourceFile), catchKeyword.getWidth(sourceFile), Rule.CATCH_FAILURE_STRING); - this.addFailure(failure); + // find the else keyword + const elseKeyword = getFirstChildOfKind(node, ts.SyntaxKind.ElseKeyword); + if (checkElse && !!elseKeyword) { + const thenStatementEndLoc = sourceFile.getLineAndCharacterOfPosition(thenStatement.getEnd()); + const elseKeywordLoc = sourceFile.getLineAndCharacterOfPosition(elseKeyword.getStart(sourceFile)); + if (thenStatementEndLoc.line === elseKeywordLoc.line) { + ctx.addFailureAtNode(elseKeyword, Rule.ELSE_FAILURE_STRING); } } - super.visitTryStatement(node); + } + + function checkTry({ tryBlock, catchClause }: ts.TryStatement): void { + if (!checkCatch || !catchClause) { + return; + } + + const tryClosingBrace = tryBlock.getLastToken(sourceFile); + const catchKeyword = catchClause.getFirstToken(sourceFile); + const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd()); + const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile)); + if (tryClosingBraceLoc.line === catchKeywordLoc.line) { + ctx.addFailureAtNode(catchKeyword, Rule.CATCH_FAILURE_STRING); + } } } diff --git a/scripts/tslint/noBomRule.ts b/scripts/tslint/noBomRule.ts new file mode 100644 index 00000000000..105e2d2d68c --- /dev/null +++ b/scripts/tslint/noBomRule.ts @@ -0,0 +1,16 @@ +import * as Lint from "tslint/lib"; +import * as ts from "typescript"; + +export class Rule extends Lint.Rules.AbstractRule { + public static FAILURE_STRING = "This file has a BOM."; + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithFunction(sourceFile, walk); + } +} + +function walk(ctx: Lint.WalkContext): void { + if (ctx.sourceFile.text[0] === "\ufeff") { + ctx.addFailure(0, 1, Rule.FAILURE_STRING); + } +} diff --git a/scripts/tslint/noInOperatorRule.ts b/scripts/tslint/noInOperatorRule.ts index 307f0dffd6a..95f052ccaa6 100644 --- a/scripts/tslint/noInOperatorRule.ts +++ b/scripts/tslint/noInOperatorRule.ts @@ -1,20 +1,19 @@ import * as Lint from "tslint/lib"; import * as ts from "typescript"; - export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "Don't use the 'in' keyword - use 'hasProperty' to check for key presence instead"; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new InWalker(sourceFile, this.getOptions())); + return this.applyWithFunction(sourceFile, walk); } } -class InWalker extends Lint.RuleWalker { - visitNode(node: ts.Node) { - super.visitNode(node); - if (node.kind === ts.SyntaxKind.InKeyword && node.parent && node.parent.kind === ts.SyntaxKind.BinaryExpression) { - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); +function walk(ctx: Lint.WalkContext): void { + ts.forEachChild(ctx.sourceFile, recur); + function recur(node: ts.Node): void { + if (node.kind === ts.SyntaxKind.InKeyword && node.parent.kind === ts.SyntaxKind.BinaryExpression) { + ctx.addFailureAtNode(node, Rule.FAILURE_STRING); } } } diff --git a/scripts/tslint/noIncrementDecrementRule.ts b/scripts/tslint/noIncrementDecrementRule.ts index 2a957b36af5..ff2d81b1962 100644 --- a/scripts/tslint/noIncrementDecrementRule.ts +++ b/scripts/tslint/noIncrementDecrementRule.ts @@ -1,44 +1,55 @@ import * as Lint from "tslint/lib"; import * as ts from "typescript"; - export class Rule extends Lint.Rules.AbstractRule { public static POSTFIX_FAILURE_STRING = "Don't use '++' or '--' postfix operators outside statements or for loops."; public static PREFIX_FAILURE_STRING = "Don't use '++' or '--' prefix operators."; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new IncrementDecrementWalker(sourceFile, this.getOptions())); + return this.applyWithFunction(sourceFile, walk); } } -class IncrementDecrementWalker extends Lint.RuleWalker { +function walk(ctx: Lint.WalkContext): void { + ts.forEachChild(ctx.sourceFile, recur); + function recur(node: ts.Node): void { + switch (node.kind) { + case ts.SyntaxKind.PrefixUnaryExpression: + const { operator } = node as ts.PrefixUnaryExpression; + if (operator === ts.SyntaxKind.PlusPlusToken || operator === ts.SyntaxKind.MinusMinusToken) { + check(node as ts.PrefixUnaryExpression); + } + break; - visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) { - super.visitPostfixUnaryExpression(node); - if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { - this.visitIncrementDecrement(node); + case ts.SyntaxKind.PostfixUnaryExpression: + check(node as ts.PostfixUnaryExpression); + break; } } - visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) { - super.visitPrefixUnaryExpression(node); - if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.PREFIX_FAILURE_STRING)); + function check(node: ts.UnaryExpression): void { + if (!isAllowedLocation(node.parent!)) { + ctx.addFailureAtNode(node, Rule.POSTFIX_FAILURE_STRING); } } - - visitIncrementDecrement(node: ts.UnaryExpression) { - if (node.parent && ( - // Can be a statement - node.parent.kind === ts.SyntaxKind.ExpressionStatement || - // Can be directly in a for-statement - node.parent.kind === ts.SyntaxKind.ForStatement || - // Can be in a comma operator in a for statement (`for (let a = 0, b = 10; a < b; a++, b--)`) - node.parent.kind === ts.SyntaxKind.BinaryExpression && - (node.parent).operatorToken.kind === ts.SyntaxKind.CommaToken && - node.parent.parent.kind === ts.SyntaxKind.ForStatement)) { - return; - } - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.POSTFIX_FAILURE_STRING)); - } +} + +function isAllowedLocation(node: ts.Node): boolean { + switch (node.kind) { + // Can be a statement + case ts.SyntaxKind.ExpressionStatement: + return true; + + // Can be directly in a for-statement + case ts.SyntaxKind.ForStatement: + return true; + + // Can be in a comma operator in a for statement (`for (let a = 0, b = 10; a < b; a++, b--)`) + case ts.SyntaxKind.BinaryExpression: + return (node as ts.BinaryExpression).operatorToken.kind === ts.SyntaxKind.CommaToken && + node.parent!.kind === ts.SyntaxKind.ForStatement; + + default: + return false; + } } diff --git a/scripts/tslint/noTypeAssertionWhitespaceRule.ts b/scripts/tslint/noTypeAssertionWhitespaceRule.ts index 5368dcf74ba..37017fb60e4 100644 --- a/scripts/tslint/noTypeAssertionWhitespaceRule.ts +++ b/scripts/tslint/noTypeAssertionWhitespaceRule.ts @@ -1,25 +1,25 @@ import * as Lint from "tslint/lib"; 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())); + return this.applyWithFunction(sourceFile, walk); } } -class TypeAssertionWhitespaceWalker extends Lint.RuleWalker { - public visitNode(node: ts.Node) { +function walk(ctx: Lint.WalkContext): void { + ts.forEachChild(ctx.sourceFile, recur); + function recur(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)); + ctx.addFailure(leftSideWhitespaceStart, rightSideWhitespaceEnd, Rule.TRAILING_FAILURE_STRING); } } - super.visitNode(node); + ts.forEachChild(node, recur); } } diff --git a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts index a705e56c969..8546aa6c973 100644 --- a/scripts/tslint/objectLiteralSurroundingSpaceRule.ts +++ b/scripts/tslint/objectLiteralSurroundingSpaceRule.ts @@ -1,7 +1,6 @@ import * as Lint from "tslint/lib"; 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."; @@ -9,34 +8,37 @@ export class Rule extends Lint.Rules.AbstractRule { 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())); + return this.applyWithFunction(sourceFile, walk); } } -class ObjectLiteralSpaceWalker extends Lint.RuleWalker { - public visitNode(node: ts.Node) { +function walk(ctx: Lint.WalkContext): void { + const { sourceFile } = ctx; + ts.forEachChild(sourceFile, recur); + function recur(node: ts.Node): void { if (node.kind === ts.SyntaxKind.ObjectLiteralExpression) { - const literal = node as ts.ObjectLiteralExpression; - const text = literal.getText(); - if (text.match(/^{[^\n]+}$/g)) { - if (text.charAt(1) !== " ") { - 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); - } - } + check(node as ts.ObjectLiteralExpression); + } + ts.forEachChild(node, recur); + } + + function check(node: ts.ObjectLiteralExpression): void { + const text = node.getText(sourceFile); + if (!text.match(/^{[^\n]+}$/g)) { + return; + } + + if (text.charAt(1) !== " ") { + ctx.addFailureAtNode(node, Rule.LEADING_FAILURE_STRING); + } + if (text.charAt(2) === " ") { + ctx.addFailureAt(node.pos + 2, 1, Rule.LEADING_EXCESS_FAILURE_STRING); + } + if (text.charAt(text.length - 2) !== " ") { + ctx.addFailureAtNode(node, Rule.TRAILING_FAILURE_STRING); + } + if (text.charAt(text.length - 3) === " ") { + ctx.addFailureAt(node.pos + node.getWidth() - 3, 1, Rule.TRAILING_EXCESS_FAILURE_STRING); } - super.visitNode(node); } } diff --git a/scripts/tslint/tsconfig.json b/scripts/tslint/tsconfig.json index db018ce2776..c9bf8dc01dc 100644 --- a/scripts/tslint/tsconfig.json +++ b/scripts/tslint/tsconfig.json @@ -1,6 +1,11 @@ { "compilerOptions": { "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strictNullChecks": true, "module": "commonjs", "outDir": "../../built/local/tslint" } diff --git a/scripts/tslint/typeOperatorSpacingRule.ts b/scripts/tslint/typeOperatorSpacingRule.ts index 50f2971a0ee..4bd70e6eefa 100644 --- a/scripts/tslint/typeOperatorSpacingRule.ts +++ b/scripts/tslint/typeOperatorSpacingRule.ts @@ -1,34 +1,36 @@ import * as Lint from "tslint/lib"; import * as ts from "typescript"; - export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "The '|' and '&' operators must be surrounded by single spaces"; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new TypeOperatorSpacingWalker(sourceFile, this.getOptions())); + return this.applyWithFunction(sourceFile, walk); } } -class TypeOperatorSpacingWalker extends Lint.RuleWalker { - public visitNode(node: ts.Node) { +function walk(ctx: Lint.WalkContext): void { + const { sourceFile } = ctx; + ts.forEachChild(sourceFile, recur); + function recur(node: ts.Node): void { if (node.kind === ts.SyntaxKind.UnionType || node.kind === ts.SyntaxKind.IntersectionType) { - const types = (node).types; - let expectedStart = types[0].end + 2; // space, | or & - for (let i = 1; i < types.length; i++) { - const currentType = types[i]; - if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) { - const sourceFile = currentType.getSourceFile(); - const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end); - const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos); - if (previousTypeEndPos.line === currentTypeStartPos.line) { - const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING); - this.addFailure(failure); - } - } - expectedStart = currentType.end + 2; - } + check((node as ts.UnionOrIntersectionTypeNode).types); + } + ts.forEachChild(node, recur); + } + + function check(types: ts.TypeNode[]): void { + let expectedStart = types[0].end + 2; // space, | or & + for (let i = 1; i < types.length; i++) { + const currentType = types[i]; + if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) { + const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end); + const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos); + if (previousTypeEndPos.line === currentTypeStartPos.line) { + ctx.addFailureAtNode(currentType, Rule.FAILURE_STRING); + } + } + expectedStart = currentType.end + 2; } - super.visitNode(node); } } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index bb37394ae24..418905e604c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1903,7 +1903,7 @@ namespace ts { // Even though in the AST the jsdoc @typedef node belongs to the current node, // its symbol might be in the same scope with the current node's symbol. Consider: - // + // // /** @typedef {string | number} MyType */ // function foo(); // diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 22c294d0243..39397837ff3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1,4 +1,4 @@ -/// +/// /// /* @internal */ diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index dc692972891..4b3dc23d565 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/compiler/core.ts b/src/compiler/core.ts index c3c0ba77fe4..c380a39611d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 05b40472c3c..b10f2e7cb17 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index cfafaabebff..3ff3bc2782f 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index cf50ab6482b..2a15df80102 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1,4 +1,4 @@ -/// +/// declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; declare function clearTimeout(handle: any): void; diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index d51fdb12ac3..bb1732b57ea 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 57e85f50f39..e55cfc76db3 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -1,4 +1,4 @@ -/// +/// /// // Transforms generator functions into a compatible ES5 representation with similar runtime diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index c1f18e2021b..80a8c985c56 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 7488c51ed91..1a362c47fd1 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index b3696c31153..885f8fad898 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index b1ffcff43a4..32b6a90e268 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f96f8623885..759d2a98660 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,4 +1,4 @@ -namespace ts { +namespace ts { /** * Type of objects whose values are all of the same type. * The `in` and `for-in` operators can *not* be safely used, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 46eccef66ad..a5229b614be 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// /* @internal */ namespace ts { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 2d75d646128..0f4a4ed6561 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2532a1875d9..0df9f4f4dd2 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1,4 +1,4 @@ -// +// // Copyright (c) Microsoft Corporation. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index caeab18958e..5ea45d2a5f6 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -1,4 +1,4 @@ -/// +/// namespace ts { interface File { diff --git a/src/harness/unittests/initializeTSConfig.ts b/src/harness/unittests/initializeTSConfig.ts index cb995212a94..ab9aaea0001 100644 --- a/src/harness/unittests/initializeTSConfig.ts +++ b/src/harness/unittests/initializeTSConfig.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts { diff --git a/src/harness/unittests/reuseProgramStructure.ts b/src/harness/unittests/reuseProgramStructure.ts index d13dd7a26fa..c9ecef0de44 100644 --- a/src/harness/unittests/reuseProgramStructure.ts +++ b/src/harness/unittests/reuseProgramStructure.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts { diff --git a/src/harness/unittests/services/colorization.ts b/src/harness/unittests/services/colorization.ts index 70592ea4151..fd7d932885a 100644 --- a/src/harness/unittests/services/colorization.ts +++ b/src/harness/unittests/services/colorization.ts @@ -1,4 +1,4 @@ -/// +/// interface ClassificationEntry { value: any; diff --git a/src/harness/unittests/services/preProcessFile.ts b/src/harness/unittests/services/preProcessFile.ts index 403cccc8cf3..b7d319a690f 100644 --- a/src/harness/unittests/services/preProcessFile.ts +++ b/src/harness/unittests/services/preProcessFile.ts @@ -1,4 +1,4 @@ -/// +/// describe("PreProcessFile:", function () { function test(sourceText: string, readImportFile: boolean, detectJavaScriptImports: boolean, expectedPreProcess: ts.PreProcessedFileInfo): void { diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 8d306a6099b..d3ea153e235 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -1,4 +1,4 @@ -/// +/// const expect: typeof _chai.expect = _chai.expect; diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 1531b18bb9d..4d1b2a0b10c 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts.projectSystem { diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 2eae01c3520..12e62aaa7b9 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/server/cancellationToken/cancellationToken.ts b/src/server/cancellationToken/cancellationToken.ts index 71a31d14016..0e7969c1e45 100644 --- a/src/server/cancellationToken/cancellationToken.ts +++ b/src/server/cancellationToken/cancellationToken.ts @@ -37,7 +37,7 @@ function createCancellationToken(args: string[]): ServerCancellationToken { // when client wants to signal cancellation it should create a named pipe with name= // server will synchronously check the presence of the pipe and treat its existance as indicator that current request should be canceled. // in case if client prefers to use more fine-grained schema than one name for all request it can add '*' to the end of cancelellationPipeName. - // in this case pipe name will be build dynamically as . + // in this case pipe name will be build dynamically as . if (cancellationPipeName.charAt(cancellationPipeName.length - 1) === "*") { const namePrefix = cancellationPipeName.slice(0, -1); if (namePrefix.length === 0 || namePrefix.indexOf("*") >= 0) { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index cbbe23650fb..397de9ead30 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/server/project.ts b/src/server/project.ts index 339f0288688..385816b1029 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 447a2c05429..0a69d701953 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -1,4 +1,4 @@ -/// +/// /// namespace ts.server.typingsInstaller { diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index e889f98789a..fa533450b26 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// diff --git a/src/services/codeFixProvider.ts b/src/services/codeFixProvider.ts index 10d0b8eef34..c22ba779d19 100644 --- a/src/services/codeFixProvider.ts +++ b/src/services/codeFixProvider.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts { export interface CodeFix { errorCodes: number[]; diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 1c157257051..3e07efbc3de 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.codefix { type ImportCodeActionKind = "CodeChange" | "InsertingIntoExistingImport" | "NewImport"; diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index a45a3c26dba..61d48bdc3bc 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.codefix { registerCodeFix({ errorCodes: [ diff --git a/src/services/documentRegistry.ts b/src/services/documentRegistry.ts index 80b0133ccfe..e2cd20a4463 100644 --- a/src/services/documentRegistry.ts +++ b/src/services/documentRegistry.ts @@ -1,4 +1,4 @@ -namespace ts { +namespace ts { /** * The document registry represents a store of SourceFile objects that can be shared between * multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index b6a8f5b5d23..bc1e50391c8 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.FindAllReferences { export function findReferencedSymbols(typeChecker: TypeChecker, cancellationToken: CancellationToken, sourceFiles: SourceFile[], sourceFile: SourceFile, position: number, findInStrings: boolean, findInComments: boolean, isForRename: boolean): ReferencedSymbol[] | undefined { const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true); diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index b732d8a1193..f2602903be3 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.GoToDefinition { export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile, position: number): DefinitionInfo[] { /// Triple slash reference comments diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index a2a32f95fa4..d0cf8c0aec8 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.JsDoc { const jsDocTagNames = [ "augments", diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index 248ceef1bd3..e7196e8f491 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. +// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. /// diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index 05ccbcc71f4..2c8d43b535b 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -1,4 +1,4 @@ -/* @internal */ +/* @internal */ namespace ts.NavigateTo { type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration }; diff --git a/src/services/services.ts b/src/services/services.ts index f122e39bcc6..df5330ebaed 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/src/services/transpile.ts b/src/services/transpile.ts index 86c6a3e8904..89ddb887809 100644 --- a/src/services/transpile.ts +++ b/src/services/transpile.ts @@ -1,4 +1,4 @@ -namespace ts { +namespace ts { export interface TranspileOptions { compilerOptions?: CompilerOptions; fileName?: string; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a4f574b9c28..7c5bf862fc8 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1,4 +1,4 @@ -// These utilities are common to multiple language service features. +// These utilities are common to multiple language service features. /* @internal */ namespace ts { export const scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); diff --git a/tslint.json b/tslint.json index 3952d4fac29..5e72aedf065 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,6 @@ { "rules": { + "no-bom": true, "class-name": true, "comment-format": [true, "check-space"