-
Notifications
You must be signed in to change notification settings - Fork 887
Lint for strict-boolean-expressions #2408
Lint for strict-boolean-expressions #2408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little verbose, especially for fast null checks or types like boolean | undefined
, but that's not too bad.
d982932
to
bccbe4e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor nits. seems fine as long as vscode-tslint continues working with type checking rules enabled (do we have any other such rules enabled in this code base?)
@@ -43,7 +43,7 @@ export class Formatter extends AbstractFormatter { | |||
const lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); | |||
const line = lineAndCharacter.line + 1; | |||
const character = lineAndCharacter.character + 1; | |||
const code = (failure.getRuleName ? failure.getRuleName() : ""); | |||
const code = failure.getRuleName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
src/rules/completedDocsRule.ts
Outdated
|
||
return CompletedDocsWalker.modifierAliases[description] || description; | ||
const alias = CompletedDocsWalker.modifierAliases[description]; | ||
if (alias !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would've preferred a ternary expression here
} | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
const limit = this.ruleArguments[0] as number | undefined || Rule.DEFAULT_ALLOWED_BLANKS; | ||
return this.applyWithFunction(sourceFile, walk, limit); | ||
const limit = this.ruleArguments[0] as number | undefined ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra space before ;
src/rules/orderedImportsRule.ts
Outdated
TRANSFORMS[optionSet["named-imports-order"] || "case-insensitive"]; | ||
interface Options { "import-sources-order"?: string; "named-imports-order"?: string; } | ||
const optionSet = (this.getOptions() as [Options])[0]; | ||
const { "import-sources-order": sources = "case-insensitive", "named-imports-order": named = "case-insensitive" } = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is kind of a crazy line. might be nice to spread it out:
const {
"import-sources-order": sources = "case-insensitive",
"named-imports-order": named = "case-insensitive",
} = optionSet === undefined ? {} : optionSet;
@@ -207,7 +208,7 @@ function isFunction(t: ts.Type): boolean { | |||
return true; | |||
} | |||
const symbol = t.getSymbol(); | |||
return (symbol && symbol.getName()) === "Function"; | |||
return symbol === undefined ? false : symbol.getName() === "Function"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a simple boolean expression would be slightly easier to read, symbol !== undefined && symbol.getName() === "Function"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2534 will catch this. ⚡
As for running this rule in vscode, see Microsoft/vscode-tslint#70. The instructions at https://github.com/angelozerr/tslint-language-service/blob/master/README.md work for me. |
4c9c62a
to
365914d
Compare
365914d
to
520f8b9
Compare
@andy-hanson @adidahiya there is a preview of the vscode-tslint extension that uses the typescript server plugin which supports type checked rules. All you need to do is to install this extension. One thing to keep in mind when using the tslint typescript server plugin is that the |
PR checklist
Overview of change:
Applies the
strict-boolean-expressions
rule to the code.