cjoudrey / graphql-schema-linter

Validate GraphQL schema definitions against a set of rules
MIT License
694 stars 62 forks source link

Inline configuration support #237

Closed mshwery closed 4 years ago

mshwery commented 4 years ago

This PR introduces the ability to disable and re-enable blocks in schema files using GraphQL comment syntax, as well as disabling rules for a single line.

Syntax is as follows:

# lint-disable fields-have-descriptions, fields-are-camel-cased
type Comment {
  id: ID!
  message: String!
  author: User!
}
# lint-enable fields-have-descriptions, fields-are-camel-cased

type User {
  id: ID! #lint-disable-line fields-have-descriptions
  name: String!
}

These linter comments are file-specific, so if you have a multi-file schema they will only apply to the file where they are included.

Closes #18

cjoudrey commented 4 years ago

Wow! 😍 I can't believe this is actually happening. I'll take a closer look at the changes tonight/tomorrow, but I just wanted to say thanks @mshwery for opening this. I really appreciate the help.

cjoudrey commented 4 years ago

I just took a look at this PR and tried it locally and it just works. 😁 Thanks again!

I found a few minor issues, but not a deal breaker for this PR.

  1. It's seemingly impossible to disable relay-page-info-spec when PageInfo isn't defined.

  2. If someone accidentally forgets to specify a list of rules following lint-disable, the linter will crash with an unhelpful message. We could probably make that a little better.

  3. We might want to validate that the rules passed to the inline configurations actually exist. Seems like this save someone time if they ever have a typo in their # lint-disable ... comment.