Skip to content

Commit ae07174

Browse files
committed
lintcmd: export fields necessary for gob encoding
Closes gh-1370 (cherry picked from commit 81b471b)
1 parent 22a3f20 commit ae07174

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lintcmd/cmd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ func runFromLintResult(res lintResult) run {
241241
diagnostics: map[diagnosticDescriptor]diagnostic{},
242242
}
243243

244-
for _, cf := range res.checkedFiles {
244+
for _, cf := range res.CheckedFiles {
245245
out.checkedFiles[cf] = struct{}{}
246246
}
247-
for _, diag := range res.diagnostics {
247+
for _, diag := range res.Diagnostics {
248248
out.diagnostics[diag.descriptor()] = diag
249249
}
250250
return out
@@ -498,7 +498,7 @@ func (cmd *Command) lint() int {
498498
return 1
499499
}
500500

501-
for _, w := range res.warnings {
501+
for _, w := range res.Warnings {
502502
fmt.Fprintln(os.Stderr, "warning:", w)
503503
}
504504

@@ -518,18 +518,18 @@ func (cmd *Command) lint() int {
518518
}
519519

520520
if cmd.flags.formatter == "binary" {
521-
for i, s := range res.checkedFiles {
522-
res.checkedFiles[i] = relPath(s)
521+
for i, s := range res.CheckedFiles {
522+
res.CheckedFiles[i] = relPath(s)
523523
}
524-
for i := range res.diagnostics {
524+
for i := range res.Diagnostics {
525525
// We turn all paths into relative, /-separated paths. This is to make -merge work correctly when
526526
// merging runs from different OSs, with different absolute paths.
527527
//
528528
// We zero out Offset, because checkouts of code on different OSs may have different kinds of
529529
// newlines and thus different offsets. We don't ever make use of the Offset, anyway. Line and
530530
// column numbers are precomputed.
531531

532-
d := &res.diagnostics[i]
532+
d := &res.Diagnostics[i]
533533
d.Position.Filename = relPath(d.Position.Filename)
534534
d.Position.Offset = 0
535535
d.End.Filename = relPath(d.End.Filename)

lintcmd/lint.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ func newLinter(opts options) (*linter, error) {
8282
}
8383

8484
type lintResult struct {
85-
checkedFiles []string
86-
diagnostics []diagnostic
87-
warnings []string
85+
// These fields are exported so that we can gob encode them.
86+
87+
CheckedFiles []string
88+
Diagnostics []diagnostic
89+
Warnings []string
8890
}
8991

9092
type options struct {
@@ -148,8 +150,8 @@ func (l *linter) run(bconf buildConfig) (lintResult, error) {
148150
}()
149151
}
150152
res, err := l.lint(r, cfg, l.opts.patterns)
151-
for i := range res.diagnostics {
152-
res.diagnostics[i].buildName = bconf.Name
153+
for i := range res.Diagnostics {
154+
res.Diagnostics[i].buildName = bconf.Name
153155
}
154156
return res, err
155157
}
@@ -185,18 +187,18 @@ func (l *linter) lint(r *runner.Runner, cfg *packages.Config, patterns []string)
185187
panic("package has errors but isn't marked as failed")
186188
}
187189
if res.Failed {
188-
out.diagnostics = append(out.diagnostics, failed(res)...)
190+
out.Diagnostics = append(out.Diagnostics, failed(res)...)
189191
} else {
190192
if res.Skipped {
191-
out.warnings = append(out.warnings, fmt.Sprintf("skipped package %s because it is too large", res.Package))
193+
out.Warnings = append(out.Warnings, fmt.Sprintf("skipped package %s because it is too large", res.Package))
192194
continue
193195
}
194196

195197
if !res.Initial {
196198
continue
197199
}
198200

199-
out.checkedFiles = append(out.checkedFiles, res.Package.GoFiles...)
201+
out.CheckedFiles = append(out.CheckedFiles, res.Package.GoFiles...)
200202
allowedAnalyzers := filterAnalyzerNames(analyzerNames, res.Config.Checks)
201203
resd, err := res.Load()
202204
if err != nil {
@@ -215,7 +217,7 @@ func (l *linter) lint(r *runner.Runner, cfg *packages.Config, patterns []string)
215217
filtered[i].mergeIf = a.Doc.MergeIf
216218
}
217219
}
218-
out.diagnostics = append(out.diagnostics, filtered...)
220+
out.Diagnostics = append(out.Diagnostics, filtered...)
219221

220222
for _, obj := range resd.Unused.Used {
221223
// Note: a side-effect of this code is that fields in instantiated structs are handled correctly. Even
@@ -254,7 +256,7 @@ func (l *linter) lint(r *runner.Runner, cfg *packages.Config, patterns []string)
254256
if used[uo.key] {
255257
continue
256258
}
257-
out.diagnostics = append(out.diagnostics, diagnostic{
259+
out.Diagnostics = append(out.Diagnostics, diagnostic{
258260
Diagnostic: runner.Diagnostic{
259261
Position: uo.obj.DisplayPosition,
260262
Message: fmt.Sprintf("%s %s is unused", uo.obj.Kind, uo.obj.Name),

0 commit comments

Comments
 (0)