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

Put comments behind an option in formatter #271

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

benjaminjkraft
Copy link
Contributor

@benjaminjkraft benjaminjkraft commented Jul 16, 2023

In #263, we introduced parsing of comments, as well as support for them in the formatter. In some cases this is surely useful, but in others it's just bloat. (And as I describe in Khan/genqlient#282, it may even be a problem in some cases which depended on the fact that formatting the query didn't include comments.)

In this commit I introduce an option to control whether comments are formatted. I set the default to false (i.e. restoring the previous behavior if no options are set), because adding this felt to me like a breaking change (so this reverts it), and because it seems to me like the more common usage (which we may as well follow if it's not a breaking change). WithComments() restores the behavior added in #263. If others disagree I'm happy to keep the changed default, and instead provide WithoutComments(). I also added tests both ways (and for the existing WithIndent() option), and checked that the comments tests match the existing ones, and the default tests match those from v2.6.3 (except for the addition of a few descriptions whose omission seems to have been a bug).

Comments are still parsed in any case, as adding new struct fields is no problem; and they are still included in Dump since that seems obviously parallel to struct fields and is more of a debugging thing.

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

In vektah#263, we introduced parsing of comments, as well as support for them
in the formatter. In some cases this is surely useful, but in others
it's just bloat. (And as I describe in Khan/genqlient#282, it may even
be a problem in some cases which depended on the fact that formatting
the query didn't include comments.)

In this commit I introduce an option to control whether comments are
formatted. I set the default to false (i.e. restoring the previous
behavior if no options are set), because adding this felt to me
like a breaking change, and because it seems to me like the more common
usage. `WithComments()` restores the behavior added in vektah#263. If others
disagree I'm happy to keep the changed default, and instead provide
`WithoutComments()`. I also added tests both ways (and for the existing
`WithIndent()` option), and checked that the `comments` tests match the
existing ones, and the `default` tests match those from `v2.6.3` (except
for the addition of a few descriptions whose omission seem to have been
a bug).

Comments are still parsed in any case, as adding new struct fields is no
problem; and they are still included in `Dump` since that seems
obviously parallel to struct fields and is more of a debugging thing.
@coveralls
Copy link

Coverage Status

coverage: 88.738% (+0.1%) from 88.607% when pulling 0cea54f on benjaminjkraft:benkraft.comments into 9fb1c32 on vektah:master.

@benjaminjkraft
Copy link
Contributor Author

/cc @Warashi @StevenACoffman

Copy link
Collaborator

@StevenACoffman StevenACoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never going to say no to better code comments and increased test coverage! Thanks very much!

@StevenACoffman StevenACoffman merged commit 8d1bedc into vektah:master Jul 17, 2023
5 checks passed
benjaminjkraft pushed a commit to Khan/genqlient that referenced this pull request Jul 17, 2023
See vektah/gqlparser#271

This updates gqlparser dependency to v2.5.8, which defaults to not
including comments.
This PR will update the snapshots and generated files to match that. The
AST will still include the comments in the dump, so the tweak to that
one test in parse_test.go is still necessary, so that remains in place.

Signed-off-by: Steve Coffman <steve@khanacademy.org>
mergify bot pushed a commit to infratographer/metadata-api that referenced this pull request Aug 16, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/vektah/gqlparser/v2](https://togithub.com/vektah/gqlparser)
| require | patch | `v2.5.6` -> `v2.5.8` |

---

### Release Notes

<details>
<summary>vektah/gqlparser (github.com/vektah/gqlparser/v2)</summary>

###
[`v2.5.8`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.8)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.7...v2.5.8)

#### What's Changed

- Put comments behind an option in formatter by
[@&#8203;benjaminjkraft](https://togithub.com/benjaminjkraft) in
[vektah/gqlparser#271

**Full Changelog**:
vektah/gqlparser@v2.5.7...v2.5.8

###
[`v2.5.7`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.7)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.6...v2.5.7)

#### What's Changed

- \[Snyk] Security upgrade
[@&#8203;babel/preset-env](https://togithub.com/babel/preset-env) from
7.16.11 to 7.22.6 by [@&#8203;lwc](https://togithub.com/lwc) in
[vektah/gqlparser#267
- Bump semver from 5.7.1 to 5.7.2 in /validator/imported by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[vektah/gqlparser#268
- Allow ommitting Directive arguments that are non-null if they have
defaults by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[vektah/gqlparser#270

**Full Changelog**:
vektah/gqlparser@v2.5.6...v2.5.7

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/infratographer/metadata-api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDEuMyIsInVwZGF0ZWRJblZlciI6IjM2LjQzLjIiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit to infratographer/x that referenced this pull request Aug 21, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/vektah/gqlparser/v2](https://togithub.com/vektah/gqlparser)
| require | patch | `v2.5.6` -> `v2.5.8` |

---

### Release Notes

<details>
<summary>vektah/gqlparser (github.com/vektah/gqlparser/v2)</summary>

###
[`v2.5.8`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.8)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.7...v2.5.8)

#### What's Changed

- Put comments behind an option in formatter by
[@&#8203;benjaminjkraft](https://togithub.com/benjaminjkraft) in
[vektah/gqlparser#271

**Full Changelog**:
vektah/gqlparser@v2.5.7...v2.5.8

###
[`v2.5.7`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.7)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.6...v2.5.7)

#### What's Changed

- \[Snyk] Security upgrade
[@&#8203;babel/preset-env](https://togithub.com/babel/preset-env) from
7.16.11 to 7.22.6 by [@&#8203;lwc](https://togithub.com/lwc) in
[vektah/gqlparser#267
- Bump semver from 5.7.1 to 5.7.2 in /validator/imported by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[vektah/gqlparser#268
- Allow ommitting Directive arguments that are non-null if they have
defaults by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[vektah/gqlparser#270

**Full Changelog**:
vektah/gqlparser@v2.5.6...v2.5.7

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/infratographer/x).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi44LjExIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants