-
Notifications
You must be signed in to change notification settings - Fork 887
strict-type-predicates: warn if strictNullChecks is not enabled #2786
Conversation
src/language/utils.ts
Outdated
@@ -425,3 +425,8 @@ export function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefi | |||
return undefined; | |||
} | |||
} | |||
|
|||
export function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean { |
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.
is this the right file for this 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.
I think it's okay. We'll probably have to split apart this file some time in the future
@@ -52,6 +54,10 @@ export class Rule extends Lint.Rules.TypedRule { | |||
} | |||
|
|||
public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { | |||
if (!Lint.isStrictNullChecksEnabled(program.getCompilerOptions())) { | |||
showWarningOnce("strict-type-predicates does not work without strictNullChecks"); |
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.
Please suggest a better warning message.
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.
I think it's fine. Would probably be more clear if it said tsc option --strictNullChecks
, but if you search for strictNullChecks
, the first hit is correct
src/language/utils.ts
Outdated
@@ -425,3 +425,8 @@ export function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefi | |||
return undefined; | |||
} | |||
} | |||
|
|||
export function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean { |
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.
I think it's okay. We'll probably have to split apart this file some time in the future
@@ -52,6 +54,10 @@ export class Rule extends Lint.Rules.TypedRule { | |||
} | |||
|
|||
public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { | |||
if (!Lint.isStrictNullChecksEnabled(program.getCompilerOptions())) { | |||
showWarningOnce("strict-type-predicates does not work without strictNullChecks"); |
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.
I think it's fine. Would probably be more clear if it said tsc option --strictNullChecks
, but if you search for strictNullChecks
, the first hit is correct
PR checklist
Overview of change:
Warn if
strict-type-predicates
is used withoutstrictNullChecks
and don't apply the rule. IMO that's a better behavior than just emitting wrong lint results.This also fixes
strict-boolean-expressions
ifstrict
is used instead ofstrictNullChecks
.Is there anything you'd like reviewers to focus on?
CHANGELOG.md entry: