refactor: introduce LintReader interface, decouple linter from sdk/mpr#5
refactor: introduce LintReader interface, decouple linter from sdk/mpr#5retran wants to merge 1 commit intopr1-quick-winsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a linter.LintReader interface to decouple linting/execution code from the concrete sdk/mpr.Reader, routing lint rules through a backend-compatible reader abstraction instead.
Changes:
- Add
LintReadertomdl/linter/context.goand thread it throughLintContext. - Update lint rules to consume
LintReaderinstead of*mpr.Reader. - Remove
Executor.Reader()/ExecContext.Reader()and update lint entrypoints to passBackend()directly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
mdl/linter/rules/page_navigation_security.go |
Switch rule helper to accept linter.LintReader instead of *mpr.Reader. |
mdl/linter/context.go |
Define LintReader; update LintContext construction and Reader() accessor to use it. |
mdl/executor/executor.go |
Remove deprecated Reader(); add Backend() accessor for callers. |
mdl/executor/exec_context.go |
Remove deprecated Reader() from ExecContext. |
mdl/executor/cmd_lint.go |
Construct LintContext with ctx.Backend directly. |
cmd/mxcli/cmd_report.go |
Construct LintContext with exec.Backend(); remove Reader() plumbing. |
cmd/mxcli/cmd_lint.go |
Construct LintContext with exec.Backend(); remove Reader() plumbing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // Backend returns the full backend, or nil if not connected. | ||
| func (e *Executor) Backend() backend.FullBackend { |
There was a problem hiding this comment.
Backend() is documented as returning nil when not connected, but it currently returns e.backend even if IsConnected() is false. This can happen after a failed CONNECT where the previous backend was disconnected but ctx.Backend was never cleared, leaving a non-nil, disconnected backend reachable via Backend(). Either update the implementation to return nil unless e.backend != nil && e.backend.IsConnected(), or adjust the doc comment to reflect the actual behavior.
| func (e *Executor) Backend() backend.FullBackend { | |
| func (e *Executor) Backend() backend.FullBackend { | |
| if e.backend == nil || !e.backend.IsConnected() { | |
| return nil | |
| } |
| // IsConnected returns true if connected to a project. | ||
| func (e *Executor) IsConnected() bool { | ||
| return e.backend != nil && e.backend.IsConnected() | ||
| } | ||
|
|
||
| // Backend returns the full backend, or nil if not connected. | ||
| func (e *Executor) Backend() backend.FullBackend { | ||
| return e.backend | ||
| } |
There was a problem hiding this comment.
Removing Executor.Reader() breaks -tags integration tests that still call it (e.g. mdl/executor/roundtrip_helpers_test.go and roundtrip_doctype_test.go call env.executor.Reader().ProjectVersion()). Update those call sites to use env.executor.Backend().ProjectVersion() (or similar) so make test-integration continues to compile/run.
5e49429 to
b2c99ab
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b2c99ab to
dcf76c0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (e *Executor) Backend() backend.FullBackend { | ||
| return e.backend | ||
| } | ||
|
|
There was a problem hiding this comment.
Removing Executor.Reader() breaks any remaining call sites (notably the integration tests under mdl/executor with the integration build tag) that still call env.executor.Reader().ProjectVersion() / similar. Please update those callers to use Executor.Backend().ProjectVersion() (or, if a test truly needs the underlying SDK reader, type-assert on the backend for an MprReader() accessor) so make test-integration continues to compile and run.
| // Reader returns the backend for backward compatibility with older callers. | |
| // Prefer Backend() in new code. | |
| func (e *Executor) Reader() backend.FullBackend { | |
| return e.Backend() | |
| } |
dcf76c0 to
0091e56
Compare
0091e56 to
a94b326
Compare
Why
The linter and executor packages import
sdk/mprdirectly for*mpr.Reader, coupling them to the concrete SQLite implementation. This blocks the WASM build (PR #7 series) wheresdk/mpris unavailable, and prevents testing with mock backends. Introducing aLintReaderinterface breaks this dependency using Go's implicit interface satisfaction — zero changes needed in the 10+ linter rule files.Summary
LintReaderinterface inmdl/linter/context.gowith 7 methods matching both*mpr.ReaderandMprBackendsignatures*mpr.Readerdependency withLintReaderinterface throughout linter and executor packagesReader()methods andreaderProviderinterface from executor — callers now passBackend()directlysdk/mprimports remain inmdl/linter/andmdl/executor/production codeStacked on
Test
make build && make test && make lint-go— all pass