Skip to content

Commit

Permalink
feat(lint): Show human readable output by default (#6625)
Browse files Browse the repository at this point in the history
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

---

### Changes are visible to end-users: yes

- 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

### Test plan

- Manual testing; please provide instructions so we can reproduce:

Running against aspect-build/bazel-examples#346
with and without `--machine`

GitOrigin-RevId: b1915d8dc8b5406c7e09ed499a38792f4af10f42
  • Loading branch information
JesseTatasciore authored and jbedard committed Sep 3, 2024
1 parent c04c10a commit a718d44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 10 additions & 1 deletion pkg/aspect/lint/bep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions pkg/aspect/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand All @@ -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, ",")))
Expand Down

0 comments on commit a718d44

Please sign in to comment.