Skip to content
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

Utilize jscodeshift CLI results output #525

Merged
merged 15 commits into from
Apr 25, 2023

Conversation

gitKrystan
Copy link
Collaborator

@gitKrystan gitKrystan commented Mar 20, 2023

Fixes #523

Previous iterations of this codemod did not take full advantage of jscodeshift's (undocumented AFAICT) results API.

Thus, a user might see:

 All done. 
 Results: 
 0 errors
 58 unmodified
 0 skipped
 0 ok
 Time elapsed: 3.029seconds 

when their codemods.log file had multiple entries like this:

2023-03-14T11:25:08.799Z [error] [addon/controllers/foo.js]: 
FAILURE 
Validation errors for class 'FooController': 
	[actions]: Transform not supported - [destroy]: action name matches one of the lifecycle hooks. 
Rename and try again. See https://github.com/scalvert/ember-native-class-codemod/issues/34 for more details

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:

Result How-to Meaning
errors throw we attempted to transform but encountered an error
unmodified return string (unchanged) we attempted to transform but it was unnecessary
skipped return undefined we did not attempt to transform
ok return string (changed) we successfully transformed

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 throwing to give an errors result, I had to remove the partialTransforms 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.

@gitKrystan gitKrystan requested a review from wycats March 20, 2023 21:49
@gitKrystan gitKrystan merged commit dd4094c into ember-codemods:master Apr 25, 2023
@gitKrystan gitKrystan deleted the fix-523 branch April 25, 2023 16:51
@gitKrystan gitKrystan added the enhancement New feature or request label Apr 25, 2023
@gitKrystan gitKrystan changed the title Fix CLI results output Utilize jscodeshift CLI results output Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error count doesn’t match log.
1 participant