dev/sg: rework lint package to allow FixableLinter and -fix
There are no commits yet
Push commits to the source branch or add previously merged commits to review them.
Created by: bobheadxi
Refactors the lint
package to now export two main ways to build linters:
Linter
, which implements a Check(...)
FixableLinter
, which also implements a Fix(...)
Using this, sg lint
now:
sg lint
, runs checks and suggests that users run sg lint -fix
if any of the failed linters implement FixableLinter
sg lint -fix
, runs all checks, but if a linter implements FixableLinter
, also runs thatTo enable this:
repo.State
now parses the full diff up-front, so that linters do not interfere with each othergo generate
check now resets the workspace in Check
sg lint [target] -h
to allow us to surface hints that a target has fixable lintersFor back-compat, we have:
lint.ScriptCheck
, which is more or less the same as the old lint.Script
lint.FuncCheck
, which can wrap the old lint.Runner
interfaceTo demonstrate the new API and features, this PR:
go generate
linter implementation that implements FixableLinter
Linter
interface directly, because the struct func approach gives a better home for configurationCloses https://github.com/sourcegraph/sourcegraph/issues/35396
go run ./dev/sg lint
with a generate issue will suggest that it is fixable, and leave no diff in the workspace:
go run ./dv/sg lint go -h
indicates this target has linters that are fixable:
With -fix
:
Push commits to the source branch or add previously merged commits to review them.