Skip to content

feat: remove unnecessary keep comments in lists#2232

Merged
jayconrod merged 4 commits intobazel-contrib:masterfrom
PeterCardenas:remove-unnecessary-keep-comments
Nov 25, 2025
Merged

feat: remove unnecessary keep comments in lists#2232
jayconrod merged 4 commits intobazel-contrib:masterfrom
PeterCardenas:remove-unnecessary-keep-comments

Conversation

@PeterCardenas
Copy link
Copy Markdown
Contributor

@PeterCardenas PeterCardenas commented Nov 17, 2025

What type of PR is this?

feature

What package or component does this PR mostly affect?

cmd/gazelle

What does this PR do? Why is it needed?

Removes keep comments in lists when the list item was going to be kept anyways. Allows for automatic cleanup of dependencies that do not have to be manually tracked.

Which issues(s) does this PR fix?

Partially addresses #2228

@jayconrod
Copy link
Copy Markdown
Contributor

Commented in #2228. Let's discuss there before getting into PR details.

@PeterCardenas PeterCardenas force-pushed the remove-unnecessary-keep-comments branch from 6c919b0 to d1bd4b4 Compare November 20, 2025 04:51
@PeterCardenas
Copy link
Copy Markdown
Contributor Author

@jayconrod i'm not super happy with the change but maybe it illustrates the files that need to be updated. also removed the ai generated tests for clarity.
some potential steps forward:

  • create client interfaces for merging rules/files and convert functions that need the options to methods on the client so that they can access the remove_noop_keep_comments option
  • pass the config struct down to mergerules so that all options can be seen
  • just pass a bool

Comment thread merger/merger.go Outdated
Comment thread rule/rule.go Outdated
@PeterCardenas
Copy link
Copy Markdown
Contributor Author

@jayconrod fixed according to your suggestions, would appreciate your preference on how to test this (integration/unit tests/none)

Copy link
Copy Markdown
Contributor

@jayconrod jayconrod left a comment

Choose a reason for hiding this comment

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

For testing, integration tests are best, and for Gazelle they can run quickly. For each test, add a new subdirectory in tests with a MODULE.bazel file and arguments.txt. I think two (nearly identical) tests would be sufficient:

  • Unnecessary comments are removed with fix. Necessary comments are preserved.
  • Same but with -remove_noop_keep_comments.

Comment thread cmd/gazelle/fix-update.go
@jayconrod
Copy link
Copy Markdown
Contributor

The current CI failure is unrelated. Should be fixed after merging master.

@PeterCardenas PeterCardenas force-pushed the remove-unnecessary-keep-comments branch from fb4eaf6 to 4e1a3c0 Compare November 25, 2025 12:12
@PeterCardenas
Copy link
Copy Markdown
Contributor Author

PeterCardenas commented Nov 25, 2025

@jayconrod updated readme + added integration tests. seems like i revealed that i'm somehow not removing the keep comments for visibility, but maybe can tackle that later and just have this merged?

Copy link
Copy Markdown
Contributor

@jayconrod jayconrod left a comment

Choose a reason for hiding this comment

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

Looks good, thank you! Fine to fix the visibility issue in a follow-up.

@jayconrod jayconrod merged commit cb5dab0 into bazel-contrib:master Nov 25, 2025
15 checks passed
jayconrod pushed a commit that referenced this pull request Dec 2, 2025
**What type of PR is this?**

Feature

**What package or component does this PR mostly affect?**

cmd/gazelle

**What does this PR do? Why is it needed?**

Followup to #2232 to
remove keep comments for scalar attribute assignments.

**Which issues(s) does this PR fix?**

partially addresses #2228, remaining work is to remove keep comments for
non-mergeable attributes (which is a little hairy)

**Other notes for review**

Keeping things abstracted to mergeAttrValues felt more right to me,
although the code there to handle the edge cases looks a little wonky.
Would appreciate some advice there.
pcj pushed a commit to stackb/bazel-gazelle that referenced this pull request Dec 23, 2025
**What type of PR is this?**

feature

**What package or component does this PR mostly affect?**

cmd/gazelle

**What does this PR do? Why is it needed?**

Removes keep comments in lists when the list item was going to be kept
anyways. Allows for automatic cleanup of dependencies that do not have
to be manually tracked.

**Which issues(s) does this PR fix?**

Partially addresses bazel-contrib#2228
pcj pushed a commit to stackb/bazel-gazelle that referenced this pull request Dec 23, 2025
**What type of PR is this?**

Feature

**What package or component does this PR mostly affect?**

cmd/gazelle

**What does this PR do? Why is it needed?**

Followup to bazel-contrib#2232 to
remove keep comments for scalar attribute assignments.

**Which issues(s) does this PR fix?**

partially addresses bazel-contrib#2228, remaining work is to remove keep comments for
non-mergeable attributes (which is a little hairy)

**Other notes for review**

Keeping things abstracted to mergeAttrValues felt more right to me,
although the code there to handle the edge cases looks a little wonky.
Would appreciate some advice there.
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.

2 participants