Skip to content

Fix library usage #473

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

Merged
merged 2 commits into from
May 17, 2025
Merged

Fix library usage #473

merged 2 commits into from
May 17, 2025

Conversation

yoheimuta
Copy link
Owner

This pull request refactors the protolint codebase to improve modularity by introducing a new libinternal package and updating the usage of linting functionality across the project. It also includes changes to streamline testing and enhance error handling. Below is a summary of the most important changes:

Refactoring for Modularity

  • Introduced a new libinternal package to encapsulate core linting logic, including the Lint function, LintRunner interface, and error definitions (ErrLintFailure and ErrInternalFailure). This improves separation of concerns and reduces coupling between internal components (internal/libinternal/lint.go).
  • Updated the lib package to delegate linting logic to libinternal, simplifying its implementation. The lib.Lint function now auto-initializes the default runner if none is set (lib/lint.go). [1] [2]

Code Adjustments for Refactoring

  • Replaced direct usage of the lib package with libinternal in various files, such as cmd/lint_runner.go and mcp/tools.go, to align with the new modular structure. This includes changes to function calls and error handling (internal/cmd/lint_runner.go, mcp/tools.go). [1] [2] [3] [4]

Testing Enhancements

  • Refactored the mock implementation of LintRunner into a separate test package (lib_test) and introduced a NewMockLintRunner function for cleaner test setup. This ensures the original runner is restored after tests (lib/mock_lint_runner_test.go). [1] [2]
  • Updated lib/lint_test.go to use the new NewMockLintRunner function for testing, ensuring isolation and maintainability of test cases.

Documentation Updates

  • Updated the README.md file to include a more comprehensive example of using protolint from Go code, demonstrating error handling and output processing (README.md).

@yoheimuta yoheimuta requested a review from Copilot May 17, 2025 09:59
@yoheimuta yoheimuta linked an issue May 17, 2025 that may be closed by this pull request
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 the protolint codebase to improve modularity by introducing a new libinternal package to encapsulate core linting functionality and update related usages across the project. Key changes include:

  • Redirecting the linting functionality from the lib package to the new libinternal package in production and test code.
  • Refactoring the test setup to use a dedicated NewMockLintRunner function.
  • Updating the documentation to reflect these internal changes.

Reviewed Changes

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

Show a summary per file
File Description
mcp/tools.go Updated import and error handling to use libinternal.
lib/mock_lint_runner_test.go Changed package and replaced init() with NewMockLintRunner.
lib/lint_test.go Updated test setup to use the new NewMockLintRunner function.
lib/lint.go Delegated default runner management to libinternal with auto-init.
internal/libinternal/lint.go Introduced new core linting functionality encapsulated in libinternal.
internal/cmd/lint_runner.go Updated runner initialization to use libinternal's runner setter.
README.md Adjusted usage examples to reflect new modular changes.

Comment on lines +41 to +42
if libinternal.GetLintRunner() == nil {
cmd.Initialize()
Copy link
Preview

Copilot AI May 17, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider caching the initialized runner in a local variable after calling cmd.Initialize() to avoid potentially re-evaluating the nil check on subsequent Lint calls.

Suggested change
if libinternal.GetLintRunner() == nil {
cmd.Initialize()
runner := libinternal.GetLintRunner()
if runner == nil {
cmd.Initialize()
runner = libinternal.GetLintRunner()

Copilot uses AI. Check for mistakes.

@yoheimuta yoheimuta merged commit d3bf2ab into master May 17, 2025
6 checks passed
@yoheimuta yoheimuta deleted the fix-lib-lint/471 branch May 17, 2025 10:02
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.

Default lint runner set to mock runner breaks library usage
1 participant