Skip to content
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

Linter: update and fix issues #793

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.54.2
version: v1.58.0
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ linters:
- goconst
- gocritic
- gocyclo
- goerr113
- err113
- gofmt
#- gofumpt
- goheader
Expand Down Expand Up @@ -71,19 +71,19 @@ linters-settings:
goimports:
local-prefixes: github.com/AllenDang/giu
govet:
check-shadowing: true
shadow: true
maligned:
suggest-new: true
misspell:
locale: US

run:
timeout: 5m

issues:
skip-dirs:
- .github
- build
- web

issues:
max-same-issues: 0
exclude-use-default: false
1 change: 1 addition & 0 deletions Alignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func AlignManually(alignmentType AlignmentType, widget Widget, widgetWidth float

if forceApplyWidth {
PushItemWidth(widgetWidth)

defer PopItemWidth()
}

Expand Down
4 changes: 2 additions & 2 deletions Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (c *Canvas) PathStroke(col color.Color, flags DrawFlags, thickness float32)
c.DrawList.PathStrokeV(ColorToUint(col), imgui.DrawFlags(flags), thickness)
}

func (c *Canvas) PathArcTo(center image.Point, radius, min, max float32, numSegments int32) {
c.DrawList.PathArcToV(ToVec2(center), radius, min, max, numSegments)
func (c *Canvas) PathArcTo(center image.Point, radius, minV, maxV float32, numSegments int32) {
c.DrawList.PathArcToV(ToVec2(center), radius, minV, maxV, numSegments)
}

func (c *Canvas) PathArcToFast(center image.Point, radius float32, min12, max12 int32) {
Expand Down
14 changes: 8 additions & 6 deletions CodeEditor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gocritic,govet,unused // this file is TODO. We don't want commentedOutCode linter issues here yet.
package giu

import (
Expand Down Expand Up @@ -40,6 +41,7 @@ type CodeEditorWidget struct {
// CodeEditor creates new code editor widget.
func CodeEditor() *CodeEditorWidget {
panic("Code Editor is not implemented yet!")

return &CodeEditorWidget{
title: GenAutoID("##CodeEditor"),
}
Expand Down Expand Up @@ -70,10 +72,10 @@ func (ce *CodeEditorWidget) TabSize(size int) *CodeEditorWidget {
func (ce *CodeEditorWidget) LanguageDefinition(definition LanguageDefinition) *CodeEditorWidget {
// s := ce.getState()
lookup := map[LanguageDefinition]func(){
//LanguageDefinitionSQL: s.editor.SetLanguageDefinitionSQL,
//LanguageDefinitionCPP: s.editor.SetLanguageDefinitionCPP,
//LanguageDefinitionLua: s.editor.SetLanguageDefinitionLua,
//LanguageDefinitionC: s.editor.SetLanguageDefinitionC,
// LanguageDefinitionSQL: s.editor.SetLanguageDefinitionSQL,
// LanguageDefinitionCPP: s.editor.SetLanguageDefinitionCPP,
// LanguageDefinitionLua: s.editor.SetLanguageDefinitionLua,
// LanguageDefinitionC: s.editor.SetLanguageDefinitionC,
}

setter, correctDefinition := lookup[definition]
Expand All @@ -95,7 +97,7 @@ func (ce *CodeEditorWidget) Text(str string) *CodeEditorWidget {
// ErrorMarkers sets error markers.
// func (ce *CodeEditorWidget) ErrorMarkers(markers imgui.ErrorMarkers) *CodeEditorWidget {
// ce.getState().editor.SetErrorMarkers(markers)
//return ce
// return ce
//}

// HandleKeyboardInputs sets if editor should handle keyboard input.
Expand Down Expand Up @@ -216,7 +218,7 @@ func (ce *CodeEditorWidget) Build() {
func (ce *CodeEditorWidget) getState() (state *codeEditorState) {
if state = GetState[codeEditorState](Context, ce.title); state == nil {
state = &codeEditorState{
//editor: imgui.NewTextEditor(),
// editor: imgui.NewTextEditor(),
}

SetState(Context, ce.title, state)
Expand Down
3 changes: 3 additions & 0 deletions Context.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (c *context) invalidAllState() {
s.valid = false
c.m.Unlock()
}

return true
})
}
Expand All @@ -95,11 +96,13 @@ func (c *context) cleanState() {
c.m.Lock()
valid := s.valid
c.m.Unlock()

if !valid {
c.state.Delete(k)
s.data.Dispose()
}
}

return true
})

Expand Down
6 changes: 2 additions & 4 deletions ExtraWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ var _ Widget = &DatePickerWidget{}
// DatePickerLabels represents a label string in date picker.
type DatePickerLabels string

// These constants hold strings for translations of day/month/year
// These constants hold strings for translations of day/month/year.
const (
DatePickerLabelMonth DatePickerLabels = "Month:"
DatePickerLabelYear DatePickerLabels = " Year:"
Expand Down Expand Up @@ -439,7 +439,7 @@ func (d *DatePickerWidget) StartOfWeek(weekday time.Weekday) *DatePickerWidget {
return d
}

// Translation sets a translation to specified label type
// Translation sets a translation to specified label type.
func (d *DatePickerWidget) Translation(label DatePickerLabels, value string) *DatePickerWidget {
d.translations[label] = value
return d
Expand Down Expand Up @@ -480,8 +480,6 @@ func (d *DatePickerWidget) Build() {
// --- [Build year/month widget] ---
imgui.AlignTextToFramePadding()

const yearButtonSize = 25

Table().
Size(0, 50).
Flags(0).
Expand Down
8 changes: 4 additions & 4 deletions Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ const (
ComboFlagsNone = ComboFlags(imgui.ComboFlagsNone)
// ComboFlagsPopupAlignLeft aligns the popup toward the left by default.
ComboFlagsPopupAlignLeft = ComboFlags(imgui.ComboFlagsPopupAlignLeft)
// ComboFlagsHeightSmall has max ~4 items visible.
// ComboFlagsHeightSmall has maxValue ~4 items visible.
// Tip: If you want your combo popup to be a specific size you can use SetNextWindowSizeConstraints() prior to calling BeginCombo().
ComboFlagsHeightSmall = ComboFlags(imgui.ComboFlagsHeightSmall)
// ComboFlagsHeightRegular has max ~8 items visible (default).
// ComboFlagsHeightRegular has maxValue ~8 items visible (default).
ComboFlagsHeightRegular = ComboFlags(imgui.ComboFlagsHeightRegular)
// ComboFlagsHeightLarge has max ~20 items visible.
// ComboFlagsHeightLarge has maxValue ~20 items visible.
ComboFlagsHeightLarge = ComboFlags(imgui.ComboFlagsHeightLarge)
// ComboFlagsHeightLargest has as many fitting items as possible.
ComboFlagsHeightLargest = ComboFlags(imgui.ComboFlagsHeightLargest)
Expand Down Expand Up @@ -449,7 +449,7 @@ type SliderFlags imgui.SliderFlags
// slider flags.
const (
SliderFlagsNone = SliderFlags(imgui.SliderFlagsNone)
// Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
// Clamp value to minValue/maxValue bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
SliderFlagsAlwaysClamp = SliderFlags(imgui.SliderFlagsAlwaysClamp)
// Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlagsNoRoundToFormat = SliderFlags(imgui.SliderFlagsNoRoundToFormat)
// a format-string with small amount of digits.
Expand Down
1 change: 1 addition & 0 deletions FontAtlasProsessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (a *FontAtlas) rebuildFontAtlas() {

a.stringMap.Range(func(k, v any) bool {
a.stringMap.Store(k, true)

if ks, ok := k.(rune); ok {
sb.WriteRune(ks)
}
Expand Down
2 changes: 2 additions & 0 deletions InputHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Test_InputHandle_RegisterKeyboardShortcuts(t *testing.T) {
Callback: tt.cb,
IsGlobal: tt.isGlobal,
})

combo := keyCombo{
key: tt.key,
modifier: tt.mod,
Expand All @@ -42,6 +43,7 @@ func Test_InputHandle_RegisterKeyboardShortcuts(t *testing.T) {
shortcut, exist := i.shortcuts[combo]

a.True(exist, "shortcut wasn't registered in input manager")

if tt.isGlobal {
// TODO: figure out why it doesn't work
// a.Equal(shortcut.global, tt.cb, "wrong shortcut set in input manager")
Expand Down
2 changes: 2 additions & 0 deletions Layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func Test_Layout_Range(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
counter := 0

test.layout.Range(func(w Widget) {
if _, isTestwidget := w.(*testwidget); isTestwidget {
counter++
Expand Down Expand Up @@ -95,6 +96,7 @@ func Test_Layout_Build(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
counter := 0

test.layout.Range(func(w Widget) {
if tw, isTestwidget := w.(*testwidget); isTestwidget {
tw.counter = &counter
Expand Down
2 changes: 2 additions & 0 deletions Markdown.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gocritic,govet,wsl // this file is TODO. We don't want commentedOutCode lint issues here.
package giu

// MarkdownWidget implements DearImGui markdown extension
Expand All @@ -13,6 +14,7 @@ type MarkdownWidget struct {
// Markdown creates new markdown widget.
func Markdown(md *string) *MarkdownWidget {
panic("MarkdownWidget is not implemented yet!")

return &MarkdownWidget{
md: md,
linkCb: OpenURL,
Expand Down
1 change: 1 addition & 0 deletions MasterWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (w *MasterWindow) SetInputHandler(handler InputHandler) {
w.backend.SetKeyCallback(func(key, scanCode, action, modifier int) {
k, m, a := keyFromGLFWKey(imgui.GLFWKey(key)), Modifier(modifier), Action(action)
handler.Handle(k, m, a)

if w.additionalInputCallback != nil {
w.additionalInputCallback(k, m, a)
}
Expand Down
10 changes: 5 additions & 5 deletions Plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (p *BarPlot) Plot() {
p.shift,
0, // TODO: implement
int32(p.offset),
8, // sizeof(double) = 8
8, // in fact this is sizeof(double) = 8
)
}

Expand Down Expand Up @@ -404,7 +404,7 @@ func (p *LinePlot) Plot() {
p.x0,
0, // flags
int32(p.offset),
8, // sizeof(double) = 8
8, // in fact this is sizeof(double) = 8
)
}

Expand Down Expand Up @@ -448,7 +448,7 @@ func (p *LineXYPlot) Plot() {
int32(len(p.xs)),
0, // flags
int32(p.offset),
8, // sizeof(double) = 8
8, // in fact this is sizeof(double) = 8
)
}

Expand Down Expand Up @@ -548,7 +548,7 @@ func (p *ScatterPlot) Plot() {
p.x0,
0, // TODO: implement flags
int32(p.offset),
8, // sizeof(double) = 8
8, // in fact this is sizeof(double) = 8
)
}

Expand Down Expand Up @@ -580,6 +580,6 @@ func (p *ScatterXYPlot) Plot() {
int32(len(p.xs)),
0, // TODO: implement
int32(p.offset),
8, // sizeof(double) = 8
8, // in fact this is sizeof(double) = 8
)
}
2 changes: 1 addition & 1 deletion ProgressIndicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (p *ProgressIndicatorWidget) Build() {
canvas.AddCircleFilled(centerPt2, p.radius/5, rgba)

// Draw text
if len(p.label) > 0 {
if p.label != "" {
labelWidth, _ := CalcTextSize(Context.FontAtlas.RegisterString(p.label))
labelPos := centerPt.Add(image.Pt(-1*int(labelWidth/2), int(p.radius+p.radius/5+8)))
canvas.AddText(labelPos, rgba, p.label)
Expand Down
Loading
Loading