Skip to content

Conversation

@Silic0nS0ldier
Copy link
Contributor

This PR adds a new CLI flag value for -lint, suggest. When used in conjunction with --format=json the output populates the new field .files[].warnings[].replacement.

Note that start and end are inconsistent with the existing fields.

  • .files[].warnings[].start and .files[].warnings[].end
    • .line is a 1-indexed line number.
    • .column is a 1-indexed UTF-16 code unit.
  • .files[].warnings[].replacement.start and .files[].warnings[].replacement.end
    • . is a 0-indexed byte positions.

Replacement positions are derived from []byte arrays, so conversion (to the correct encoding) would be necessary. But also;

  • Correctly detecting line endings in a manner consistent with the parser.
  • Correctly handling multi-byte sequences (and potentially Unicode grapheme clusters) in a manner consistent with the parser.

As a result normalisation is difficult, bug prone, and unless []byte usage is eliminated close to it's source, liable to carry a (minor) performance and memory penalty.

Output sample;

❯ buildifier -lint=suggest -mode=check -format json -v ___/BUILD.bazel
{
    "success": false,
    "files": [
        {
            "filename": "___/BUILD.bazel",
            "formatted": false,
            "valid": true,
            "warnings": [
                {
                    "start": {
                        "line": 259,
                        "column": 1
                    },
                    "end": {
                        "line": 259,
                        "column": 10
                    },
                    "category": "native-java-test",
                    "actionable": true,
                    "autoFixable": true,
                    "message": "Function \"java_test\" is not global anymore and needs to be loaded from \"@rules_java//java:java_test.bzl\".",
                    "url": "https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#native-java-test",
                    "replacement": {
                        "start": 57,
                        "end": 57,
                        "content": "@rules_java//java:java_test.bzl\", \"java_test\")\nload(\""
                    }
                }
            ]
        }
    ]
}

The use case for this change is integrating suggested fixes with an internal tool.

@Silic0nS0ldier Silic0nS0ldier requested a review from a team as a code owner December 11, 2025 10:15
@Silic0nS0ldier Silic0nS0ldier requested review from oreflow and removed request for a team December 11, 2025 10:15
@gemini-code-assist
Copy link

Summary of Changes

Hello @Silic0nS0ldier, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the buildifier tool by introducing a new suggest lint mode. This mode, when used with JSON output, provides detailed code replacement suggestions directly within the warning objects. The primary purpose is to facilitate the integration of buildifier's linting capabilities with external automation tools that can consume these structured suggestions to apply fixes programmatically. The changes involve updating configuration, validation logic, and the diagnostic output structures to accommodate this new functionality.

Highlights

  • New Lint Mode: Introduced a new -lint=suggest option to buildifier.
  • JSON Output Enhancement: When -lint=suggest is combined with --format=json, the output now includes a new replacement field within warnings, providing byte-offset based start/end positions and suggested content for automated fixes.
  • Compatibility Enforcement: The --lint=suggest mode is strictly enforced to be compatible only with --format=json.
  • Data Structure Updates: New data structures (replacement struct and Replacement field in warning struct) were added to buildifier/utils/diagnostics.go to support the new replacement information in the JSON output.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new -lint=suggest flag to include replacement suggestions in the JSON output. The implementation is straightforward and well-contained. I've identified two minor issues: an outdated error message and a missing omitempty tag on a new JSON field, for which I've provided suggestions. Overall, this is a valuable addition.

Silic0nS0ldier and others added 2 commits December 11, 2025 21:17
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[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.

1 participant