diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 37866ff00f2c..dbcc0377a400 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -539,6 +539,9 @@ linters: # Checks if the exported methods of a structure are placed before the non-exported ones. # Default: true struct-method: false + # Checks if the constructors and/or structure methods are sorted alphabetically. + # Default: false + alphabetical: true funlen: # Checks the number of lines in a function. diff --git a/go.mod b/go.mod index 00695fdf37ad..cfdbc0b02765 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 - github.com/manuelarte/funcorder v0.2.1 + github.com/manuelarte/funcorder v0.3.0 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 github.com/matoous/godox v1.1.0 diff --git a/go.sum b/go.sum index 9bc80fb7cd9b..b89f9c35faf7 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/manuelarte/funcorder v0.2.1 h1:7QJsw3qhljoZ5rH0xapIvjw31EcQeFbF31/7kQ/xS34= -github.com/manuelarte/funcorder v0.2.1/go.mod h1:BQQ0yW57+PF9ZpjpeJDKOffEsQbxDFKW8F8zSMe/Zd0= +github.com/manuelarte/funcorder v0.3.0 h1:mV1joNYIjIUnnyZ6wfaC+sCWB6IvG62ay3xuhbklHps= +github.com/manuelarte/funcorder v0.3.0/go.mod h1:wBFktqsi8PyQvNYEUpF5Lt+V/xqgaevfCi4SSpUhyPo= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE= github.com/maratori/testpackage v1.1.1 h1:S58XVV5AD7HADMmD0fNnziNHqKvSdDuEKdPD1rNTU04= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 0f2ef5fcc50b..9af538279cbc 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -1317,6 +1317,11 @@ "description": "Checks if the exported methods of a structure are placed before the non-exported ones.", "type": "boolean", "default": true + }, + "alphabetical": { + "description": "Checks if the constructors and/or structure methods are sorted alphabetically.", + "type": "boolean", + "default": false } } }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 16a8bb9501b9..065abfab47c1 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -428,6 +428,7 @@ type ForbidigoPattern struct { type FuncOrderSettings struct { Constructor bool `mapstructure:"constructor,omitempty"` StructMethod bool `mapstructure:"struct-method,omitempty"` + Alphabetical bool `mapstructure:"alphabetical,omitempty"` } type FunlenSettings struct { diff --git a/pkg/golinters/funcorder/funcorder.go b/pkg/golinters/funcorder/funcorder.go index 7b8e9689e587..605304f26203 100644 --- a/pkg/golinters/funcorder/funcorder.go +++ b/pkg/golinters/funcorder/funcorder.go @@ -17,6 +17,7 @@ func New(settings *config.FuncOrderSettings) *goanalysis.Linter { cfg[a.Name] = map[string]any{ analyzer.ConstructorCheckName: settings.Constructor, analyzer.StructMethodCheckName: settings.StructMethod, + analyzer.AlphabeticalCheckName: settings.Alphabetical, } }