Merge pull request #21 from navidys/golangci_lint

running golangci-lint
This commit is contained in:
Navid Yaghoobi 2023-12-15 19:38:50 +11:00 committed by GitHub
commit 0ecdc1cf6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 88 deletions

19
.github/workflows/go.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: Go
on:
push:
branches: [ main ]
jobs:
golangci-lint:
runs-on: ubuntu-latest
container:
image: fedora:latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '>=1.19.0'
- uses: actions/checkout@v4
- run: |
dnf -y install make
make .install.golangci-lint
make lint

View File

@ -34,6 +34,20 @@ jobs:
check_filenames: true
skip: ./.git,./vendor,*_test.go,go.sum,go.mod
golangci-lint:
runs-on: ubuntu-latest
container:
image: fedora:latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '>=1.19.0'
- uses: actions/checkout@v4
- run: |
dnf -y install make
make .install.golangci-lint
make lint
goreportcard:
name: update reportcard
if: github.event.pull_request.merged == true

View File

@ -5,9 +5,14 @@ run:
linters:
enable-all: true
disable:
- exhaustruct
- varnamelen
- exhaustruct
# deprecated
- structcheck
- deadcode
- varcheck
- nosnakecase
- ifshort
- golint
- maligned
- interfacer

View File

@ -23,7 +23,7 @@ install.tools: .install.pre-commit .install.codespell .install.golangci-lint ##
.PHONY: .install.golangci-lint
.install.golangci-lint:
VERSION=1.46.2 ./hack/install_golangci.sh
VERSION=1.51.1 ./hack/install_golangci.sh
#=================================================
# Linting/Formatting/Code Validation targets
@ -35,7 +35,6 @@ validate: gofmt lint govet pre-commit codespell ## Validate prometheus-podman-ex
.PHONY: lint
lint: ## Run golangci-lint
@echo "running golangci-lint"
GO111MODULE=off
$(BIN)/golangci-lint run
.PHONY: pre-commit

View File

@ -2,6 +2,7 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/navidys/tvxwidgets)](https://pkg.go.dev/github.com/navidys/tvxwidgets)
![Go](https://github.com/navidys/tvxwidgets/workflows/Go/badge.svg)
[![Go Report](https://img.shields.io/badge/go%20report-A%2B-brightgreen.svg)](https://goreportcard.com/report/github.com/navidys/tvxwidgets)
tvxwidgets provides extra widgets for [tview](https://github.com/rivo/tview).

View File

@ -61,14 +61,14 @@ func (c *BarChart) HasFocus() bool {
}
// Draw draws this primitive onto the screen.
func (c *BarChart) Draw(screen tcell.Screen) { // nolint:funlen,cyclop
func (c *BarChart) Draw(screen tcell.Screen) { //nolint:funlen,cyclop
c.Box.DrawForSubclass(screen, c)
x, y, width, height := c.Box.GetInnerRect()
maxValY := y + 1
xAxisStartY := y + height - 2 // nolint:gomnd
barStartY := y + height - 3 // nolint:gomnd
xAxisStartY := y + height - 2 //nolint:gomnd
barStartY := y + height - 3 //nolint:gomnd
borderPadding := 0
if c.hasBorder {

View File

@ -37,7 +37,7 @@ type MessageDialog struct {
bgColor tcell.Color
// message dialog text message to display.
message string
// callback for whwen user clicked on the the button or presses "enter" or "esc"
// callback for when user clicked on the button or presses "enter" or "esc"
doneHandler func()
}
@ -68,9 +68,6 @@ func NewMessageDialog(dtype int) *MessageDialog {
return dialog
}
// SetBorder sets dialogs border - no effect always true.
func (d *MessageDialog) SetBorder(status bool) {}
// SetType sets dialog type to info or error.
func (d *MessageDialog) SetType(dtype int) {
if dtype >= 0 && dtype <= 2 {
@ -79,21 +76,6 @@ func (d *MessageDialog) SetType(dtype int) {
}
}
// SetTitle sets title for this primitive.
func (d *MessageDialog) SetTitle(title string) {
d.layout.SetTitle(title)
}
// SetTitleColor sets title color.
func (g *MessageDialog) SetTitleColor(color tcell.Color) {
g.layout.SetTitleColor(color)
}
// SetTitleAlign sets title alignment.
func (g *MessageDialog) SetTitleAlign(align int) {
g.Box.SetTitleAlign(align)
}
// SetBackgroundColor sets dialog background color.
func (d *MessageDialog) SetBackgroundColor(color tcell.Color) {
d.bgColor = color
@ -144,7 +126,7 @@ func (d *MessageDialog) Draw(screen tcell.Screen) {
// InputHandler returns input handler function for this primitive.
func (d *MessageDialog) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
return d.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
if event.Key() == tcell.KeyDown || event.Key() == tcell.KeyUp || event.Key() == tcell.KeyPgDn || event.Key() == tcell.KeyPgUp { // nolint:lll
if event.Key() == tcell.KeyDown || event.Key() == tcell.KeyUp || event.Key() == tcell.KeyPgDn || event.Key() == tcell.KeyPgUp { //nolint:lll
if textHandler := d.textview.InputHandler(); textHandler != nil {
textHandler(event, setFocus)
@ -160,8 +142,8 @@ func (d *MessageDialog) InputHandler() func(event *tcell.EventKey, setFocus func
}
// MouseHandler returns the mouse handler for this primitive.
func (d *MessageDialog) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { // nolint:lll
return d.WrapMouseHandler(func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { // nolint:lll,nonamedreturns
func (d *MessageDialog) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { //nolint:lll
return d.WrapMouseHandler(func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { //nolint:lll,nonamedreturns
// Pass mouse events on to the form.
consumed, capture = d.form.MouseHandler()(action, event, setFocus)
if !consumed && action == tview.MouseLeftClick && d.InRect(event.Position()) {
@ -174,7 +156,7 @@ func (d *MessageDialog) MouseHandler() func(action tview.MouseAction, event *tce
}
// SetDoneFunc sets callback function for when user clicked on
// the the button or presses "enter" or "esc".
// the button or presses "enter" or "esc".
func (d *MessageDialog) SetDoneFunc(handler func()) *MessageDialog {
d.doneHandler = handler
enterButton := d.form.GetButton(d.form.GetButtonCount() - 1)
@ -200,7 +182,7 @@ func (d *MessageDialog) setColor() {
func (d *MessageDialog) setRect() {
maxHeight := d.height
maxWidth := d.width // nolint:ifshort
maxWidth := d.width //nolint:ifshort
messageHeight := len(strings.Split(d.message, "\n"))
messageWidth := getMessageWidth(d.message)

View File

@ -39,21 +39,6 @@ func (g *ActivityModeGauge) Draw(screen tcell.Screen) {
}
}
// SetTitle sets title for this primitive.
func (g *ActivityModeGauge) SetTitle(title string) {
g.Box.SetTitle(title)
}
// SetTitleAlign sets title alignment.
func (g *ActivityModeGauge) SetTitleAlign(align int) {
g.Box.SetTitleAlign(align)
}
// SetTitleColor sets title color.
func (g *ActivityModeGauge) SetTitleColor(color tcell.Color) {
g.Box.SetTitleColor(color)
}
// Focus is called when this primitive receives focus.
func (g *ActivityModeGauge) Focus(delegate func(p tview.Primitive)) {
}

View File

@ -69,21 +69,6 @@ func (g *PercentageModeGauge) Draw(screen tcell.Screen) {
}
}
// SetTitle sets title for this primitive.
func (g *PercentageModeGauge) SetTitle(title string) {
g.Box.SetTitle(title)
}
// SetTitleColor sets title color.
func (g *PercentageModeGauge) SetTitleColor(color tcell.Color) {
g.Box.SetTitleColor(color)
}
// SetTitleAlign sets title alignment.
func (g *PercentageModeGauge) SetTitleAlign(align int) {
g.Box.SetTitleAlign(align)
}
// Focus is called when this primitive receives focus.
func (g *PercentageModeGauge) Focus(delegate func(p tview.Primitive)) {
}

View File

@ -48,21 +48,6 @@ func NewUtilModeGauge() *UtilModeGauge {
return gauge
}
// SetTitle sets title for this primitive.
func (g *UtilModeGauge) SetTitle(title string) {
g.Box.SetTitle(title)
}
// SetTitleColor sets title color.
func (g *UtilModeGauge) SetTitleColor(color tcell.Color) {
g.Box.SetTitleColor(color)
}
// SetTitleAlign sets title alignment.
func (g *UtilModeGauge) SetTitleAlign(align int) {
g.Box.SetTitleAlign(align)
}
// SetLabel sets label for this primitive.
func (g *UtilModeGauge) SetLabel(label string) {
g.label = label

14
plot.go
View File

@ -219,13 +219,13 @@ func (plot *Plot) drawAxesToScreen(screen tcell.Screen) {
tview.Print(screen,
label,
x,
y+height-(i*(plotYAxisLabelsGap+1))-2, // nolint:gomnd
y+height-(i*(plotYAxisLabelsGap+1))-2, //nolint:gomnd
plotYAxisLabelsWidth,
tview.AlignLeft, plot.axesLabelColor)
}
}
// nolint:gocognit,cyclop
//nolint:gocognit,cyclop
func (plot *Plot) drawDotMarkerToScreen(screen tcell.Screen) {
x, y, width, height := plot.getChartAreaRect()
chartData := plot.getData()
@ -290,12 +290,12 @@ func (plot *Plot) calcBrailleLines() {
plot.setBrailleLine(
image.Pt(
(x+(j*plotHorizontalScale))*2, // nolint:gomnd
(y+height-previousHeight-1)*4, // nolint:gomnd
(x+(j*plotHorizontalScale))*2, //nolint:gomnd
(y+height-previousHeight-1)*4, //nolint:gomnd
),
image.Pt(
(x+((j+1)*plotHorizontalScale))*2, // nolint:gomnd
(y+height-lheight-1)*4, // nolint:gomnd
(x+((j+1)*plotHorizontalScale))*2, //nolint:gomnd
(y+height-lheight-1)*4, //nolint:gomnd
),
plot.lineColors[i],
)
@ -306,7 +306,7 @@ func (plot *Plot) calcBrailleLines() {
}
func (plot *Plot) setBraillePoint(p image.Point, color tcell.Color) {
point := image.Pt(p.X/2, p.Y/4) // nolint:gomnd
point := image.Pt(p.X/2, p.Y/4) //nolint:gomnd
plot.brailleCellMap[point] = brailleCell{
plot.brailleCellMap[point].cRune | brailleRune[p.Y%4][p.X%2],
color,

View File

@ -18,7 +18,7 @@ type Sparkline struct {
mu sync.Mutex
}
// NewSparkline returns a a new sparkline widget.
// NewSparkline returns a new sparkline widget.
func NewSparkline() *Sparkline {
return &Sparkline{
Box: tview.NewBox(),

View File

@ -37,14 +37,14 @@ const (
)
var (
brailleRune = [4][2]rune{ // nolint:gochecknoglobals
brailleRune = [4][2]rune{ //nolint:gochecknoglobals
{'\u0001', '\u0008'},
{'\u0002', '\u0010'},
{'\u0004', '\u0020'},
{'\u0040', '\u0080'},
}
barsRune = [...]rune{' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'} // nolint:gochecknoglobals
barsRune = [...]rune{' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'} //nolint:gochecknoglobals
)
// getColorName returns convert tcell color to its name.
@ -114,14 +114,14 @@ func absInt(x int) int {
return -x
}
func drawLine(screen tcell.Screen, x int, y int, length int, mode drawLineMode, style tcell.Style) {
func drawLine(screen tcell.Screen, startX int, startY int, length int, mode drawLineMode, style tcell.Style) {
if mode == horizontalLine {
for i := 0; i < length; i++ {
tview.PrintJoinedSemigraphics(screen, x+i, y, tview.BoxDrawingsLightTripleDashHorizontal, style)
tview.PrintJoinedSemigraphics(screen, startX+i, startY, tview.BoxDrawingsLightTripleDashHorizontal, style)
}
} else if mode == verticalLine {
for i := 0; i < length; i++ {
tview.PrintJoinedSemigraphics(screen, x, y+i, tview.BoxDrawingsLightTripleDashVertical, style)
tview.PrintJoinedSemigraphics(screen, startX, startY+i, tview.BoxDrawingsLightTripleDashVertical, style)
}
}
}