Fix library usage#473
Merged
Merged
Conversation
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
[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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the
protolintcodebase to improve modularity by introducing a newlibinternalpackage 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
libinternalpackage to encapsulate core linting logic, including theLintfunction,LintRunnerinterface, and error definitions (ErrLintFailureandErrInternalFailure). This improves separation of concerns and reduces coupling between internal components (internal/libinternal/lint.go).libpackage to delegate linting logic tolibinternal, simplifying its implementation. Thelib.Lintfunction now auto-initializes the default runner if none is set (lib/lint.go). [1] [2]Code Adjustments for Refactoring
libpackage withlibinternalin various files, such ascmd/lint_runner.goandmcp/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
LintRunnerinto a separate test package (lib_test) and introduced aNewMockLintRunnerfunction for cleaner test setup. This ensures the original runner is restored after tests (lib/mock_lint_runner_test.go). [1] [2]lib/lint_test.goto use the newNewMockLintRunnerfunction for testing, ensuring isolation and maintainability of test cases.Documentation Updates
README.mdfile to include a more comprehensive example of usingprotolintfrom Go code, demonstrating error handling and output processing (README.md).