Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ linters:
- godot
- godox
- goheader
- golistics
- gomoddirectives
- gomodguard
- goprintffuncname
Expand Down Expand Up @@ -178,6 +179,7 @@ linters:
- godot
- godox
- goheader
- golistics
- gomoddirectives
- gomodguard
- goprintffuncname
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ require (
go.augendre.info/arangolint v0.4.0
go.augendre.info/fatcontext v0.9.0
go.uber.org/automaxprocs v1.6.0
go.ufukty.com/golistics v0.2.2
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b
golang.org/x/mod v0.32.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/golinters/golistics/golistics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package golistics

import (
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"

"go.ufukty.com/golistics/pkg/analyzer"
)

func New() *goanalysis.Linter {
return goanalysis.NewLinterFromAnalyzer(analyzer.New()).
WithLoadMode(goanalysis.LoadModeTypesInfo)
}
11 changes: 11 additions & 0 deletions pkg/golinters/golistics/golistics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package golistics

import (
"testing"

"github.com/golangci/golangci-lint/v2/test/testshared/integration"
)

func TestGolistics(t *testing.T) {
integration.RunTestdata(t)
}
124 changes: 124 additions & 0 deletions pkg/golinters/golistics/testdata/golistics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//golangcitest:args -Egolistics
package ast

import "image/color"

type Dimensional map[string]uint

type (
Display struct {
Outside string
Inside string
}
Border struct {
Color any
Style any
Width any
}
BorderRadiuses struct {
TopLeft, TopRight, BottomRight, BottomLeft any
}
Borders struct {
Top, Right, Bottom, Left Border
}
Margin struct {
Top, Right, Bottom, Left any
}
Padding struct {
Top, Right, Bottom, Left any
}
Font struct {
Family any
Size any
Weight any
}
Text struct {
Color any
LineHeight any
TextAlignment any
}
Dimensions struct {
Height any
Width any
unexported color.RGBA
}

Styles struct {
Dimensions Dimensions
Margin Margin
Padding Padding
Display Display
Text Text
Font Font
Border Borders
BorderRadiuses BorderRadiuses
BackgroundColor any
}
Rule struct {
Selector string
Styles *Styles
}
)

// implementation is not needed for test purposes
func collect(_ map[string]any) []string { return nil }
func tree(_ ...any) string { return "" }
func safeEq(a, b any) bool { return a == b }

//golistics:exported
func (s Text) Strings() []string {
return collect(map[string]any{
"Color": s.Color,
"LineHeight": s.LineHeight,
"TextAlignment": s.TextAlignment,
})
}

//golistics:exported // want `missing fields: Height, Width`
func (Dimensions) Strings() []string {
return nil
}

//golistics:exported
func (s *Styles) Strings() []string {
return collect(map[string]any{
"Dimensions": s.Dimensions,
"Margin": s.Margin,
"Padding": s.Padding,
"Display": s.Display,
"Text": s.Text,
"Font": s.Font,
"Border": s.Border,
"BorderRadiuses": s.BorderRadiuses,
"BackgroundColor": s.BackgroundColor,
})
}

//golistics:exported
func (r Rule) String() string {
return tree(r.Selector, r.Styles.Strings())
}

//golistics:all // want `missing fields: Bottom, Left, Right, Top`
func (Borders) IsEqual(Borders) bool {
return false
}

//golistics:all // want `missing field: Top`
func (s Margin) IsEqual(y Margin) bool {
return safeEq(s.Right, y.Right) &&
safeEq(s.Bottom, y.Bottom) &&
safeEq(s.Left, y.Left)
}

//golistics:exported
func (s Dimensions) IsEqual(y Dimensions) bool {
return safeEq(s.Height, y.Height) &&
safeEq(s.Width, y.Width)
}

// Suppress is exist to suppress linter error on unused & unexported
// field that is needed in [Dimensions.Strings] for testing linter behavior
func (d Dimensions) Suppress() {
_ = d.unexported
}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/golangci/golangci-lint/v2/pkg/golinters/goheader"
"github.com/golangci/golangci-lint/v2/pkg/golinters/goimports"
"github.com/golangci/golangci-lint/v2/pkg/golinters/golines"
"github.com/golangci/golangci-lint/v2/pkg/golinters/golistics"
"github.com/golangci/golangci-lint/v2/pkg/golinters/gomoddirectives"
"github.com/golangci/golangci-lint/v2/pkg/golinters/gomodguard"
"github.com/golangci/golangci-lint/v2/pkg/golinters/goprintffuncname"
Expand Down Expand Up @@ -369,6 +370,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithAutoFix().
WithURL("https://github.com/segmentio/golines"),

linter.NewConfig(golistics.New()).
WithSince("v2.9.0").
WithLoadForGoAnalysis().
WithURL("https://github.com/ufukty/golistics"),

linter.NewConfig(goheader.New(&cfg.Linters.Settings.Goheader, placeholderReplacer)).
WithSince("v1.28.0").
WithAutoFix().
Expand Down