Skip to content

Commit

Permalink
Update tslint dependency (palantir#2851)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ajafff authored and adidahiya committed Jun 2, 2017
1 parent d87c52d commit 85e6469
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ruleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/adjacentOverloadSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noDefaultExportRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function walk(ctx: Lint.WalkContext<void>) {
}
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 &&
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noInternalModuleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NoInternalModuleWalker extends Lint.AbstractWalker<void> {
}

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
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUnsafeAnyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function walk(ctx: Lint.WalkContext<void>, 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/preferObjectSpreadRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ abstract class SemicolonWalker extends Lint.AbstractWalker<Options> {
}
}

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));
}

Expand Down
6 changes: 3 additions & 3 deletions src/rules/trailingCommaRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ class TrailingCommaWalker extends Lint.AbstractWalker<Options> {
}
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);
}
}

private checkList(list: ts.NodeArray<ts.Node>, closeElementPos: number, optionKey: OptionName) {
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<ts.Node>, closeTokenPos: number, optionKey: OptionName) {
private checkComma(hasTrailingComma: boolean | undefined, list: ts.NodeArray<ts.Node>, closeTokenPos: number, optionKey: OptionName) {
const options = isSameLine(this.sourceFile, list[list.length - 1].end, closeTokenPos)
? this.options.singleline
: this.options.multiline;
Expand Down
4 changes: 2 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async function runLinter(options: Options, logger: Logger): Promise<LintResult>
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 {
Expand Down Expand Up @@ -255,7 +255,7 @@ async function tryReadFile(filename: string, logger: Logger): Promise<string | u
return fs.readFileSync(filename, "utf8");
}

function showDiagnostic({ file, start, category, messageText }: ts.Diagnostic, program: ts.Program, outputAbsolutePaths: boolean): string {
function showDiagnostic({ file, start, category, messageText }: ts.Diagnostic, program: ts.Program, outputAbsolutePaths?: boolean): string {
let message = ts.DiagnosticCategory[category];
if (file) {
const {line, character} = file.getLineAndCharacterOfPosition(start);
Expand Down
4 changes: 2 additions & 2 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ function displayDiffResults(diffResults: diff.IDiffResult[], extension: string)

for (const diffResult of diffResults) {
let color = colors.grey;
if (diffResult.added === true) {
if (diffResult.added) {
color = colors.green.underline;
} else if (diffResult.removed === true) {
} else if (diffResult.removed) {
color = colors.red.underline;
}
process.stdout.write(color(diffResult.value));
Expand Down
4 changes: 2 additions & 2 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ if (parsed.unknown.length !== 0) {
}
const argv = commander.opts() as any as Argv;

if (!(argv.init === true || argv.test !== undefined || argv.project !== undefined || commander.args.length > 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);
}
Expand Down
8 changes: 4 additions & 4 deletions test/ruleLoaderTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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}`);
}
}
Expand Down
31 changes: 16 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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" "*"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 85e6469

Please sign in to comment.