Skip to content

Use strategic newlines to improve rule output readability #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 26, 2021
Merged

Use strategic newlines to improve rule output readability #211

merged 4 commits into from
Jul 26, 2021

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Jul 26, 2021

In the cases where a project may violate a rule multiple times, the rule message contains a list of identifiers for the
violations. Previously, this always took the form of a comma-separated list. These identifiers can sometimes be quite
long. When automatic line wrapping occurred in the middle of an identifier, it could make the message difficult to
interpret, especially now that Arduino Lint wraps its own output in a tabular form.

The solution is to insert line breaks into the rule message where appropriate. This is done for all violation identifier
lists that are likely to have long identifiers, as well as additional locations as needed.

The rule ID is appended to the rule message and there are also situations where the rule message structure will contain
other text after the violation identifier list. For this reason, the list is indented to visually differentiate it from
the non-list message text that follows the list.

Example output before:

ERROR: .exe file(s) found. Presence of these files blocks addition to the Library
       Manager index: deleteme-testdata/bar.exe deleteme-testdata/examples/baz.exe
       deleteme-testdata/examples/qux/asdf.exe (Rule LS007)

after:

ERROR: .exe file(s) found. Presence of these files blocks addition to the Library Manager index:
         deleteme-testdata/bar.exe
         deleteme-testdata/examples/baz.exe
         deleteme-testdata/examples/qux/asdf.exe
       (Rule LS007)

per1234 added 4 commits July 25, 2021 12:24
The `github.com/olekukonko/tablewriter` package used for formatting of the rule output does not correctly handle text
with explicit (as opposed by ones added during auto-wrapping) line breaks.

With reflow enabled, these explicit line breaks are removed and the line wrapped solely based on the column width, just
as it would be without the explicit line breaks. For example, given this rule message:

```
.exe file(s) found. Presence of these files blocks addition to the Library Manager index:
deleteme-testdata\bar.exe
deleteme-testdata\examples\baz.exe
deleteme-testdata\examples\qux\asdf.exe
(Rule LS007)
```

The output is:

```
ERROR: .exe file(s) found. Presence of these files blocks addition to the Library
       Manager index: deleteme-testdata/bar.exe deleteme-testdata/examples/baz.exe
       deleteme-testdata/examples/qux/asdf.exe (Rule LS007)
```

With reflow disabled, each explicit line break becomes a blank line:

```
ERROR: .exe file(s) found. Presence of these files blocks addition to the Library Manager index:

       deleteme-testdata/bar.exe

       deleteme-testdata/examples/baz.exe

       deleteme-testdata/examples/qux/asdf.exe

       (Rule LS007)
```

I could not find any way to coerce the package to produce the desired output:

```
ERROR: .exe file(s) found. Presence of these files blocks addition to the Library Manager index:
       deleteme-testdata/bar.exe
       deleteme-testdata/examples/baz.exe
       deleteme-testdata/examples/qux/asdf.exe
       (Rule LS007)
```

so I had to resort to post-processing of the non-reflowed output to remove the spurious blank lines.
Readability of rule message output may be improved by inserting strategic line breaks. In this case, the current behavior
of appending the rule ID suffix to the non-verbose rule violation output on the same line will not always be appropriate.
So when the rule message contains explicit line breaks, the rule ID should be appended on a new line, with the previous
behavior preserved in the case of single line rule messages (which will be wrapped according to the column size).
This rule is for packages[].name value of "arduino". Since the identifier for packages is the name value and the name is
already stated in the rule message, identifying the package in violation of the rule by its ID is senseless.
In the cases where a project may violate a rule multiple times, the rule message contains a list of identifiers for the
violations. Previously, this always took the form of a comma-separated list. These identifiers can sometimes be quite
long. When automatic line wrapping occurred in the middle of an identifier, it could make the message difficult to
interpret, especially now that Arduino Lint wraps its own output in a tabular form.

The solution is to insert line breaks into the rule message where appropriate. This is done for all violation identifier
lists that are likely to have long identifiers, as well as additional locations as needed.

The rule ID is appended to the rule message and there are also situations where the rule message structure will contain
other text after the violation identifier list. For this reason, the list is indented to visually differentiate it from
the non-list message text that follows the list.
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jul 26, 2021
@per1234 per1234 requested review from ubidefeo and silvanocerza July 26, 2021 00:53
@codecov-commenter
Copy link

Codecov Report

Merging #211 (c306439) into main (3fb6daf) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #211      +/-   ##
==========================================
+ Coverage   87.96%   87.97%   +0.01%     
==========================================
  Files          43       43              
  Lines        4170     4176       +6     
==========================================
+ Hits         3668     3674       +6     
  Misses        391      391              
  Partials      111      111              
Flag Coverage Δ
unit 87.97% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ternal/rule/ruleconfiguration/ruleconfiguration.go 100.00% <ø> (ø)
internal/result/result.go 90.57% <100.00%> (+0.35%) ⬆️
internal/rule/rulefunction/library.go 94.75% <100.00%> (ø)
internal/rule/rulefunction/packageindex.go 97.28% <100.00%> (ø)
internal/rule/rulefunction/rulefunction.go 81.81% <100.00%> (+0.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fb6daf...c306439. Read the comment docs.

@per1234 per1234 requested a review from umbynos July 26, 2021 05:34
@per1234 per1234 merged commit 6edad11 into arduino:main Jul 26, 2021
@per1234 per1234 self-assigned this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants