Skip to content

Add bitclear analyzer to suggest &^= A instead of &= ^A#3150

Merged
jakebailey merged 6 commits intomainfrom
jabaile/and-not-analyzer
Mar 24, 2026
Merged

Add bitclear analyzer to suggest &^= A instead of &= ^A#3150
jakebailey merged 6 commits intomainfrom
jabaile/and-not-analyzer

Conversation

@jakebailey
Copy link
Member

Go has a bit clear operator, &^= A. We've used this nearly everywhere in place of &= ^A, but some stragglers remained.

Add an analyzer that finds these cases, then allows for easy --fix.

Copilot AI review requested due to automatic review settings March 18, 2026 19:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a custom Go lint analyzer to standardize bit-clearing patterns by suggesting &^= (bit clear) in place of &= ^, and updates remaining occurrences in the compiler code to use the idiomatic operator.

Changes:

  • Replace several x &= ^y usages across internal/ with x &^= y.
  • Add a new _tools/customlint analyzer (bitclear) that reports &= ^ patterns and provides an autofix.
  • Add golden test coverage for the new analyzer diagnostics.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/transformers/tstransforms/runtimesyntax.go Convert modifier mask clearing to &^=.
internal/transformers/jsxtransforms/jsx.go Use &^= when clearing synthesized node flags.
internal/printer/printer.go Use &^= to clear multi-line/indent formatting flags.
internal/parser/parser.go Use &^= to clear parser context flags.
internal/checker/nodebuilderimpl.go Use &^= to clear nodebuilder context flags.
internal/checker/jsx.go Use &^= to clear enum flag from symbol flags.
internal/checker/checker.go Use &^= for JSX factory symbol flag adjustments.
internal/binder/binder.go Use &^= for clearing various node flags.
internal/ast/subtreefacts.go Use &^= for subtree facts bit clearing.
_tools/customlint/plugin.go Register the new bitclear analyzer in the plugin.
_tools/customlint/bitclear.go New analyzer to detect &= ^ and provide --fix edits.
_tools/customlint/testdata/bitclear/bitclear.go New test inputs for the analyzer.
_tools/customlint/testdata/bitclear/bitclear.go.golden Golden output validating reported diagnostics/ranges/messages.

You can also share your feedback on Copilot code review. Take the survey.

@jakebailey jakebailey enabled auto-merge March 24, 2026 20:53
@jakebailey jakebailey added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit bbf0402 Mar 24, 2026
21 checks passed
@jakebailey jakebailey deleted the jabaile/and-not-analyzer branch March 24, 2026 21:43
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.

3 participants