-
Notifications
You must be signed in to change notification settings - Fork 62
Add support for autofixing #261
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution @benjaminjkraft! I love that you're working on adding support for I quickly looked at your pull request and a few things come to mind:
|
Totally fair! I'll see what I have time to do later this week.
I am certainly trying to handle that right (using the
Yeah, I agree it's unfortunate -- if we can come up with a good interface it should be easy to implement. (And will save me some time re-wiring a script that currently uses |
6a09c6d
to
e907bb4
Compare
Ok, I've added support for all the capitalization-related fixers, and wrote some more tests for the fix-application logic (which indeed caught a bug). Autofixing the alphabetization rules is surprisingly tricky (due to keeping track of the whitespace and comments between blocks); I may have more time tomorrow to try to finish that off. |
The core API is fairly simple: errors can have a new field, `fix`, which includes a location (likely a graphql node's `.loc`) and a replacement. The runner then takes care of applying the fix, if the `--fix` option was specified. I added autofixers for all of the capitalization and alphabetization rules. (The remainder can't (or shouldn't) really be autofixed.) In general, capitalization was very easy, and alphabetization was quite tricky, but in the latter case it's mostly in a shared util that handles all of annoying syntax-transformation junk. Fixes cjoudrey#23.
e907bb4
to
06244fb
Compare
Ok, unless I missed any, all the rules that are fixable should have fixers now! |
thanks @benjaminjkraft it worked like a charm for my schema :) |
note, on another test i got a small mixup with the rule of the case...
which ends up as
|
Oh, good find! It looks like I refactored out the check I had for conflicts between fixes. I suspect we won't be able to fix that one in one go (without a lot of work, anyway) but it shouldn't be too hard to add a conflict check and just apply the first fix (then running twice will fix it fully). I'll take a look at that, although I may not have time for a week or two. |
The API is fairly simple: errors can have a new field,
fix
, whichincludes a location (likely a graphql node's
.loc
) and a replacement.The runner then takes care of applying the fix, if the
--fix
optionwas specified.
I added just one autofixer in this commit, for
enum-rules-all-caps
.It should be fairly easy to add more, I just figured I'd keep this
commit small by adding only a very simple one. (Full disclosure: the
rules I actually care about autofixing are custom plugins!)
Fixes (some of) #23.