-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(schematics): enable strict null checks #12983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(schematics): enable strict null checks #12983
Conversation
@@ -30,7 +30,7 @@ export default function(options: Schema): Rule { | |||
*/ | |||
function addFormModulesToModule(options: Schema) { | |||
return (host: Tree) => { | |||
const modulePath = findModuleFromOptions(host, options); | |||
const modulePath = findModuleFromOptions(host, options)!; |
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 never undefined
or null
because the addXModulesToModule
methods are only called if skipImport
is set to false
. And the findModuleFromOptions
method only returns undefined if that option is enabled.
@jelbourn Want me to add a comment for this? (afraid of repeating it for every schematic though)
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.
Could the function return an empty string in that case?
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.
What would be the benefit? This comes from an utility function from @schematics/angular
. It should be really never undefined because we already check for skipImport
before.
@@ -30,7 +30,7 @@ export default function(options: Schema): Rule { | |||
*/ | |||
function addFormModulesToModule(options: Schema) { | |||
return (host: Tree) => { | |||
const modulePath = findModuleFromOptions(host, options); | |||
const modulePath = findModuleFromOptions(host, options)!; |
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.
Could the function return an empty string in that case?
@@ -33,7 +33,7 @@ export function appendElementToHead(host: Tree, project: WorkspaceProject, eleme | |||
throw `Could not find '<head>' element in HTML file: ${indexPath}`; | |||
} | |||
|
|||
const endTagOffset = headTag.sourceCodeLocation.endTag.startOffset; | |||
const endTagOffset = headTag.sourceCodeLocation!.endTag.startOffset; |
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.
Why is this never null?
Similar for other one-off places (like architect
below)
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 never null
because we explicitly enabled the parse5
option to track the source code location. So we will always have this property set.
Regarding architect: We could do better here, but I just went with the assumption that every CLI project has an architect block configured. We also assert if the default architect builders
are used in the theming/index.ts
file.
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.
We should capture that explanation somewhere in the code
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 will add a note for the parse5
instances. There aren't too much of those.
For the architect. I'll probably create an utility function that does the checking for an architect target. That way we are strict-null check compliant and also make sure that projects that don't have a builder will gracefully exit with a meaningful error message.
* Enables strict null checks for the schematics and fixes a few potential unsafe accesses. * Supports specifying a project for `ng-add`.
e7f5c42
to
0a872c4
Compare
0a872c4
to
85ded36
Compare
@jelbourn Addressed your feedback. Please have another look |
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.
LGTM
Just looks like there's a lint error |
Fixed |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ng-add
.