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

---

- 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 aspect-build/bazel-examples#346
with and without `--machine`

GitOrigin-RevId: b1915d8dc8b5406c7e09ed499a38792f4af10f42
  • Loading branch information
JesseTatasciore authored and alexeagle committed Sep 4, 2024
1 parent c22237e commit aebb041
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
9 changes: 5 additions & 4 deletions docs/aspect_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ aspect lint <target patterns> [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
Expand Down
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 aebb041

Please sign in to comment.