graphql-schema-linter icon indicating copy to clipboard operation
graphql-schema-linter copied to clipboard

Add --fix option

Open cjoudrey opened this issue 7 years ago β€’ 24 comments

In some error cases, the linter can programmatically know what the schema should have been.

It would be awesome to provide a --fix option that would automatically resolve these errors.

Some example rules that could be fixed by the linter this way:

  • EnumValuesAllCaps
  • EnumValuesSortedAlphabetically
  • FieldsAreCamelCased
  • InputObjectValuesAreCamelCased
  • TypesAreCapitalized

cjoudrey avatar Aug 09 '17 17:08 cjoudrey

@cjoudrey I'd like to check this out, I might not be able to get to it for a few days as I'm at graphql summit but I'll start messing around with it. Cool idea by the way πŸ‘.

bbohen avatar Oct 25 '17 13:10 bbohen

That would be awesome @bbohen. πŸ˜€

Whenever you do poke at it, let me know if you need help or want to discuss solutions.

cjoudrey avatar Oct 25 '17 14:10 cjoudrey

Absolutely! I think it would be really nice to be able to use this with ESLint per #21.

bbohen avatar Oct 25 '17 18:10 bbohen

@cjoudrey @bbohen - Is this still being worked on? If not, I may take a stab at it

iamclaytonray avatar Dec 13 '17 02:12 iamclaytonray

I’m not working on it atm. If @bbohen isn’t, I’d say go for it. πŸ˜€

cjoudrey avatar Dec 13 '17 04:12 cjoudrey

@cjoudrey - I'll wait to see what @bbohen says

iamclaytonray avatar Dec 13 '17 08:12 iamclaytonray

@iamclaytonray Go for it! I was all excited to work on this and then work got really busy 😬 .

bbohen avatar Dec 14 '17 13:12 bbohen

Thanks @bbohen!

No promises but I'll try to get a rough copy up and then we can iterate πŸ™‚

iamclaytonray avatar Dec 14 '17 17:12 iamclaytonray

Sorry for being so late on this. Totally dropped the ball. Umm... @cjoudrey - Can we add a task list to the original issue that includes which rules should be fixable?

iamclaytonray avatar Jan 16 '18 09:01 iamclaytonray

I'll be working on this for at least today and hopefully more. I've never written a lint fixer so I'm in new waters. May take a bit but I'll do my best πŸ˜„

iamclaytonray avatar Jan 16 '18 09:01 iamclaytonray

@iamclaytonray I've never written something like this before either. 😁 I would have looked into ESLint and Rubocop.

Conceptually, I was thinking each rule would be able to optionally provide a function that the linter would use to fix the issue. I think we'll want to make these changes by manipulating the AST at some point.

One challenge is that the AST we use during validation is the concatenation of all .graphql files. We may want to have a second step after validation called fix which would take the reported errors, parse the individual files causing the mistake, and have the rule fix that AST.

Can we add a task list to the original issue that includes which rules should be fixable?

:+1: Done

cjoudrey avatar Jan 16 '18 16:01 cjoudrey

That makes sense to me! Thanks for the kind words πŸ˜„

I've been looking into TSLint and ESLint. Didn't think of Rubocop. I'll have to check that one out. Thanks!

iamclaytonray avatar Jan 16 '18 16:01 iamclaytonray

Disregard:

(So that I can check these off)

  • [ ] EnumValuesAllCaps
  • [ ] EnumValuesSortedAlphabetically
  • [ ] FieldsAreCamelCased
  • [ ] InputObjectValuesAreCamelCased
  • [ ] TypesAreCapitalized

iamclaytonray avatar Jan 16 '18 18:01 iamclaytonray

@cjoudrey - I'd like to integrate this fix feature (when it's done) with graphql-cli as well. Do you have any thoughts on that? I'm sure Johannes would love to chime in too

iamclaytonray avatar Jan 16 '18 19:01 iamclaytonray

I'd like to integrate this fix feature (when it's done) with graphql-cli as well.

@iamclaytonray yeah, that makes sense. You might be interested by this open issue: https://github.com/graphql-cli/graphql-cli/issues/14

At the moment graphql lint does schema linting, but I recall Johannes mentioning he wanted to have graphql lint schema. graphql lint would be for queries.

You might want to have that discussion with him in that issue to confirm that's still what he had in mind.

cjoudrey avatar Jan 16 '18 20:01 cjoudrey

Sounds good!

iamclaytonray avatar Jan 16 '18 20:01 iamclaytonray

@iamclaytonray have you managed to make any progress on this by any chance? πŸ˜€πŸ˜€

cjoudrey avatar Jan 26 '18 06:01 cjoudrey

@cjoudrey - Sorry, no :/

I had a family emergency that's had me busy for the past week.

I actually just started picking this up again this morning.

iamclaytonray avatar Jan 26 '18 19:01 iamclaytonray

@iamclaytonray No need to be sorry! I was just curious. πŸ˜„ Hope all is well.

cjoudrey avatar Jan 26 '18 19:01 cjoudrey

Hey @cjoudrey. I am still hacking away at this, a little bit at a time. I just got super slammed with work so I've been doing what I can in my off time. If anyone else in the community wants to help me out, I would definitely appreciate it πŸ˜„

iamclaytonray avatar Feb 04 '18 19:02 iamclaytonray

@cjoudrey Hello, do you still want this feature? I think it might be helpful for us too :P

jlwt90 avatar Mar 08 '20 09:03 jlwt90

@cjoudrey Hello, do you still want this feature? I think it might be helpful for us too :P

Hi @jlwt90! πŸ˜„I still think this would be helpful. I'm not actively working on it though. PRs are welcome.

cjoudrey avatar Mar 09 '20 16:03 cjoudrey

can we please merge this, it will be super helpful

shubhang-bot avatar Jul 12 '23 14:07 shubhang-bot

@cjoudrey +1 can we please merge this? It seems like this project has been abandoned for a while. If the owner of the project is not working on it anymore can the ownership be at least shared with others who are working on the project so that a great PR like this can be merged and released?

danfoley avatar Feb 09 '24 18:02 danfoley