From a29ba579a7769b3c3a94164efeffed4715512678 Mon Sep 17 00:00:00 2001 From: Jesse Tatasciore Date: Tue, 3 Sep 2024 17:29:47 -0400 Subject: [PATCH] feat(lint): Show human readable output by default (#6625) We were always showing the linting sarif output from the CLI. Instead default to the human readable version and request the machine readable one from workflows --- - Searched for relevant documentation and updated as needed: no - Breaking change (forces users to change their own code or config): yes - Suggested release notes appear below: yes The CLI now outputs linting results in human readable form by default. To get the machine readable version, use the `--machine` flag - Manual testing; please provide instructions so we can reproduce: Running against https://github.com/aspect-build/bazel-examples/pull/346 with and without `--machine` GitOrigin-RevId: b1915d8dc8b5406c7e09ed499a38792f4af10f42 --- docs/aspect_lint.md | 9 +++++---- pkg/aspect/lint/bep.go | 11 ++++++++++- pkg/aspect/lint/lint.go | 19 +++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/docs/aspect_lint.md b/docs/aspect_lint.md index b3a9a7113..1838c287c 100755 --- a/docs/aspect_lint.md +++ b/docs/aspect_lint.md @@ -21,10 +21,11 @@ aspect lint [flags] ### Options ``` - --diff Show unified diff instead of diff stats for fixes - --fix Apply all patch fixes for lint violations - -h, --help help for lint - --report Output lint reports (default true) + --diff Show unified diff instead of diff stats for fixes + --fix Apply all patch fixes for lint violations + -h, --help help for lint + --machine Request the machine readable output from linters + --report Output lint reports (default true) ``` ### Options inherited from parent commands diff --git a/pkg/aspect/lint/bep.go b/pkg/aspect/lint/bep.go index dc93e60ee..925862533 100644 --- a/pkg/aspect/lint/bep.go +++ b/pkg/aspect/lint/bep.go @@ -144,7 +144,7 @@ func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEven result.mnemonic = mnemonic } result.patchFile = file - } else if outputGroup.Name == LINT_MACHINE_GROUP { + } else if outputGroup.Name == LINT_REPORT_GROUP_MACHINE { if mnemonic := parseLinterMnemonicFromFilename(file.Name); mnemonic != "" { result.mnemonic = mnemonic } @@ -153,6 +153,15 @@ func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEven } else if strings.HasSuffix(file.Name, ".exit_code") { result.exitCodeFile = file } + } else if outputGroup.Name == LINT_REPORT_GROUP_HUMAN { + if mnemonic := parseLinterMnemonicFromFilename(file.Name); mnemonic != "" { + result.mnemonic = mnemonic + } + if strings.HasSuffix(file.Name, ".out") { + result.reportFile = file + } else if strings.HasSuffix(file.Name, ".exit_code") { + result.exitCodeFile = file + } } } } diff --git a/pkg/aspect/lint/lint.go b/pkg/aspect/lint/lint.go index 91bf0419e..705e6f9fe 100644 --- a/pkg/aspect/lint/lint.go +++ b/pkg/aspect/lint/lint.go @@ -62,11 +62,12 @@ type Linter struct { // Align with rules_lint const ( - LINT_MACHINE_GROUP = "rules_lint_machine" - LINT_PATCH_GROUP = "rules_lint_patch" - LINT_RESULT_REGEX = ".*AspectRulesLint.*" - HISTOGRAM_CHARS = 20 - MAX_FILENAME_WIDTH = 80 + LINT_REPORT_GROUP_HUMAN = "rules_lint_human" + LINT_REPORT_GROUP_MACHINE = "rules_lint_machine" + LINT_PATCH_GROUP = "rules_lint_patch" + LINT_RESULT_REGEX = ".*AspectRulesLint.*" + HISTOGRAM_CHARS = 20 + MAX_FILENAME_WIDTH = 80 ) func New( @@ -85,6 +86,7 @@ func AddFlags(flags *pflag.FlagSet) { flags.Bool("fix", false, "Apply all patch fixes for lint violations") flags.Bool("diff", false, "Show unified diff instead of diff stats for fixes") flags.Bool("report", true, "Output lint reports") + flags.Bool("machine", false, "Request the machine readable output from linters") } // TODO: hoist this to a flags package so it can be used by other commands that require this functionality @@ -158,6 +160,7 @@ lint: applyAll, _ := cmd.Flags().GetBool("fix") showDiff, _ := cmd.Flags().GetBool("diff") printReport, _ := cmd.Flags().GetBool("report") + machine, _ := cmd.Flags().GetBool("machine") // Separate out the lint command specific flags from the list of args to // pass to `bazel build` @@ -183,7 +186,11 @@ lint: outputGroups = append(outputGroups, LINT_PATCH_GROUP) } if printReport { - outputGroups = append(outputGroups, LINT_MACHINE_GROUP) + if machine { + outputGroups = append(outputGroups, LINT_REPORT_GROUP_MACHINE) + } else { + outputGroups = append(outputGroups, LINT_REPORT_GROUP_HUMAN) + } } bazelCmd = append(bazelCmd, fmt.Sprintf("--output_groups=%s", strings.Join(outputGroups, ",")))