Skip to content

Commit

Permalink
Simplify non-verbose rule output
Browse files Browse the repository at this point in the history
Previously, the output resulting from rule violations was always prefaced with the rule ID and result:

Rule SD001 result: fail

This is necessary in verbose output mode because in that mode the result of every rule applied to the project is printed.
This is the only way to identify the rule and result when a rule passes.

The situation is different non-verbose mode, where output is only printed when a rule is violated. This means that:

- The rule is identified by the rule message
- The rule result is implicit

So this preface doesn't really serve any purpose in non-verbose mode. It is somewhat cryptic, so may make the output less
approachable to the users. Because the rule ID is still sometimes of value as a succinct and unequivocal way to refer to
a specific rule, it is printed in a less prominent location at the end of the rule message.
  • Loading branch information
per1234 committed Jul 19, 2021
1 parent a8641c3 commit 64551f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion internal/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ func (results *Type) Record(lintedProject project.Type, ruleConfiguration ruleco
}

summaryText := ""
if (ruleResult == ruleresult.Fail) || configuration.Verbose() {
if configuration.Verbose() {
summaryText = fmt.Sprintf("Rule %s result: %s", ruleConfiguration.ID, ruleResult)
// Add explanation of rule result if present.
if ruleMessage != "" {
summaryText += fmt.Sprintf("\n%s: %s", ruleLevel, ruleMessage)
}
summaryText += "\n"
} else {
if ruleResult == ruleresult.Fail {
summaryText = fmt.Sprintf("%s: %s (Rule %s)\n", ruleLevel, ruleMessage, ruleConfiguration.ID)
}
}

reportExists, projectReportIndex := results.getProjectReportIndex(lintedProject.Path)
Expand Down
2 changes: 1 addition & 1 deletion internal/result/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestRecord(t *testing.T) {
flags.Set("verbose", "false")
require.Nil(t, configuration.Initialize(flags, projectPaths))
summaryText = results.Record(lintedProject, ruleConfiguration, ruleresult.Fail, ruleOutput)
assert.Equal(t, fmt.Sprintf("Rule %s result: %s\n%s: %s\n", ruleConfiguration.ID, ruleresult.Fail, rulelevel.Error, message(ruleConfiguration.MessageTemplate, ruleOutput)), summaryText)
assert.Equal(t, fmt.Sprintf("%s: %s (Rule %s)\n", rulelevel.Error, message(ruleConfiguration.MessageTemplate, ruleOutput), ruleConfiguration.ID), summaryText)
summaryText = results.Record(lintedProject, ruleConfiguration, ruleresult.NotRun, ruleOutput)
assert.Equal(t, "", summaryText, "Non-fail result should not result in output in non-verbose mode")
summaryText = results.Record(lintedProject, ruleConfiguration, ruleresult.Pass, "")
Expand Down
2 changes: 1 addition & 1 deletion test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_verbose(run_command):
result = run_command(cmd=["--format", "text", project_path])
assert result.ok
assert "result: pass" not in result.stdout
assert "result: fail" in result.stdout
assert "WARNING:" in result.stdout

result = run_command(cmd=["--format", "text", "--verbose", project_path])
assert result.ok
Expand Down

0 comments on commit 64551f8

Please sign in to comment.