Skip to content

Bump github.com/olekukonko/tablewriter from 0.0.5 to 1.0.6 #878

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adjust root module code for github.com/olekukonko/tablewriter 1.x API
The API of the `github.com/olekukonko/tablewriter` module was completely redesigned prior to the 1.0.0 release. This
made it incompatible with the code written for the API of the 0.0.x versions of the module.

These code changes are purely refactoring. They do not result in any change to the output of Arduino Lint.

The previous version of `github.com/olekukonko/tablewriter` had a bug that caused it to incorrectly add a blank line
when the cell content contained an explicit line break. That bug has been fixed, and so the code previously required to
work around the bug has been removed.
  • Loading branch information
per1234 committed May 20, 2025
commit 5401dc215f995711ca6997536c73b83dc936b1fd
54 changes: 42 additions & 12 deletions internal/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"github.com/arduino/arduino-lint/internal/rule/ruleresult"
"github.com/arduino/go-paths-helper"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
)

// Results is the global instance of the rule results result.Type struct
Expand Down Expand Up @@ -126,18 +128,46 @@ func (results *Type) Record(lintedProject project.Type, ruleConfiguration ruleco
prefix := fmt.Sprintf("%s: ", level)

formattedOutput := &strings.Builder{}
table := tablewriter.NewWriter(formattedOutput)
table.SetBorder(false)
table.SetColumnSeparator("")
table.SetNoWhiteSpace(true)
table.SetColWidth(width - len(prefix))
table.SetReflowDuringAutoWrap(false) // Reflow removes explicit line breaks.
table.Append([]string{prefix, message})
table.Render()
// Remove blank lines on explicit line breaks caused by tablewriter bug.
cleanedOutput := blankLineRegexp.ReplaceAllLiteralString(formattedOutput.String(), "\n")

return cleanedOutput

tableConfigBuilder := tablewriter.NewConfigBuilder()
// Configure column widths so that the text will be wrapped to the appropriate width.
tableConfigBuilder.ForColumn(0).WithMaxWidth(len(prefix))
tableConfigBuilder.ForColumn(1).WithMaxWidth(width - len(prefix))
// A trailing space is intentionally added to the "prefix" string. Trimming must be disabled to preserve that space.
tableConfigBuilder.WithTrimSpace(tw.Off)
tableConfig := tableConfigBuilder.Build()

tableRendition := tw.Rendition{
// Do not add border characters to the table.
Borders: tw.BorderNone,
Settings: tw.Settings{
/*
Do not add a separator character between columns. The trailing space on the "prefix" string serves as the
separator.
*/
Separators: tw.SeparatorsNone,
},
}

tableRenderer := renderer.NewBlueprint(tableRendition)

table := tablewriter.NewTable(
formattedOutput,
tablewriter.WithConfig(tableConfig),
tablewriter.WithRenderer(tableRenderer),
// Do not add margins to the cell content.
tablewriter.WithPadding(tw.PaddingNone),
)

if err := table.Append([]string{prefix, message}); err != nil {
panic(err)
}

if err := table.Render(); err != nil {
panic(err)
}

return formattedOutput.String()
}

if configuration.Verbose() {
Expand Down