Utilize jscodeshift CLI results output #525
Merged
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.
Fixes #523
Previous iterations of this codemod did not take full advantage of jscodeshift's (undocumented AFAICT) results API.
Thus, a user might see:
when their codemods.log file had multiple entries like this:
This discrepancy can be pretty confusing for users.
I did some code-reading and found that jscodeshift checks the output of the transform function and sorts the transform attempt into its corresponding results category based on the following:
errors
throw
unmodified
string
(unchanged)skipped
undefined
ok
string
(changed)While the changes to make this happen for this codemod were trivial, I found that neither codemod-cli nor jscodeshift's testing helpers expect the transform to throw, so I had to re-write the testing helpers and get a little creative to expect errors and error messages. Thus, this PR is mostly testing changes.
Additionally, due to the nature of
throw
ing to give anerrors
result, I had to remove thepartialTransforms
functionality. This means that the codemod will fail for the file if any object within the file fails. This is standard for jscodeshift codemods apparently and was the standard for this codemod until very recently when I changed it thinking it would be helpful. It turns out not to be helpful.