From 85e646980e7ce7ff6a4554f6bb1664dcee95dd02 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 2 Jun 2017 16:54:15 +0200 Subject: [PATCH] Update tslint dependency (#2851) Don't type-check while linting. We can now use `allow-boolean-or-undefined` option of `strict-boolean-expressions`. This commit removes some explicit comparison to `true`. --- package.json | 4 +-- src/ruleLoader.ts | 2 +- src/rules/adjacentOverloadSignaturesRule.ts | 2 +- src/rules/noDefaultExportRule.ts | 2 +- src/rules/noInternalModuleRule.ts | 2 +- src/rules/noUnsafeAnyRule.ts | 2 +- src/rules/noUnusedVariableRule.ts | 2 +- src/rules/preferObjectSpreadRule.ts | 2 +- src/rules/semicolonRule.ts | 2 +- src/rules/trailingCommaRule.ts | 6 ++-- src/runner.ts | 4 +-- src/test.ts | 4 +-- src/tslint-cli.ts | 4 +-- test/ruleLoaderTests.ts | 8 +++--- yarn.lock | 31 +++++++++++---------- 15 files changed, 39 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index cb19fc1a5c8..655139f17e9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "compile:scripts": "tsc -p scripts", "compile:test": "tsc -p test", "lint": "npm-run-all -p lint:global lint:from-bin", - "lint:global": "tslint --project test/tsconfig.json --format stylish --type-check # test includes 'src' too", + "lint:global": "tslint --project test/tsconfig.json --format stylish # test includes 'src' too", "lint:from-bin": "node bin/tslint --project test/tsconfig.json --format stylish", "test": "npm-run-all test:pre -p test:mocha test:rules", "test:pre": "cd ./test/config && npm install --no-save", @@ -71,7 +71,7 @@ "npm-run-all": "^4.0.2", "nyc": "^10.2.0", "rimraf": "^2.5.4", - "tslint": "latest", + "tslint": "^5.4.2", "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", "typescript": "^2.3.0" }, diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 879618f8677..9b1442b5b44 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -117,7 +117,7 @@ function loadRule(directory: string, ruleName: string): RuleConstructor | "not-f return "not-found"; } -function loadCachedRule(directory: string, ruleName: string, isCustomPath = false): RuleConstructor | undefined { +function loadCachedRule(directory: string, ruleName: string, isCustomPath?: boolean): RuleConstructor | undefined { // use cached value if available const fullPath = path.join(directory, ruleName); const cachedRule = cachedRules.get(fullPath); diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index beb254678b4..c9757f3929c 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -111,7 +111,7 @@ export function getOverloadKey(node: ts.SignatureDeclaration): string | undefine return undefined; } - const [computed, name] = typeof info === "string" ? [false, info] : [info.computed === true, info.name]; + const [computed, name] = typeof info === "string" ? [false, info] : [info.computed, info.name]; const isStatic = Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword); return (computed ? "0" : "1") + (isStatic ? "0" : "1") + name; } diff --git a/src/rules/noDefaultExportRule.ts b/src/rules/noDefaultExportRule.ts index 9e9835be9ad..2ffb7edb9f3 100644 --- a/src/rules/noDefaultExportRule.ts +++ b/src/rules/noDefaultExportRule.ts @@ -50,7 +50,7 @@ function walk(ctx: Lint.WalkContext) { } for (const statement of ctx.sourceFile.statements) { if (statement.kind === ts.SyntaxKind.ExportAssignment) { - if ((statement as ts.ExportAssignment).isExportEquals !== true) { + if (!(statement as ts.ExportAssignment).isExportEquals) { ctx.addFailureAtNode(statement.getChildAt(1, ctx.sourceFile), Rule.FAILURE_STRING); } } else if (statement.modifiers !== undefined && statement.modifiers.length >= 2 && diff --git a/src/rules/noInternalModuleRule.ts b/src/rules/noInternalModuleRule.ts index 574c457f9ee..a447d8996d2 100644 --- a/src/rules/noInternalModuleRule.ts +++ b/src/rules/noInternalModuleRule.ts @@ -55,7 +55,7 @@ class NoInternalModuleWalker extends Lint.AbstractWalker { } private checkModuleDeclaration(node: ts.ModuleDeclaration, nested?: boolean): void { - if (nested !== true && + if (!nested && node.name.kind === ts.SyntaxKind.Identifier && !Lint.isNodeFlagSet(node, ts.NodeFlags.Namespace) && // augmenting global uses a special syntax that is allowed diff --git a/src/rules/noUnsafeAnyRule.ts b/src/rules/noUnsafeAnyRule.ts index 414bf4170fa..b9ba319d2c6 100644 --- a/src/rules/noUnsafeAnyRule.ts +++ b/src/rules/noUnsafeAnyRule.ts @@ -195,7 +195,7 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker): void { } function check(): boolean { - const isUnsafe = anyOk !== true && isNodeAny(node, checker); + const isUnsafe = !anyOk && isNodeAny(node, checker); if (isUnsafe) { ctx.addFailureAtNode(node, Rule.FAILURE_STRING); } diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index c28abc74622..634032956a5 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -68,7 +68,7 @@ export class Rule extends Lint.Rules.TypedRule { public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { const x = program.getCompilerOptions(); - if (x.noUnusedLocals === true && x.noUnusedParameters === true) { + if (x.noUnusedLocals && x.noUnusedParameters) { console.warn("WARNING: 'no-unused-variable' lint rule does not need to be set if " + "the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled."); } diff --git a/src/rules/preferObjectSpreadRule.ts b/src/rules/preferObjectSpreadRule.ts index f5d1b1f59d0..513e550b016 100644 --- a/src/rules/preferObjectSpreadRule.ts +++ b/src/rules/preferObjectSpreadRule.ts @@ -96,7 +96,7 @@ function createFix(node: ts.CallExpression, sourceFile: ts.SourceFile): Lint.Fix let end = arg.end; if (i !== args.length - 1) { end = args[i + 1].getStart(sourceFile); - } else if (args.hasTrailingComma === true) { + } else if (args.hasTrailingComma) { end = args.end; } // remove empty object iteral and the following comma if exists diff --git a/src/rules/semicolonRule.ts b/src/rules/semicolonRule.ts index 4645fc3bb90..baab2f17344 100644 --- a/src/rules/semicolonRule.ts +++ b/src/rules/semicolonRule.ts @@ -105,7 +105,7 @@ abstract class SemicolonWalker extends Lint.AbstractWalker { } } - protected reportUnnecessary(pos: number, noFix = false) { + protected reportUnnecessary(pos: number, noFix?: boolean) { this.addFailure(pos - 1, pos, Rule.FAILURE_STRING_UNNECESSARY, noFix ? undefined : Lint.Replacement.deleteText(pos - 1, 1)); } diff --git a/src/rules/trailingCommaRule.ts b/src/rules/trailingCommaRule.ts index 25d4cec591e..d4de6e4ce6f 100644 --- a/src/rules/trailingCommaRule.ts +++ b/src/rules/trailingCommaRule.ts @@ -206,7 +206,7 @@ class TrailingCommaWalker extends Lint.AbstractWalker { } const token = getChildOfKind(node, closeTokenKind, this.sourceFile); if (token !== undefined) { - return this.checkComma(list.hasTrailingComma === true, list, token.end, optionKey); + return this.checkComma(list.hasTrailingComma, list, token.end, optionKey); } } @@ -214,11 +214,11 @@ class TrailingCommaWalker extends Lint.AbstractWalker { if (list.length === 0) { return; } - return this.checkComma(list.hasTrailingComma === true, list, closeElementPos, optionKey); + return this.checkComma(list.hasTrailingComma, list, closeElementPos, optionKey); } /* Expects `list.length !== 0` */ - private checkComma(hasTrailingComma: boolean, list: ts.NodeArray, closeTokenPos: number, optionKey: OptionName) { + private checkComma(hasTrailingComma: boolean | undefined, list: ts.NodeArray, closeTokenPos: number, optionKey: OptionName) { const options = isSameLine(this.sourceFile, list[list.length - 1].end, closeTokenPos) ? this.options.singleline : this.options.multiline; diff --git a/src/runner.ts b/src/runner.ts index 5ae114e9d6b..708021b71db 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -160,7 +160,7 @@ async function runLinter(options: Options, logger: Logger): Promise if (program && options.typeCheck) { const diagnostics = ts.getPreEmitDiagnostics(program); if (diagnostics.length !== 0) { - const message = diagnostics.map((d) => showDiagnostic(d, program, options.outputAbsolutePaths === true)).join("\n"); + const message = diagnostics.map((d) => showDiagnostic(d, program, options.outputAbsolutePaths)).join("\n"); if (options.force) { logger.error(message); } else { @@ -255,7 +255,7 @@ async function tryReadFile(filename: string, logger: Logger): Promise 0)) { +if (!(argv.init || argv.test !== undefined || argv.project !== undefined || commander.args.length > 0)) { console.error("Missing files"); process.exit(1); } -if (argv.typeCheck === true && argv.project === undefined) { +if (argv.typeCheck && argv.project === undefined) { console.error("--project must be specified in order to enable type checking."); process.exit(1); } diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index 59621236c02..614e302567a 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -103,10 +103,10 @@ describe("Rule Loader", () => { const diffResults = diffLists(everyRule(), tests); let testFailed = false; for (const { added, removed, value } of diffResults) { - if (added === true) { + if (added) { console.warn(`Test has no matching rule: ${value}`); testFailed = true; - } else if (removed === true) { + } else if (removed) { console.warn(`Missing test: ${value}`); testFailed = true; } @@ -123,9 +123,9 @@ describe("Rule Loader", () => { const failures: string[] = []; for (const { added, removed, value } of diffResults) { - if (added === true) { + if (added) { failures.push(`Rule in 'tslint:all' does not exist: ${value}`); - } else if (removed === true) { + } else if (removed) { failures.push(`Rule not in 'tslint:all': ${value}`); } } diff --git a/yarn.lock b/yarn.lock index 618624a3c14..c27dff3ad08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15,8 +15,8 @@ resolved "https://registry.yarnpkg.com/@types/colors/-/colors-1.1.3.tgz#5413b0a7a1b16dd18be0e3fd57d2feecc81cc776" "@types/commander@^2.9.0": - version "2.9.0" - resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.9.0.tgz#dd07af1fc35d76833e0da26ea67a2be088b5fafc" + version "2.9.1" + resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.9.1.tgz#d4e464425baf4685bd49dd233be11de9c00c0784" dependencies: "@types/node" "*" @@ -44,8 +44,8 @@ resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.41.tgz#e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608" "@types/node@*", "@types/node@^7.0.16": - version "7.0.22" - resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.22.tgz#4593f4d828bdd612929478ea40c67b4f403ca255" + version "7.0.24" + resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.24.tgz#dc94dab6cf1c372d8681d30557f9f2989fa08fb3" "@types/resolve@^0.0.4": version "0.0.4" @@ -206,8 +206,8 @@ babel-types@^6.18.0, babel-types@^6.24.1: to-fast-properties "^1.0.1" babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0: - version "6.17.1" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.1.tgz#17f14fddf361b695981fe679385e4f1c01ebd86f" + version "6.17.2" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.2.tgz#201d25ef5f892c41bae49488b08db0dd476e9f5c" balanced-match@^0.4.1: version "0.4.2" @@ -1103,7 +1103,7 @@ once@^1.3.0: dependencies: wrappy "1" -optimist@^0.6.1, optimist@~0.6.0: +optimist@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" dependencies: @@ -1454,28 +1454,29 @@ trim-right@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" -tslib@^1.6.0, tslib@^1.7.1: +tslib@^1.7.1: version "1.7.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec" "tslint-test-config-non-relative@file:test/external/tslint-test-config-non-relative": version "0.0.1" -tslint@latest: - version "5.3.2" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.3.2.tgz#e56459fb095a7307f103b84052174f5e3bbef6ed" +tslint@^5.4.2: + version "5.4.2" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.4.2.tgz#609b6640cc0424f4a395a9adf68c375563c549c7" dependencies: babel-code-frame "^6.22.0" colors "^1.1.2" + commander "^2.9.0" diff "^3.2.0" glob "^7.1.1" - optimist "~0.6.0" + minimatch "^3.0.4" resolve "^1.3.2" semver "^5.3.0" - tslib "^1.6.0" - tsutils "^2.0.0" + tslib "^1.7.1" + tsutils "^2.3.0" -tsutils@^2.0.0, tsutils@^2.3.0: +tsutils@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.3.0.tgz#96e661d7c2363f31adc8992ac67bbe7b7fc175e5"