Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [Unreleased]

- No changes yet.
- Revert the use of the new compiler report format and properly ungate Editions 2024 features.

## [v1.68.0] - 2026-04-14

Expand Down
3 changes: 1 addition & 2 deletions cmd/buf/internal/command/breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
bufctl.WithFileAnnotationsToStdout(),
)
if err != nil {
Expand Down Expand Up @@ -369,7 +368,7 @@ func run(
}
}
if len(allFileAnnotations) > 0 {
allFileAnnotationSet := bufanalysis.NewFileAnnotationSet(nil, allFileAnnotations...)
allFileAnnotationSet := bufanalysis.NewFileAnnotationSet(allFileAnnotations...)
if err := bufanalysis.PrintFileAnnotationSet(
container.Stdout(),
allFileAnnotationSet,
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/dep/depgraph/depgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/buf/internal/command/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(controllerErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
bufctl.WithFileAnnotationsToStdout(),
)
if err != nil {
Expand Down Expand Up @@ -173,7 +172,7 @@ func run(
}
}
if len(allFileAnnotations) > 0 {
allFileAnnotationSet := bufanalysis.NewFileAnnotationSet(nil, allFileAnnotations...)
allFileAnnotationSet := bufanalysis.NewFileAnnotationSet(allFileAnnotations...)
if flags.ErrorFormat == "config-ignore-yaml" {
if err := bufcli.PrintFileAnnotationSetLintConfigIgnoreYAMLV1(
container.Stdout(),
Expand Down
1 change: 0 additions & 1 deletion cmd/buf/internal/command/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func getBuildableWorkspace(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ func run(
container,
bufctl.WithDisableSymlinks(flags.DisableSymlinks),
bufctl.WithFileAnnotationErrorFormat(flags.ErrorFormat),
bufctl.WithColorizedFileAnnotationSetDiagnosticReport(container.LogFormat() == appext.LogFormatColor),
)
if err != nil {
return err
Expand Down
22 changes: 4 additions & 18 deletions private/buf/bufctl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io/fs"
"log/slog"
"net/http"
"os"
"slices"
"sort"

Expand Down Expand Up @@ -54,7 +53,6 @@ import (
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/bufbuild/buf/private/pkg/wasm"
"golang.org/x/term"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -215,11 +213,10 @@ type controller struct {
policyDataProvider bufpolicy.PolicyDataProvider
wktStore bufwktstore.Store

disableSymlinks bool
fileAnnotationErrorFormat string
fileAnnotationsToStdout bool
colorizedFileAnnotationSetDiagnosticReport bool
copyToInMemory bool
disableSymlinks bool
fileAnnotationErrorFormat string
fileAnnotationsToStdout bool
copyToInMemory bool

storageosProvider storageos.Provider
buffetchRefParser buffetch.RefParser
Expand Down Expand Up @@ -1368,26 +1365,15 @@ func (c *controller) handleFileAnnotationSetRetError(retErrAddr *error) {
return
}
var fileAnnotationSet bufanalysis.FileAnnotationSet
var printDiagnosticReport bool
if errors.As(*retErrAddr, &fileAnnotationSet) {
writer := c.container.Stderr()
if c.fileAnnotationsToStdout {
writer = c.container.Stdout()
} else {
// When writing to stderr, check if the input is TTY, if so, allow printing the
// diagnostic report.
//
// HACK: We need to check os.Stderr rather than writer, since c.container.Stderr()
// returns wrapped writer, which only implements io.Writer. A fix needs to be made
// upstream in order to address this.
printDiagnosticReport = term.IsTerminal(int(os.Stderr.Fd()))
}
if err := bufanalysis.PrintFileAnnotationSet(
writer,
fileAnnotationSet,
c.fileAnnotationErrorFormat,
bufanalysis.WithPrintDiagnosticReport(printDiagnosticReport),
bufanalysis.WithRenderColorizedDiagnosticReport(c.colorizedFileAnnotationSetDiagnosticReport),
); err != nil {
*retErrAddr = err
return
Expand Down
8 changes: 0 additions & 8 deletions private/buf/bufctl/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ func WithFileAnnotationsToStdout() ControllerOption {
}
}

// WithColorizedFileAnnotationSetDiagnosticReport returns a new ControllerOptions that sets
// whether or not to render a colorized diagnostic report for the FileAnnotationSet.
func WithColorizedFileAnnotationSetDiagnosticReport(colorizedFileAnnotationSetDiagnosticReport bool) ControllerOption {
return func(controller *controller) {
controller.colorizedFileAnnotationSetDiagnosticReport = colorizedFileAnnotationSetDiagnosticReport
}
}

// WithCopyToInMemory returns a new ControllerOption that copies to memory.
func WithCopyToInMemory() ControllerOption {
return func(controller *controller) {
Expand Down
65 changes: 3 additions & 62 deletions private/bufpkg/bufanalysis/bufanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"io"
"strconv"
"strings"

"github.com/bufbuild/protocompile/experimental/report"
)

const (
Expand Down Expand Up @@ -209,77 +207,25 @@ type FileAnnotationSet interface {
// These will be deduplicated and sorted.
FileAnnotations() []FileAnnotation

// diagnosticReport returns the diagnostic [report.Report] for the [FileAnnotationSet],
// if set.
//
// This may be nil. If non-nil, it will be used as the output for
// [PrintFileAnnotationSet] when the format is set to "text", rendered
// with a [report.Renderer] configured by the given print options.
diagnosticReport() *report.Report

isFileAnnotationSet()
}

// NewFileAnnotationSet returns a new FileAnnotationSet.
//
// If len(fileAnnotations) is 0, this returns nil.
//
// The diagnosticReport is the [report.Report] from the compiler, if available.
// If non-nil, it will be rendered by [PrintFileAnnotationSet] when the format
// is "text". Otherwise, the individual file annotations will be used, same as
// all other print formats.
func NewFileAnnotationSet(diagnosticReport *report.Report, fileAnnotations ...FileAnnotation) FileAnnotationSet {
return newFileAnnotationSet(diagnosticReport, fileAnnotations)
}

// PrintFileAnnotationSetOption is an option for printing the FileAnnotationSet.
type PrintFileAnnotationSetOption func(*printFileAnnotationSetOptions)

// WithPrintDiagnosticReport returns a new PrintFileAnnotationSetOption that sets whether
// or not to print the diagnostic report.
//
// The diagnostic report is only use for text outputs.
func WithPrintDiagnosticReport(printDiagnosticReport bool) PrintFileAnnotationSetOption {
return func(options *printFileAnnotationSetOptions) {
options.printDiagnosticReport = printDiagnosticReport
}
}

// WithRenderColorizedDiagnosticReport returns a new PrintFileAnnotationSetOption that sets
// whether or not to render a colorized diagnostic report.
//
// The diagnostic report is only use for text outputs.
func WithRenderColorizedDiagnosticReport(colorizedDiagnosticReport bool) PrintFileAnnotationSetOption {
return func(options *printFileAnnotationSetOptions) {
options.colorizedDiagnosticReport = colorizedDiagnosticReport
}
func NewFileAnnotationSet(fileAnnotations ...FileAnnotation) FileAnnotationSet {
return newFileAnnotationSet(fileAnnotations)
}

// PrintFileAnnotationSet prints the file annotations separated by newlines.
func PrintFileAnnotationSet(writer io.Writer, fileAnnotationSet FileAnnotationSet, formatString string, options ...PrintFileAnnotationSetOption) error {
opts := &printFileAnnotationSetOptions{}
for _, option := range options {
option(opts)
}

func PrintFileAnnotationSet(writer io.Writer, fileAnnotationSet FileAnnotationSet, formatString string) error {
format, err := ParseFormat(formatString)
if err != nil {
return err
}

switch format {
case FormatText:
if diagnosticReport := fileAnnotationSet.diagnosticReport(); diagnosticReport != nil && opts.printDiagnosticReport {
// TODO: There is a follow-up effort to organize the way compiler warnings are
// handled vs. lint/breaking change rules. For now, only render the errors and
// suppress compiler warnings.
diagnosticReport.Options.SuppressWarnings = true
renderer := report.Renderer{
Colorize: opts.colorizedDiagnosticReport,
}
_, _, err := renderer.Render(diagnosticReport, writer)
return err
}
return printAsText(writer, fileAnnotationSet.FileAnnotations())
case FormatJSON:
return printAsJSON(writer, fileAnnotationSet.FileAnnotations())
Expand All @@ -295,8 +241,3 @@ func PrintFileAnnotationSet(writer io.Writer, fileAnnotationSet FileAnnotationSe
return fmt.Errorf("unknown FileAnnotation Format: %v", format)
}
}

type printFileAnnotationSetOptions struct {
printDiagnosticReport bool
colorizedDiagnosticReport bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestBasic(t *testing.T) {
),
}
sb := &strings.Builder{}
err := bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), "text")
err := bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(fileAnnotations...), "text")
require.NoError(t, err)
assert.Equal(
t,
Expand All @@ -59,7 +59,7 @@ path/to/file.proto:2:1:Hello. (buf-plugin-foo)
sb.String(),
)
sb.Reset()
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), "json")
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(fileAnnotations...), "json")
require.NoError(t, err)
assert.Equal(
t,
Expand All @@ -69,7 +69,7 @@ path/to/file.proto:2:1:Hello. (buf-plugin-foo)
sb.String(),
)
sb.Reset()
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), "msvs")
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(fileAnnotations...), "msvs")
require.NoError(t, err)
assert.Equal(t,
`path/to/file.proto(1,1) : error FOO : Hello.
Expand All @@ -78,7 +78,7 @@ path/to/file.proto(2,1) : error FOO : Hello. (buf-plugin-foo)
sb.String(),
)
sb.Reset()
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), "junit")
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(fileAnnotations...), "junit")
require.NoError(t, err)
assert.Equal(t,
`<testsuites>
Expand All @@ -98,7 +98,6 @@ path/to/file.proto(2,1) : error FOO : Hello. (buf-plugin-foo)
err = bufanalysis.PrintFileAnnotationSet(
sb,
bufanalysis.NewFileAnnotationSet(
nil,
append(
fileAnnotations,
newFileAnnotation(
Expand Down Expand Up @@ -136,7 +135,7 @@ path/to/file.proto(2,1) : error FOO : Hello. (buf-plugin-foo)
sb.String(),
)
sb.Reset()
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), "gitlab-code-quality")
err = bufanalysis.PrintFileAnnotationSet(sb, bufanalysis.NewFileAnnotationSet(fileAnnotations...), "gitlab-code-quality")
require.NoError(t, err)
assert.Equal(t,
`[{"description":"Hello.","check_name":"FOO","fingerprint":"7fa769d9df9f6db3b793316aa485c307df262ece452189a1c434e77480e9a6a26759f7616faf70c654639075b2fd170d3b66eef686ad402c72b550305883a7b7","location":{"path":"path/to/file.proto","positions":{"begin":{"line":1},"end":{"line":1}}},"severity":"minor"},{"description":"Hello.","check_name":"FOO","fingerprint":"60eab160b8308bb2c5fb823e200a54d58749513e2f2ad28447584f7223812f106a746ab7bf5fa5493e2e320163f86b46d098cb398f1795715617a825665e2a89","location":{"path":"path/to/file.proto","positions":{"begin":{"line":2,"column":1},"end":{"line":2,"column":1}}},"severity":"minor"}]
Expand Down
10 changes: 1 addition & 9 deletions private/bufpkg/bufanalysis/file_annotation_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ import (
"sort"
"strconv"
"strings"

"github.com/bufbuild/protocompile/experimental/report"
)

type fileAnnotationSet struct {
fileAnnotations []FileAnnotation
report *report.Report
}

func newFileAnnotationSet(diagnosticReport *report.Report, fileAnnotations []FileAnnotation) *fileAnnotationSet {
func newFileAnnotationSet(fileAnnotations []FileAnnotation) *fileAnnotationSet {
if len(fileAnnotations) == 0 {
return nil
}
return &fileAnnotationSet{
fileAnnotations: deduplicateAndSortFileAnnotations(fileAnnotations),
report: diagnosticReport,
}
}

Expand All @@ -53,10 +49,6 @@ func (f *fileAnnotationSet) String() string {
return sb.String()
}

func (f *fileAnnotationSet) diagnosticReport() *report.Report {
return f.report
}

func (f *fileAnnotationSet) Error() string {
return f.String()
}
Expand Down
2 changes: 0 additions & 2 deletions private/bufpkg/bufcheck/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (c *client) Lint(
return nil
}
return bufanalysis.NewFileAnnotationSet(
nil,
annotationsToFileAnnotations(
imageToPathToExternalPath(
image,
Expand Down Expand Up @@ -303,7 +302,6 @@ func (c *client) Breaking(
return nil
}
return bufanalysis.NewFileAnnotationSet(
nil,
annotationsToFileAnnotations(
imageToPathToExternalPath(
image,
Expand Down
2 changes: 1 addition & 1 deletion private/bufpkg/bufimage/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func compileImage(
)
}
if len(fileAnnotations) > 0 {
return nil, bufanalysis.NewFileAnnotationSet(diagnostics, fileAnnotations...)
return nil, bufanalysis.NewFileAnnotationSet(fileAnnotations...)
}

// Validate that there is a single result for all files
Expand Down
2 changes: 1 addition & 1 deletion private/bufpkg/bufprotocompile/bufprotocompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func FileAnnotationSetForErrorsWithPos(
if err != nil {
return nil, err
}
return bufanalysis.NewFileAnnotationSet(nil, fileAnnotations...), nil
return bufanalysis.NewFileAnnotationSet(fileAnnotations...), nil
}

// FileAnnotationOption is an option when creating a FileAnnotation.
Expand Down
Loading
Loading