facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.26k stars 477 forks source link

Add a way to provide reason for skipping #115

Open gaearon opened 8 years ago

gaearon commented 8 years ago

I’m writing my first codemod and I noticed it’s very hard to determine whether certain edge cases are worth handling. Currently I see an output like this:

168 errors
0 unmodified
61720 skipped
858 ok

However “61720 skipped” is not very informative. I have 15 different places where I return early based on some condition. Handling these cases could introduce more complexity to the codemod but I want to know when it would be worth it. For example, an output like this would be way more helpful:

168 errors
0 unmodified
50042 skipped (reason: does not import a mixin)
8243 skipped (reason: contains a dangerous call)
2192 skipped (no reason given)
858 ok

This would give me a much better understanding of where to spend the effort making the codemod smarter. In terms of API, it could look like:

if (something) {
  return j.skip('does not import a mixin');
}

if (somethingElse) {
  return j.skip('contains a dangerous call');
}

if (blabla) {
  return;
}

Would you be interested in considering this feature request?

fkling commented 8 years ago

That sounds very good to me. jscodeshift already provides some way to get this information, via the stats function.

I.e. you can call stats('does not import a mixin') in your transformer and you will see counters for each value when you dry run.

But I like the idea of merging this into skip information.

gaearon commented 8 years ago

Ah, I missed stats in README.

fkling commented 8 years ago

I still think it's valuable to have both.

GMZwinge commented 3 months ago

Could the --verbose mode also display a reason in addition to the file being skipped?