Skip to content

Conversation

yoheimuta
Copy link
Owner

This pull request introduces several changes to enhance the functionality of proto file linting, primarily by refactoring the Finally methods across various visitors to accept a *parser.Proto parameter. Additionally, it improves handling of file name rules and introduces new test cases to validate these updates.

Refactoring of Visitor Methods:

  • Updated the Finally method in BaseVisitor, BaseFixableVisitor, and other visitor implementations (indentVisitor, orderVisitor, etc.) to accept a *parser.Proto parameter for better context during finalization. [1] [2] [3] [4] [5]

  • Modified the extendedAutoDisableVisitor and extendedDisableRuleVisitor to pass the *parser.Proto object to their inner visitors during the Finally method call. [1] [2]

File Name Rule Enhancements:

  • Introduced support for disabling the FILE_NAMES_LOWER_SNAKE_CASE rule using a directive (// protolint:disable FILE_NAMES_LOWER_SNAKE_CASE) in proto files.

  • Adjusted the fileNamesLowerSnakeCaseVisitor to rename files only when the rule is not disabled and updated its Finally method for clarity.

Test Case Additions:

  • Added test cases to verify that the FILE_NAMES_LOWER_SNAKE_CASE rule is correctly disabled when the directive is present and that no renaming occurs in such cases. [1] [2]

  • Enhanced the test suite for Finally method behavior, ensuring proper handling of the *parser.Proto parameter across various scenarios.

Interface and Usage Adjustments:

  • Updated the HasExtendedVisitor interface to remove the OnStart method and modify the Finally method to accept a *parser.Proto parameter. Adjusted the RunVisitorAutoDisable function accordingly. [1] [2]

…te visitor methods to accept proto parameter

Close #451.
@yoheimuta yoheimuta requested a review from Copilot May 18, 2025 02:07
Copy link

@Copilot 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

This PR refactors visitor finalization to receive the full *parser.Proto context, adds support for disabling the FILE_NAMES_LOWER_SNAKE_CASE rule via a comment directive, and covers this behavior with new tests.

  • Updated Finally signatures on the HasExtendedVisitor interface and all visitor implementations to accept *parser.Proto.
  • Introduced directive-based disabling for the file name snake case rule.
  • Added tests to verify disabling and non-disabling scenarios for file renaming.

Reviewed Changes

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

File Description
linter/visitor/hasExtendedVisitor.go Changed Finally() to Finally(*parser.Proto) and removed OnStart.
linter/visitor/extendedDisableRuleVisitor.go Updated Finally to check disable directive but passing no comments.
internal/addon/rules/fileNamesLowerSnakeCaseRule.go Swapped OnStart for Finally to perform rename logic.
internal/addon/rules/fileNamesLowerSnakeCaseRule_test.go Added test cases for disabling and non-disabling scenarios.
Comments suppressed due to low confidence (1)

internal/addon/rules/fileNamesLowerSnakeCaseRule_test.go:202

  • This test case is named as if it includes a disable directive, but the inputProto doesn't include a corresponding parser.Comment. Add a comment node with the disable directive so the rule actually skips renaming.
name:          "no fix for a proto with disable directive",

@yoheimuta yoheimuta merged commit 8087c37 into master May 18, 2025
6 checks passed
@yoheimuta yoheimuta deleted the fix-FILE_NAMES_LOWER_SNAKE_CASE-disable/451 branch May 18, 2025 02:09
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