Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

strict-type-predicates: warn if strictNullChecks is not enabled #2786

Merged
merged 4 commits into from May 31, 2017
Merged

strict-type-predicates: warn if strictNullChecks is not enabled #2786

merged 4 commits into from May 31, 2017

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented May 18, 2017

PR checklist

Overview of change:

Warn if strict-type-predicates is used without strictNullChecks and don't apply the rule. IMO that's a better behavior than just emitting wrong lint results.

This also fixes strict-boolean-expressions if strict is used instead of strictNullChecks.

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

@@ -425,3 +425,8 @@ export function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefi
return undefined;
}
}

export function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean {
Copy link
Contributor Author

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?

Copy link
Contributor

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");
Copy link
Contributor Author

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.

Copy link
Contributor

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

@@ -425,3 +425,8 @@ export function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefi
return undefined;
}
}

export function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean {
Copy link
Contributor

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");
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants