Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for this plugin, @LuudJanssen. In this PR, I have made some minor code adjustments to improve readability and increase the semantic value of the code. These changes can roughly be split into three different subjects, which I will outline, below:
Swap returning
false
for returningnull
when no result can be returnedSome functions return either a result or
false
when no result can be provided. I do not think this is semantically correct, as I expectfalse
to be returned only when in a type guard or another assertion function. When a function parses and returns data, I expect either an error to be raised ornull
to be returned as a value to signal the parsing was completed successfully, but no valid result could be retrieved from parsing, therefore returningnull
.Change
is-github-alert-declaration.ts
toparse-github-alert-declaration.ts
The function contained in this file was called
parseGithubAlertDeclaration
. I believe file names should follow function naming and have changed this in this PR.Add type guard function to check whether provided type is a GitHub alert type
Before this PR, we needed to typecast the
type
variable inparseGithubAlertDeclaration
twice. Once to check whether the type was correct and twice when returning. I have added a utility to check whether a type is a GitHub alert type, which borrows its logic directly from the previous code. The second advantage of stripping this logic into a separate function is that we can test that function directly and ensuring that, during parsing, only the correct types are being parsed - without having to test the flow of multiple functions.