Skip to content

Commit

Permalink
Upgrade tslint, prettier, tsutils (palantir#4549)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Feb 26, 2019
1 parent cd2f37c commit 587129e
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 182 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"compile:core": "tsc -p src",
"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 codeFrame",
"lint": "npm-run-all -p lint:from-installed lint:from-bin",
"lint:from-bin": "node bin/tslint --project test/tsconfig.json --format codeFrame",
"lint:from-installed": "tslint --project test/tsconfig.json --format codeFrame",
"lint-fix": "yarn lint:from-installed --fix",
"publish:local": "./scripts/npmPublish.sh",
"test": "npm-run-all test:pre -p test:mocha test:rules",
"test:pre": "cd ./test/config && npm install --no-save",
Expand All @@ -40,7 +41,7 @@
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.27.2"
"tsutils": "^2.29.0"
},
"peerDependencies": {
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev"
Expand All @@ -65,11 +66,11 @@
"mocha": "^3.2.0",
"npm-run-all": "^4.0.2",
"nyc": "^10.2.0",
"prettier": "1.14.3",
"prettier": "~1.16.4",
"rimraf": "^2.5.4",
"ts-node": "^3.3.0",
"tslint": "~5.12.0",
"tslint-config-prettier": "^1.15.0",
"tslint": "~5.13.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
"typescript": "~3.1.6"
Expand Down
7 changes: 2 additions & 5 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,8 @@ export function parseConfigFile(
return {
...(raw.exclude !== undefined
? {
exclude: arrayify(raw.exclude).map(
pattern =>
dir === undefined
? path.resolve(pattern)
: path.resolve(dir, pattern),
exclude: arrayify(raw.exclude).map(pattern =>
dir === undefined ? path.resolve(pattern) : path.resolve(dir, pattern),
),
}
: {}),
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 @@ -338,8 +338,8 @@ export class RuleFailure {
this.fix === undefined
? undefined
: Array.isArray(this.fix)
? this.fix.map(r => r.toJson())
: this.fix.toJson(),
? this.fix.map(r => r.toJson())
: this.fix.toJson(),
name: this.fileName,
ruleName: this.ruleName,
ruleSeverity: this.ruleSeverity.toUpperCase(),
Expand Down
14 changes: 6 additions & 8 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ export class Linter {
* `resolveJsonModule`.
*/
public static getFileNames(program: ts.Program): string[] {
return mapDefined(
program.getSourceFiles(),
file =>
file.fileName.endsWith(".d.ts") ||
file.fileName.endsWith(".json") ||
program.isSourceFileFromExternalLibrary(file)
? undefined
: file.fileName,
return mapDefined(program.getSourceFiles(), file =>
file.fileName.endsWith(".d.ts") ||
file.fileName.endsWith(".json") ||
program.isSourceFileFromExternalLibrary(file)
? undefined
: file.fileName,
);
}

Expand Down
18 changes: 6 additions & 12 deletions src/rules/adjacentOverloadSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ function walk(ctx: Lint.WalkContext<void>): void {
| ts.ClassDeclaration
| ts.TypeLiteralNode;
addFailures(
getMisplacedOverloads<ts.TypeElement | ts.ClassElement>(
members,
member =>
utils.isSignatureDeclaration(member)
? getOverloadKey(member)
: undefined,
getMisplacedOverloads<ts.TypeElement | ts.ClassElement>(members, member =>
utils.isSignatureDeclaration(member) ? getOverloadKey(member) : undefined,
),
);
}
Expand All @@ -77,12 +73,10 @@ function walk(ctx: Lint.WalkContext<void>): void {

function visitStatements(statements: ReadonlyArray<ts.Statement>): void {
addFailures(
getMisplacedOverloads(
statements,
statement =>
utils.isFunctionDeclaration(statement) && statement.name !== undefined
? statement.name.text
: undefined,
getMisplacedOverloads(statements, statement =>
utils.isFunctionDeclaration(statement) && statement.name !== undefined
? statement.name.text
: undefined,
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/commentFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function parseOptions(options: Array<string | IExceptionsObject>): Options {
options.indexOf(OPTION_LOWERCASE) !== -1
? Case.Lower
: options.indexOf(OPTION_UPPERCASE) !== -1
? Case.Upper
: Case.None,
? Case.Upper
: Case.None,
failureSuffix: "",
space: options.indexOf(OPTION_SPACE) !== -1,
...composeExceptions(options[options.length - 1]),
Expand Down
4 changes: 2 additions & 2 deletions src/rules/memberAccessRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ function walk(ctx: Lint.WalkContext<Options>) {
node.kind === ts.SyntaxKind.Constructor
? getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)!
: node.name !== undefined
? node.name
: node;
? node.name
: node;
const memberName =
node.name !== undefined && node.name.kind === ts.SyntaxKind.Identifier
? node.name.text
Expand Down
55 changes: 28 additions & 27 deletions src/rules/memberOrderingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,27 +354,29 @@ class MemberOrderingWalker extends Lint.AbstractWalker<Options> {
}
}
if (failureExists) {
const sortedMemberIndexes = members.map((_, i) => i).sort((ai, bi) => {
const a = members[ai];
const b = members[bi];

// first, sort by member rank
const rankDiff = this.memberRank(a) - this.memberRank(b);
if (rankDiff !== 0) {
return rankDiff;
}
// then lexicographically if alphabetize == true
if (this.options.alphabetize && a.name !== undefined && b.name !== undefined) {
const aName = nameString(a.name);
const bName = nameString(b.name);
const nameDiff = aName.localeCompare(bName);
if (nameDiff !== 0) {
return nameDiff;
const sortedMemberIndexes = members
.map((_, i) => i)
.sort((ai, bi) => {
const a = members[ai];
const b = members[bi];

// first, sort by member rank
const rankDiff = this.memberRank(a) - this.memberRank(b);
if (rankDiff !== 0) {
return rankDiff;
}
}
// finally, sort by position in original NodeArray so the sort remains stable.
return ai - bi;
});
// then lexicographically if alphabetize == true
if (this.options.alphabetize && a.name !== undefined && b.name !== undefined) {
const aName = nameString(a.name);
const bName = nameString(b.name);
const nameDiff = aName.localeCompare(bName);
if (nameDiff !== 0) {
return nameDiff;
}
}
// finally, sort by position in original NodeArray so the sort remains stable.
return ai - bi;
});
const splits = getSplitIndexes(members, this.sourceFile.text);
const sortedMembersText = sortedMemberIndexes.map(i => {
const start = splits[i];
Expand Down Expand Up @@ -488,8 +490,8 @@ function getMemberKind(member: Member): MemberKind | undefined {
const accessLevel = hasModifier(member.modifiers, ts.SyntaxKind.PrivateKeyword)
? "private"
: hasModifier(member.modifiers, ts.SyntaxKind.ProtectedKeyword)
? "protected"
: "public";
? "protected"
: "public";

switch (member.kind) {
case ts.SyntaxKind.Constructor:
Expand Down Expand Up @@ -536,11 +538,10 @@ interface Options {

function parseOptions(options: any[]): Options {
const { order: orderJson, alphabetize } = getOptionsJson(options);
const order = orderJson.map(
cat =>
typeof cat === "string"
? new MemberCategory(cat.replace(/-/g, " "), new Set(memberKindFromName(cat)))
: new MemberCategory(cat.name, new Set(flatMap(cat.kinds, memberKindFromName))),
const order = orderJson.map(cat =>
typeof cat === "string"
? new MemberCategory(cat.replace(/-/g, " "), new Set(memberKindFromName(cat)))
: new MemberCategory(cat.name, new Set(flatMap(cat.kinds, memberKindFromName))),
);
return { order, alphabetize };
}
Expand Down
8 changes: 4 additions & 4 deletions src/rules/noDuplicateSuperRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ function worse(a: Super, b: Super): Super {
: a
: b
: typeof b === "number"
? a
: a.break
? b
: a;
? a
: a.break
? b
: a;
}
4 changes: 2 additions & 2 deletions src/rules/noTrailingWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function walk(ctx: Lint.WalkContext<Options>) {
? getExcludedRanges(sourceFile, ctx.options)
: getTemplateRanges(sourceFile)
: ctx.options.ignoreJsDoc
? getExcludedComments(sourceFile, ctx.options)
: [];
? getExcludedComments(sourceFile, ctx.options)
: [];
for (const possibleFailure of possibleFailures) {
if (
!excludedRanges.some(
Expand Down
8 changes: 4 additions & 4 deletions src/rules/objectLiteralSortKeysRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ function walk(ctx: Lint.WalkContext<Options>, checker?: ts.TypeChecker): void {
lastKey === undefined
? false
: localeCompare
? lastKey.localeCompare(key) === 1
: lastKey > key;
? lastKey.localeCompare(key) === 1
: lastKey > key;
if (keyOrderDescending && !hasBlankLineBefore(ctx.sourceFile, property)) {
ctx.addFailureAtNode(
property.name,
Expand Down Expand Up @@ -354,8 +354,8 @@ function getTypeName(t: TypeLike): string | undefined {
return t.kind === ts.SyntaxKind.InterfaceDeclaration
? t.name.text
: isTypeAliasDeclaration(parent)
? parent.name.text
: undefined;
? parent.name.text
: undefined;
}

type TypeLike = ts.InterfaceDeclaration | ts.TypeLiteralNode;
Expand Down
4 changes: 2 additions & 2 deletions src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class Rule extends Lint.Rules.AbstractRule {
this.ruleArguments.indexOf(OPTION_STRICT_BOUND_CLASS_METHODS) !== -1
? BoundClassMethodOption.Strict
: this.ruleArguments.indexOf(OPTION_IGNORE_BOUND_CLASS_METHODS) !== -1
? BoundClassMethodOption.Ignore
: BoundClassMethodOption.Default,
? BoundClassMethodOption.Ignore
: BoundClassMethodOption.Default,
interfaces: this.ruleArguments.indexOf(OPTION_IGNORE_INTERFACES) === -1,
};
const Walker =
Expand Down
4 changes: 2 additions & 2 deletions src/rules/spaceBeforeFunctionParenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ function getOption(node: ts.Node, options: Options): Option | undefined {
return hasName
? options.named
: !hasTypeParameters(node)
? options.anonymous
: undefined;
? options.anonymous
: undefined;
}

case ts.SyntaxKind.MethodDeclaration:
Expand Down
52 changes: 26 additions & 26 deletions src/rules/strictBooleanExpressionsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ function handleUnion(type: ts.UnionType, options: Options): TypeFailure | undefi
return seenFalsy === 0
? TypeFailure.AlwaysTruthy
: !anyTruthy
? TypeFailure.AlwaysFalsy
: !options.allowMix && seenFalsy > 1
? TypeFailure.Mixes
: undefined;
? TypeFailure.AlwaysFalsy
: !options.allowMix && seenFalsy > 1
? TypeFailure.Mixes
: undefined;
}

/** Fails if a kind of falsiness is not allowed. */
Expand Down Expand Up @@ -388,28 +388,28 @@ function getKind(type: ts.Type): TypeKind {
return is(ts.TypeFlags.String)
? TypeKind.String
: is(ts.TypeFlags.Number)
? TypeKind.Number
: is(ts.TypeFlags.Boolean)
? TypeKind.Boolean
: is(ts.TypeFlags.Null)
? TypeKind.Null // tslint:disable-next-line:no-bitwise
: is(ts.TypeFlags.Undefined | ts.TypeFlags.Void)
? TypeKind.Undefined
: is(ts.TypeFlags.EnumLike)
? TypeKind.Enum
: is(ts.TypeFlags.NumberLiteral)
? numberLiteralIsZero(type as ts.NumberLiteralType)
? TypeKind.FalseNumberLiteral
: TypeKind.AlwaysTruthy
: is(ts.TypeFlags.StringLiteral)
? stringLiteralIsEmpty(type as ts.StringLiteralType)
? TypeKind.FalseStringLiteral
: TypeKind.AlwaysTruthy
: is(ts.TypeFlags.BooleanLiteral)
? (type as ts.IntrinsicType).intrinsicName === "true"
? TypeKind.AlwaysTruthy
: TypeKind.FalseBooleanLiteral
: TypeKind.AlwaysTruthy;
? TypeKind.Number
: is(ts.TypeFlags.Boolean)
? TypeKind.Boolean
: is(ts.TypeFlags.Null)
? TypeKind.Null // tslint:disable-next-line:no-bitwise
: is(ts.TypeFlags.Undefined | ts.TypeFlags.Void)
? TypeKind.Undefined
: is(ts.TypeFlags.EnumLike)
? TypeKind.Enum
: is(ts.TypeFlags.NumberLiteral)
? numberLiteralIsZero(type as ts.NumberLiteralType)
? TypeKind.FalseNumberLiteral
: TypeKind.AlwaysTruthy
: is(ts.TypeFlags.StringLiteral)
? stringLiteralIsEmpty(type as ts.StringLiteralType)
? TypeKind.FalseStringLiteral
: TypeKind.AlwaysTruthy
: is(ts.TypeFlags.BooleanLiteral)
? (type as ts.IntrinsicType).intrinsicName === "true"
? TypeKind.AlwaysTruthy
: TypeKind.FalseBooleanLiteral
: TypeKind.AlwaysTruthy;

function is(flags: ts.TypeFlags) {
return isTypeFlagSet(type, flags);
Expand Down
12 changes: 6 additions & 6 deletions src/rules/strictTypePredicatesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ function testNonStrictNullUndefined(type: ts.Type): boolean | "null" | "undefine
return !anyOther
? true
: anyNull && anyUndefined
? undefined
: anyNull
? "null"
: anyUndefined
? "undefined"
: false;
? undefined
: anyNull
? "null"
: anyUndefined
? "undefined"
: false;
}

function unionParts(type: ts.Type) {
Expand Down
16 changes: 6 additions & 10 deletions src/rules/useDefaultTypeParameterRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function getArgsAndParameters(node: ts.Node, checker: ts.TypeChecker): ArgsAndPa
decl.kind === ts.SyntaxKind.TypeReference
? typeParamsFromType(decl.typeName, checker)
: decl.kind === ts.SyntaxKind.ExpressionWithTypeArguments
? typeParamsFromType(decl.expression, checker)
: typeParamsFromCall(node as ts.CallExpression | ts.NewExpression, checker);
? typeParamsFromType(decl.expression, checker)
: typeParamsFromCall(node as ts.CallExpression | ts.NewExpression, checker);
return typeParameters === undefined ? undefined : { typeArguments, typeParameters };
default:
return undefined;
Expand Down Expand Up @@ -134,14 +134,10 @@ function typeParamsFromType(
return undefined;
}

return find(
sym.declarations,
decl =>
isClassLikeDeclaration(decl) ||
isTypeAliasDeclaration(decl) ||
isInterfaceDeclaration(decl)
? decl.typeParameters
: undefined,
return find(sym.declarations, decl =>
isClassLikeDeclaration(decl) || isTypeAliasDeclaration(decl) || isInterfaceDeclaration(decl)
? decl.typeParameters
: undefined,
);
}

Expand Down
Loading

0 comments on commit 587129e

Please sign in to comment.