diff --git a/Jakefile.js b/Jakefile.js index bfb80982237..5a3348a61eb 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -108,17 +108,6 @@ var serverCoreSources = [ return path.join(serverDirectory, f); }); -var scriptSources = [ - "tslint/booleanTriviaRule.ts", - "tslint/nextLineRule.ts", - "tslint/noNullRule.ts", - "tslint/preferConstRule.ts", - "tslint/typeOperatorSpacingRule.ts", - "tslint/noInOperatorRule.ts" -].map(function (f) { - return path.join(scriptsDirectory, f); -}); - var serverSources = serverCoreSources.concat(servicesSources); var languageServiceLibrarySources = [ @@ -878,7 +867,8 @@ var tslintRules = ([ "preferConstRule", "booleanTriviaRule", "typeOperatorSpacingRule", - "noInOperatorRule" + "noInOperatorRule", + "noIncrementDecrementRule" ]); var tslintRulesFiles = tslintRules.map(function(p) { return path.join(tslintRuleDir, p + ".ts"); @@ -932,7 +922,7 @@ var servicesLintTargets = [ var lintTargets = compilerSources .concat(harnessCoreSources) .concat(serverCoreSources) - .concat(scriptSources) + .concat(tslintRulesFiles) .concat(servicesLintTargets); desc("Runs tslint on the compiler sources"); diff --git a/scripts/tslint/noIncrementDecrementRule.ts b/scripts/tslint/noIncrementDecrementRule.ts new file mode 100644 index 00000000000..75f4d2f5c08 --- /dev/null +++ b/scripts/tslint/noIncrementDecrementRule.ts @@ -0,0 +1,37 @@ +import * as Lint from "tslint/lib/lint"; +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())); + } +} + +class IncrementDecrementWalker extends Lint.RuleWalker { + + visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) { + super.visitPostfixUnaryExpression(node); + if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { + this.visitIncrementDecrement(node); + } + } + + 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)); + } + } + + visitIncrementDecrement(node: ts.UnaryExpression) { + if (node.parent && (node.parent.kind === ts.SyntaxKind.ExpressionStatement || + node.parent.kind === ts.SyntaxKind.ForStatement)) { + return; + } + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.POSTFIX_FAILURE_STRING)); + } +} diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 145478693a1..eb0338c9f57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7,7 +7,10 @@ namespace ts { let nextMergeId = 1; export function getNodeId(node: Node): number { - if (!node.id) node.id = nextNodeId++; + if (!node.id) { + node.id = nextNodeId; + nextNodeId++; + } return node.id; } @@ -15,7 +18,8 @@ namespace ts { export function getSymbolId(symbol: Symbol): number { if (!symbol.id) { - symbol.id = nextSymbolId++; + symbol.id = nextSymbolId; + nextSymbolId++; } return symbol.id; @@ -287,7 +291,10 @@ namespace ts { } function recordMergedSymbol(target: Symbol, source: Symbol) { - if (!source.mergeId) source.mergeId = nextMergeId++; + if (!source.mergeId) { + source.mergeId = nextMergeId; + nextMergeId++; + } mergedSymbols[source.mergeId] = target; } @@ -1267,7 +1274,8 @@ namespace ts { function createType(flags: TypeFlags): Type { const result = new Type(checker, flags); - result.id = typeCount++; + result.id = typeCount; + typeCount++; return result; } @@ -1823,11 +1831,13 @@ namespace ts { } if (pos < end) { writePunctuation(writer, SyntaxKind.LessThanToken); - writeType(typeArguments[pos++], TypeFormatFlags.None); + writeType(typeArguments[pos], TypeFormatFlags.None); + pos++; while (pos < end) { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); - writeType(typeArguments[pos++], TypeFormatFlags.None); + writeType(typeArguments[pos], TypeFormatFlags.None); + pos++; } writePunctuation(writer, SyntaxKind.GreaterThanToken); } @@ -5676,7 +5686,7 @@ namespace ts { return Ternary.False; } let result = Ternary.True; - for (let i = 0, len = sourceSignatures.length; i < len; ++i) { + for (let i = 0, len = sourceSignatures.length; i < len; i++) { const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return Ternary.False; @@ -13839,7 +13849,8 @@ namespace ts { } if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; + getNodeLinks(member).enumMemberValue = autoValue; + autoValue++; } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 034b7022e82..367fcf48c0d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -334,7 +334,8 @@ namespace ts { function parseStrings(args: string[]) { let i = 0; while (i < args.length) { - let s = args[i++]; + let s = args[i]; + i++; if (s.charCodeAt(0) === CharacterCodes.at) { parseResponseFile(s.slice(1)); } @@ -356,18 +357,21 @@ namespace ts { switch (opt.type) { case "number": - options[opt.name] = parseInt(args[i++]); + options[opt.name] = parseInt(args[i]); + i++; break; case "boolean": options[opt.name] = true; break; case "string": - options[opt.name] = args[i++] || ""; + options[opt.name] = args[i] || ""; + i++; break; // If not a primitive, the possible types are specified in what is effectively a map of options. default: let map = >opt.type; - let key = (args[i++] || "").toLowerCase(); + let key = (args[i] || "").toLowerCase(); + i++; if (hasProperty(map, key)) { options[opt.name] = map[key]; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ad434d4cfad..1ae130f0f2d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -244,9 +244,11 @@ namespace ts { const count = array.length; if (count > 0) { let pos = 0; - let result = arguments.length <= 2 ? array[pos++] : initial; + let result = arguments.length <= 2 ? array[pos] : initial; + pos++; while (pos < count) { - result = f(result, array[pos++]); + result = f(result, array[pos]); + pos++; } return result; } @@ -260,9 +262,11 @@ namespace ts { if (array) { let pos = array.length - 1; if (pos >= 0) { - let result = arguments.length <= 2 ? array[pos--] : initial; + let result = arguments.length <= 2 ? array[pos] : initial; + pos--; while (pos >= 0) { - result = f(result, array[pos--]); + result = f(result, array[pos]); + pos--; } return result; } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index d0c5cbff48b..75319d0ab51 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -501,7 +501,8 @@ namespace ts { } let count = 0; while (true) { - const name = baseName + "_" + (++count); + count++; + const name = baseName + "_" + count; if (!hasProperty(currentIdentifiers, name)) { return name; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c266a0fa77e..174ddb68546 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5464,7 +5464,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi }); leadingComma = true; } - ++parameterIndex; + parameterIndex++; } } return argumentsWritten; @@ -6488,7 +6488,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let started = false; if (exportedDeclarations) { - for (let i = 0; i < exportedDeclarations.length; ++i) { + for (let i = 0; i < exportedDeclarations.length; i++) { // write name of exported declaration, i.e 'export var x...' writeExportedName(exportedDeclarations[i]); } @@ -6604,7 +6604,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLine(); write("var "); const seen: Map = {}; - for (let i = 0; i < hoistedVars.length; ++i) { + for (let i = 0; i < hoistedVars.length; i++) { const local = hoistedVars[i]; const name = local.kind === SyntaxKind.Identifier ? local @@ -6816,7 +6816,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitSetters(exportStarFunction: string, dependencyGroups: DependencyGroup[]) { write("setters:["); - for (let i = 0; i < dependencyGroups.length; ++i) { + for (let i = 0; i < dependencyGroups.length; i++) { if (i !== 0) { write(","); } @@ -6864,7 +6864,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(`${exportFunctionForFile}({`); writeLine(); increaseIndent(); - for (let i = 0, len = (entry).exportClause.elements.length; i < len; ++i) { + for (let i = 0, len = (entry).exportClause.elements.length; i < len; i++) { if (i !== 0) { write(","); writeLine(); @@ -6909,7 +6909,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("execute: function() {"); increaseIndent(); writeLine(); - for (let i = startIndex; i < node.statements.length; ++i) { + for (let i = startIndex; i < node.statements.length; i++) { const statement = node.statements[i]; switch (statement.kind) { // - function declarations are not emitted because they were already hoisted @@ -6971,7 +6971,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi const groupIndices: Map = {}; const dependencyGroups: DependencyGroup[] = []; - for (let i = 0; i < externalImports.length; ++i) { + for (let i = 0; i < externalImports.length; i++) { const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName); if (hasProperty(groupIndices, text)) { // deduplicate/group entries in dependency list by the dependency name @@ -7296,7 +7296,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean, ensureUseStrict?: boolean): number { let foundUseStrict = false; - for (let i = 0; i < statements.length; ++i) { + for (let i = 0; i < statements.length; i++) { if (isPrologueDirective(statements[i])) { if (isUseStrictPrologue(statements[i] as ExpressionStatement)) { foundUseStrict = true; @@ -7318,7 +7318,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function writeLines(text: string): void { const lines = text.split(/\r\n|\r|\n/g); - for (let i = 0; i < lines.length; ++i) { + for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (line.length) { writeLine(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d5c8b9f913f..c9de6a0ed96 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -495,7 +495,7 @@ namespace ts { const moduleNames = map(newSourceFile.imports, name => name.text); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory)); // ensure that module resolution results are still correct - for (let i = 0; i < moduleNames.length; ++i) { + for (let i = 0; i < moduleNames.length; i++) { const newResolution = resolutions[i]; const oldResolution = getResolvedModule(oldSourceFile, moduleNames[i]); const resolutionChanged = oldResolution @@ -523,7 +523,7 @@ namespace ts { } // update fileName -> file mapping - for (let i = 0, len = newSourceFiles.length; i < len; ++i) { + for (let i = 0, len = newSourceFiles.length; i < len; i++) { filesByName.set(filePaths[i], newSourceFiles[i]); } @@ -1073,7 +1073,7 @@ namespace ts { file.resolvedModules = {}; const moduleNames = map(file.imports, name => name.text); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory)); - for (let i = 0; i < file.imports.length; ++i) { + for (let i = 0; i < file.imports.length; i++) { const resolution = resolutions[i]; setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 022d63fbe9d..6c0489ff1dc 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -288,7 +288,8 @@ namespace ts { let pos = 0; let lineStart = 0; while (pos < text.length) { - const ch = text.charCodeAt(pos++); + const ch = text.charCodeAt(pos); + pos++; switch (ch) { case CharacterCodes.carriageReturn: if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { @@ -823,7 +824,8 @@ namespace ts { } function scanString(): string { - const quote = text.charCodeAt(pos++); + const quote = text.charCodeAt(pos); + pos++; let result = ""; let start = pos; while (true) { @@ -933,7 +935,8 @@ namespace ts { error(Diagnostics.Unexpected_end_of_text); return ""; } - const ch = text.charCodeAt(pos++); + const ch = text.charCodeAt(pos); + pos++; switch (ch) { case CharacterCodes._0: return "\0"; @@ -1182,7 +1185,8 @@ namespace ts { } return pos += 2, token = SyntaxKind.ExclamationEqualsToken; } - return pos++, token = SyntaxKind.ExclamationToken; + pos++; + return token = SyntaxKind.ExclamationToken; case CharacterCodes.doubleQuote: case CharacterCodes.singleQuote: tokenValue = scanString(); @@ -1193,7 +1197,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PercentEqualsToken; } - return pos++, token = SyntaxKind.PercentToken; + pos++; + return token = SyntaxKind.PercentToken; case CharacterCodes.ampersand: if (text.charCodeAt(pos + 1) === CharacterCodes.ampersand) { return pos += 2, token = SyntaxKind.AmpersandAmpersandToken; @@ -1201,11 +1206,14 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.AmpersandEqualsToken; } - return pos++, token = SyntaxKind.AmpersandToken; + pos++; + return token = SyntaxKind.AmpersandToken; case CharacterCodes.openParen: - return pos++, token = SyntaxKind.OpenParenToken; + pos++; + return token = SyntaxKind.OpenParenToken; case CharacterCodes.closeParen: - return pos++, token = SyntaxKind.CloseParenToken; + pos++; + return token = SyntaxKind.CloseParenToken; case CharacterCodes.asterisk: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.AsteriskEqualsToken; @@ -1216,7 +1224,8 @@ namespace ts { } return pos += 2, token = SyntaxKind.AsteriskAsteriskToken; } - return pos++, token = SyntaxKind.AsteriskToken; + pos++; + return token = SyntaxKind.AsteriskToken; case CharacterCodes.plus: if (text.charCodeAt(pos + 1) === CharacterCodes.plus) { return pos += 2, token = SyntaxKind.PlusPlusToken; @@ -1224,9 +1233,11 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PlusEqualsToken; } - return pos++, token = SyntaxKind.PlusToken; + pos++; + return token = SyntaxKind.PlusToken; case CharacterCodes.comma: - return pos++, token = SyntaxKind.CommaToken; + pos++; + return token = SyntaxKind.CommaToken; case CharacterCodes.minus: if (text.charCodeAt(pos + 1) === CharacterCodes.minus) { return pos += 2, token = SyntaxKind.MinusMinusToken; @@ -1234,7 +1245,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.MinusEqualsToken; } - return pos++, token = SyntaxKind.MinusToken; + pos++; + return token = SyntaxKind.MinusToken; case CharacterCodes.dot: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); @@ -1243,7 +1255,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.dot && text.charCodeAt(pos + 2) === CharacterCodes.dot) { return pos += 3, token = SyntaxKind.DotDotDotToken; } - return pos++, token = SyntaxKind.DotToken; + pos++; + return token = SyntaxKind.DotToken; case CharacterCodes.slash: // Single-line comment if (text.charCodeAt(pos + 1) === CharacterCodes.slash) { @@ -1301,7 +1314,8 @@ namespace ts { return pos += 2, token = SyntaxKind.SlashEqualsToken; } - return pos++, token = SyntaxKind.SlashToken; + pos++; + return token = SyntaxKind.SlashToken; case CharacterCodes._0: if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) { @@ -1354,9 +1368,11 @@ namespace ts { tokenValue = scanNumber(); return token = SyntaxKind.NumericLiteral; case CharacterCodes.colon: - return pos++, token = SyntaxKind.ColonToken; + pos++; + return token = SyntaxKind.ColonToken; case CharacterCodes.semicolon: - return pos++, token = SyntaxKind.SemicolonToken; + pos++; + return token = SyntaxKind.SemicolonToken; case CharacterCodes.lessThan: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1382,7 +1398,8 @@ namespace ts { text.charCodeAt(pos + 2) !== CharacterCodes.asterisk) { return pos += 2, token = SyntaxKind.LessThanSlashToken; } - return pos++, token = SyntaxKind.LessThanToken; + pos++; + return token = SyntaxKind.LessThanToken; case CharacterCodes.equals: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1403,7 +1420,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.greaterThan) { return pos += 2, token = SyntaxKind.EqualsGreaterThanToken; } - return pos++, token = SyntaxKind.EqualsToken; + pos++; + return token = SyntaxKind.EqualsToken; case CharacterCodes.greaterThan: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1415,20 +1433,26 @@ namespace ts { } } - return pos++, token = SyntaxKind.GreaterThanToken; + pos++; + return token = SyntaxKind.GreaterThanToken; case CharacterCodes.question: - return pos++, token = SyntaxKind.QuestionToken; + pos++; + return token = SyntaxKind.QuestionToken; case CharacterCodes.openBracket: - return pos++, token = SyntaxKind.OpenBracketToken; + pos++; + return token = SyntaxKind.OpenBracketToken; case CharacterCodes.closeBracket: - return pos++, token = SyntaxKind.CloseBracketToken; + pos++; + return token = SyntaxKind.CloseBracketToken; case CharacterCodes.caret: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.CaretEqualsToken; } - return pos++, token = SyntaxKind.CaretToken; + pos++; + return token = SyntaxKind.CaretToken; case CharacterCodes.openBrace: - return pos++, token = SyntaxKind.OpenBraceToken; + pos++; + return token = SyntaxKind.OpenBraceToken; case CharacterCodes.bar: if (text.charCodeAt(pos + 1) === CharacterCodes.bar) { return pos += 2, token = SyntaxKind.BarBarToken; @@ -1436,13 +1460,17 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.BarEqualsToken; } - return pos++, token = SyntaxKind.BarToken; + pos++; + return token = SyntaxKind.BarToken; case CharacterCodes.closeBrace: - return pos++, token = SyntaxKind.CloseBraceToken; + pos++; + return token = SyntaxKind.CloseBraceToken; case CharacterCodes.tilde: - return pos++, token = SyntaxKind.TildeToken; + pos++; + return token = SyntaxKind.TildeToken; case CharacterCodes.at: - return pos++, token = SyntaxKind.AtToken; + pos++; + return token = SyntaxKind.AtToken; case CharacterCodes.backslash: let cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { @@ -1451,7 +1479,8 @@ namespace ts { return token = getIdentifierToken(); } error(Diagnostics.Invalid_character); - return pos++, token = SyntaxKind.Unknown; + pos++; + return token = SyntaxKind.Unknown; default: if (isIdentifierStart(ch, languageVersion)) { pos++; @@ -1472,7 +1501,8 @@ namespace ts { continue; } error(Diagnostics.Invalid_character); - return pos++, token = SyntaxKind.Unknown; + pos++; + return token = SyntaxKind.Unknown; } } } @@ -1489,10 +1519,12 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.GreaterThanGreaterThanEqualsToken; } - return pos++, token = SyntaxKind.GreaterThanGreaterThanToken; + pos++; + return token = SyntaxKind.GreaterThanGreaterThanToken; } if (text.charCodeAt(pos) === CharacterCodes.equals) { - return pos++, token = SyntaxKind.GreaterThanEqualsToken; + pos++; + return token = SyntaxKind.GreaterThanEqualsToken; } } return token; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c5a31992a80..7bc708c7178 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -92,7 +92,7 @@ namespace ts { return false; } - for (let i = 0; i < array1.length; ++i) { + for (let i = 0; i < array1.length; i++) { const equals = equaler ? equaler(array1[i], array2[i]) : array1[i] === array2[i]; if (!equals) { return false; @@ -1884,8 +1884,8 @@ namespace ts { writeTextOfNode, writeLiteral, writeLine, - increaseIndent: () => indent++, - decreaseIndent: () => indent--, + increaseIndent: () => { indent++; }, + decreaseIndent: () => { indent--; }, getIndent: () => indent, getTextPos: () => output.length, getLine: () => lineCount + 1, diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a078b64543b..8cd1bca876e 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -727,7 +727,7 @@ namespace FourSlash { // Count only the references in local files. Filter the ones in lib and other files. ts.forEach(references, entry => { if (localFiles.some((fileName) => fileName === entry.fileName)) { - ++referencesCount; + referencesCount++; } }); } @@ -1093,7 +1093,7 @@ namespace FourSlash { const emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on const allFourSlashFiles = this.testData.files; - for (let idx = 0; idx < allFourSlashFiles.length; ++idx) { + for (let idx = 0; idx < allFourSlashFiles.length; idx++) { const file = allFourSlashFiles[idx]; if (file.fileOptions[metadataOptionNames.emitThisFile] === "true") { // Find a file with the flag emitThisFile turned on @@ -1853,7 +1853,7 @@ namespace FourSlash { let item: ts.NavigateToItem = null; // Count only the match that match the same MatchKind - for (let i = 0; i < items.length; ++i) { + for (let i = 0; i < items.length; i++) { item = items[i]; if (!matchKind || item.matchKind === matchKind) { actual++; diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 52102663457..96fcfedc6b4 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -307,9 +307,10 @@ class ProjectRunner extends RunnerBase { // If the generated output file resides in the parent folder or is rooted path, // we need to instead create files that can live in the project reference folder // but make sure extension of these files matches with the fileName the compiler asked to write - diskRelativeName = "diskFile" + nonSubfolderDiskFiles++ + + diskRelativeName = "diskFile" + nonSubfolderDiskFiles + (Harness.Compiler.isDTS(fileName) ? ".d.ts" : Harness.Compiler.isJS(fileName) ? ".js" : ".js.map"); + nonSubfolderDiskFiles++; } if (Harness.Compiler.isJS(fileName)) { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 5a1c85fc13c..d78f7d40ef6 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -718,7 +718,8 @@ namespace ts.server { else { for (const directory of project.directoriesWatchedForTsconfig) { // if the ref count for this directory watcher drops to 0, it's time to close it - if (!(--project.projectService.directoryWatchersRefCount[directory])) { + project.projectService.directoryWatchersRefCount[directory]--; + if (!project.projectService.directoryWatchersRefCount[directory]) { this.log("Close directory watcher for: " + directory); project.projectService.directoryWatchersForTsconfig[directory].close(); delete project.projectService.directoryWatchersForTsconfig[directory]; @@ -1730,7 +1731,8 @@ namespace ts.server { let count = 1; let pos = 0; this.index.every((ll, s, len) => { - starts[count++] = pos; + starts[count] = pos; + count++; pos += ll.text.length; return true; }, 0); @@ -1996,7 +1998,8 @@ namespace ts.server { while (adjustedStart >= childCharCount) { this.skipChild(adjustedStart, rangeLength, childIndex, walkFns, CharRangeSection.PreStart); adjustedStart -= childCharCount; - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); } // Case I: both start and end of range in same subtree @@ -2011,14 +2014,16 @@ namespace ts.server { return; } let adjustedLength = rangeLength - (childCharCount - adjustedStart); - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); while (adjustedLength > childCharCount) { if (this.execWalk(0, childCharCount, walkFns, childIndex, CharRangeSection.Mid)) { return; } adjustedLength -= childCharCount; - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); } if (adjustedLength > 0) { @@ -2142,7 +2147,8 @@ namespace ts.server { if (childIndex < clen) { splitNode = new LineNode(); while (childIndex < clen) { - splitNode.add(this.children[childIndex++]); + splitNode.add(this.children[childIndex]); + childIndex++; } splitNode.updateCounts(); } @@ -2183,7 +2189,9 @@ namespace ts.server { let nodeIndex = 0; childIndex++; while ((childIndex < lineCollectionCapacity) && (nodeIndex < nodeCount)) { - this.children[childIndex++] = nodes[nodeIndex++]; + this.children[childIndex] = nodes[nodeIndex]; + childIndex++; + nodeIndex++; } let splitNodes: LineNode[] = []; let splitNodeCount = 0; @@ -2196,7 +2204,8 @@ namespace ts.server { } let splitNode = splitNodes[0]; while (nodeIndex < nodeCount) { - splitNode.add(nodes[nodeIndex++]); + splitNode.add(nodes[nodeIndex]); + nodeIndex++; if (splitNode.children.length === lineCollectionCapacity) { splitNodeIndex++; splitNode = splitNodes[splitNodeIndex]; diff --git a/src/server/session.ts b/src/server/session.ts index 78686b79118..9b9bf35a4a5 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -263,7 +263,8 @@ namespace ts.server { let index = 0; const checkOne = () => { if (matchSeq(seq)) { - const checkSpec = checkList[index++]; + const checkSpec = checkList[index]; + index++; if (checkSpec.project.getSourceFileFromName(checkSpec.fileName, requireOpen)) { this.syntacticCheck(checkSpec.fileName, checkSpec.project); this.immediateId = setImmediate(() => { diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index 3663b1a1d09..93cc5130d72 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -94,7 +94,7 @@ namespace ts { // The spans in this text chunk that we think are of interest and should be matched // independently. For example, if the chunk is for "UIElement" the the spans of interest - // correspond to "U", "I" and "Element". If "UIElement" isn't found as an exaxt, prefix. + // correspond to "U", "I" and "Element". If "UIElement" isn't found as an exact, prefix. // or substring match, then the character spans will be used to attempt a camel case match. characterSpans: TextSpan[]; } @@ -168,7 +168,7 @@ namespace ts { for (let i = dotSeparatedSegments.length - 2, j = candidateContainers.length - 1; i >= 0; - i--, j--) { + i -= 1, j -= 1) { const segment = dotSeparatedSegments[i]; const containerName = candidateContainers[j]; @@ -581,9 +581,10 @@ namespace ts { for (let i = 0; i < pattern.length; i++) { const ch = pattern.charCodeAt(i); if (isWordChar(ch)) { - if (wordLength++ === 0) { + if (wordLength === 0) { wordStart = i; } + wordLength++; } else { if (wordLength > 0) { diff --git a/src/services/services.ts b/src/services/services.ts index 0ffd1138cba..0fd4df19907 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -469,7 +469,8 @@ namespace ts { function pushDocCommentLineText(docComments: SymbolDisplayPart[], text: string, blankLineCount: number) { // Add the empty lines in between texts - while (blankLineCount--) { + while (blankLineCount) { + blankLineCount--; docComments.push(textPart("")); } diff --git a/tslint.json b/tslint.json index 71efb21ad7b..2d2e42d4383 100644 --- a/tslint.json +++ b/tslint.json @@ -42,6 +42,7 @@ "boolean-trivia": true, "type-operator-spacing": true, "prefer-const": true, - "no-in-operator": true + "no-in-operator": true, + "no-increment-decrement": true } }