Skip to content
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
7 changes: 7 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ linters:
- ineffassign
- interfacebloat
- intrange
- iotamixing
- ireturn
- lll
- loggercheck
Expand Down Expand Up @@ -186,6 +187,7 @@ linters:
- ineffassign
- interfacebloat
- intrange
- iotamixing
- ireturn
- lll
- loggercheck
Expand Down Expand Up @@ -1883,6 +1885,11 @@ linters:
# Default: 10
max: 5

iotamixing:
# Whether to report individual consts rather than just the const block.
# Default: false
report-individual: true

ireturn:
# List of interfaces to allow.
# Lists of the keywords and regular expressions matched to interface or package names can be used.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
dev.gaijin.team/go/exhaustruct/v4 v4.0.0
github.com/4meepo/tagalign v1.4.3
github.com/Abirdcfly/dupword v0.1.6
github.com/AdminBenni/iota-mixing v1.0.0
github.com/AlwxSin/noinlineerr v1.0.5
github.com/Antonboom/errname v1.1.0
github.com/Antonboom/nilnil v1.1.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.

15 changes: 15 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@
"ineffassign",
"interfacebloat",
"intrange",
"iotamixing",
"ireturn",
"lll",
"loggercheck",
Expand Down Expand Up @@ -2429,6 +2430,17 @@
}
}
},
"iotamixingSettings": {
"type": "object",
"additionalProperties": false,
"properties": {
"report-individual": {
"description": "Whether to report individual consts rather than just the const block.",
"type": "boolean",
"default": false
}
}
},
"ireturnSettings": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -4589,6 +4601,9 @@
"ineffassign": {
"$ref": "#/definitions/settings/definitions/ineffassignSettings"
},
"iotamixing": {
"$ref": "#/definitions/settings/definitions/iotamixingSettings"
},
"ireturn": {
"$ref": "#/definitions/settings/definitions/ireturnSettings"
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ type LintersSettings struct {
Inamedparam INamedParamSettings `mapstructure:"inamedparam"`
Ineffassign IneffassignSettings `mapstructure:"ineffassign"`
InterfaceBloat InterfaceBloatSettings `mapstructure:"interfacebloat"`
IotaMixing IotaMixingSettings `mapstructure:"iotamixing"`
Ireturn IreturnSettings `mapstructure:"ireturn"`
Lll LllSettings `mapstructure:"lll"`
LoggerCheck LoggerCheckSettings `mapstructure:"loggercheck"`
Expand Down Expand Up @@ -653,6 +654,10 @@ type InterfaceBloatSettings struct {
Max int `mapstructure:"max"`
}

type IotaMixingSettings struct {
ReportIndividual bool `mapstructure:"report-individual"`
}

type IreturnSettings struct {
Allow []string `mapstructure:"allow"`
Reject []string `mapstructure:"reject"`
Expand Down
26 changes: 26 additions & 0 deletions pkg/golinters/iotamixing/iotamixing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package iotamixing

import (
im "github.com/AdminBenni/iota-mixing/pkg/analyzer"
"github.com/AdminBenni/iota-mixing/pkg/analyzer/flags"

"github.com/golangci/golangci-lint/v2/pkg/config"
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
)

func New(settings *config.IotaMixingSettings) *goanalysis.Linter {
cfg := map[string]any{}

if settings != nil {
cfg[flags.ReportIndividualFlagName] = settings.ReportIndividual
}

analyzer := im.GetIotaMixingAnalyzer()

flags.SetupFlags(&analyzer.Flags)

return goanalysis.
NewLinterFromAnalyzer(analyzer).
WithConfig(cfg).
WithLoadMode(goanalysis.LoadModeSyntax)
}
11 changes: 11 additions & 0 deletions pkg/golinters/iotamixing/iotamixing_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package iotamixing

import (
"testing"

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

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

import "fmt"

// iota mixing in const block containing an iota and r-val declared above.
const ( // want "iota mixing. keep iotas in separate blocks to consts with r-val"
InvalidPerBlockIotaDeclAboveAnything = "anything"
InvalidPerBlockIotaDeclAboveNotZero = iota
InvalidPerBlockIotaDeclAboveNotOne
InvalidPerBlockIotaDeclAboveNotTwo
)

// iota mixing in const block containing an iota and r-val declared below.
const ( // want "iota mixing. keep iotas in separate blocks to consts with r-val"
InvalidPerBlockIotaDeclBelowZero = iota
InvalidPerBlockIotaDeclBelowOne
InvalidPerBlockIotaDeclBelowTwo
InvalidPerBlockIotaDeclBelowAnything = "anything"
)

// iota mixing in const block containing an iota and r-val declared between consts.
const ( // want "iota mixing. keep iotas in separate blocks to consts with r-val"
InvalidPerBlockIotaDeclBetweenZero = iota
InvalidPerBlockIotaDeclBetweenOne
InvalidPerBlockIotaDeclBetweenAnything = "anything"
InvalidPerBlockIotaDeclBetweenNotTwo
)

// iota mixing in const block containing an iota and r-vals declared above, between, and below consts.
const ( // want "iota mixing. keep iotas in separate blocks to consts with r-val"
InvalidPerBlockIotaDeclMultipleAbove = "above"
InvalidPerBlockIotaDeclMultipleNotZero = iota
InvalidPerBlockIotaDeclMultipleNotOne
InvalidPerBlockIotaDeclMultipleBetween = "between"
InvalidPerBlockIotaDeclMultipleNotTwo
InvalidPerBlockIotaDeclMultipleBelow = "below"
)

// no iota mixing in a const block containing an iota and no r-vals.
const (
ValidPerBlockIotaZero = iota
ValidPerBlockIotaOne
ValidPerBlockIotaTwo
)

// no iota mixing in a const block containing r-vals and no iota.
const (
ValidPerBlockRegularSomething = "something"
ValidPerBlockRegularAnything = "anything"
)

func _() {
fmt.Println("using the std import so goland doesn't nuke it")
}
50 changes: 50 additions & 0 deletions pkg/golinters/iotamixing/testdata/iotamixing_report-individual.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//golangcitest:args -Eiotamixing
//golangcitest:config_path testdata/iotamixing_report-individual.yml
package testdata

import "fmt"

const (
InvalidPerIndividualIotaDeclAboveAnything = "anything" // want "InvalidPerIndividualIotaDeclAboveAnything is a const with r-val in same const block as iota. keep iotas in separate const blocks"
InvalidPerIndividualIotaDeclAboveNotZero = iota
InvalidPerIndividualIotaDeclAboveNotOne
InvalidPerIndividualIotaDeclAboveNotTwo
)

const (
InvalidPerIndividualIotaDeclBelowZero = iota
InvalidPerIndividualIotaDeclBelowOne
InvalidPerIndividualIotaDeclBelowTwo
InvalidPerIndividualIotaDeclBelowAnything = "anything" // want "InvalidPerIndividualIotaDeclBelowAnything is a const with r-val in same const block as iota. keep iotas in separate const blocks"
)

const (
InvalidPerIndividualIotaDeclBetweenZero = iota
InvalidPerIndividualIotaDeclBetweenOne
InvalidPerIndividualIotaDeclBetweenAnything = "anything" // want "InvalidPerIndividualIotaDeclBetweenAnything is a const with r-val in same const block as iota. keep iotas in separate const blocks"
InvalidPerIndividualIotaDeclBetweenNotTwo
)

const (
InvalidPerIndividualIotaDeclMultipleAbove = "above" // want "InvalidPerIndividualIotaDeclMultipleAbove is a const with r-val in same const block as iota. keep iotas in separate const blocks"
InvalidPerIndividualIotaDeclMultipleNotZero = iota
InvalidPerIndividualIotaDeclMultipleNotOne
InvalidPerIndividualIotaDeclMultipleBetween = "between" // want "InvalidPerIndividualIotaDeclMultipleBetween is a const with r-val in same const block as iota. keep iotas in separate const blocks"
InvalidPerIndividualIotaDeclMultipleNotTwo
InvalidPerIndividualIotaDeclMultipleBelow = "below" // want "InvalidPerIndividualIotaDeclMultipleBelow is a const with r-val in same const block as iota. keep iotas in separate const blocks"
)

const (
ValidPerIndividualIotaZero = iota
ValidPerIndividualIotaOne
ValidPerIndividualIotaTwo
)

const (
ValidPerIndividualRegularSomething = "something"
ValidPerIndividualRegularAnything = "anything"
)

func _() {
fmt.Println("using the std import so goland doesn't nuke it")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "2"

linters:
settings:
iotamixing:
report-individual: true
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
"github.com/golangci/golangci-lint/v2/pkg/golinters/ineffassign"
"github.com/golangci/golangci-lint/v2/pkg/golinters/interfacebloat"
"github.com/golangci/golangci-lint/v2/pkg/golinters/intrange"
"github.com/golangci/golangci-lint/v2/pkg/golinters/iotamixing"
"github.com/golangci/golangci-lint/v2/pkg/golinters/ireturn"
"github.com/golangci/golangci-lint/v2/pkg/golinters/lll"
"github.com/golangci/golangci-lint/v2/pkg/golinters/loggercheck"
Expand Down Expand Up @@ -440,6 +441,10 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/ckaznocha/intrange").
WithNoopFallback(cfg, linter.IsGoLowerThanGo122()),

linter.NewConfig(iotamixing.New(&cfg.Linters.Settings.IotaMixing)).
WithSince("v2.5.0").
WithURL("github.com/AdminBenni/iota-mixing"),

linter.NewConfig(ireturn.New(&cfg.Linters.Settings.Ireturn)).
WithSince("v1.43.0").
WithLoadForGoAnalysis().
Expand Down
Loading