Skip to content

Commit

Permalink
feat: deprecate gomnd, add mnd
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 24, 2024
1 parent 0d8e137 commit 82a623c
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 148 deletions.
69 changes: 35 additions & 34 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -779,38 +779,6 @@ linters-settings:
# Default: ""
local-prefixes: github.com/org/project

gomnd:
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
checks:
- argument
- case
- condition
- operation
- return
- assign
# List of numbers to exclude from analysis.
# The numbers should be written as string.
# Values always ignored: "1", "1.0", "0" and "0.0"
# Default: []
ignored-numbers:
- '0666'
- '0755'
- '42'
# List of file patterns to exclude from analysis.
# Values always ignored: `.+_test.go`
# Default: []
ignored-files:
- 'magic1_.+\.go$'
# List of function patterns to exclude from analysis.
# Following functions are always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- '^math\.'
- '^http\.StatusText$'

gomoddirectives:
# Allow local `replace` directives.
# Default: false
Expand Down Expand Up @@ -1367,6 +1335,38 @@ linters-settings:
# Default: ""
mode: restricted

mnd:
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
checks:
- argument
- case
- condition
- operation
- return
- assign
# List of numbers to exclude from analysis.
# The numbers should be written as string.
# Values always ignored: "1", "1.0", "0" and "0.0"
# Default: []
ignored-numbers:
- '0666'
- '0755'
- '42'
# List of file patterns to exclude from analysis.
# Values always ignored: `.+_test.go`
# Default: []
ignored-files:
- 'magic1_.+\.go$'
# List of function patterns to exclude from analysis.
# Following functions are always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- '^math\.'
- '^http\.StatusText$'

musttag:
# A set of custom functions to check in addition to the builtin ones.
# Default: json, xml, gopkg.in/yaml.v3, BurntSushi/toml, mitchellh/mapstructure, jmoiron/sqlx
Expand Down Expand Up @@ -2552,7 +2552,6 @@ linters:
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -2573,6 +2572,7 @@ linters:
- makezero
- mirror
- misspell
- mnd
- musttag
- nakedret
- nestif
Expand Down Expand Up @@ -2665,7 +2665,6 @@ linters:
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -2686,6 +2685,7 @@ linters:
- makezero
- mirror
- misspell
- mnd
- musttag
- nakedret
- nestif
Expand Down Expand Up @@ -2735,6 +2735,7 @@ linters:
- ifshort # Deprecated
- interfacer # Deprecated
- maligned # Deprecated
- gomnd # Deprecated
- nosnakecase # Deprecated
- scopelint # Deprecated
- structcheck # Deprecated
Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ issues:
- path: pkg/golinters/gci.go
linters: [staticcheck]
text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead."
- path: pkg/golinters/gomnd.go
- path: pkg/golinters/mnd.go
linters: [staticcheck]
text: "SA1019: settings.Settings is deprecated: use root level settings instead."
- path: pkg/golinters/mnd.go
linters: [staticcheck]
text: "SA1019: config.GoMndSettings is deprecated: use MndSettings."

# Related to `run.go`, it cannot be removed.
- path: pkg/golinters/gofumpt.go
Expand Down
4 changes: 2 additions & 2 deletions docs/src/docs/usage/false-positives.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ In the following example, all the reports from the linters (`linters`) that cont
issues:
exclude-rules:
- linters:
- gomnd
text: "mnd: Magic number: 9"
- mnd
text: "Magic number: 9"
```

In the following example, all the reports from the linters (`linters`) that originated from the source (`source`) are excluded:
Expand Down
90 changes: 45 additions & 45 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@
"goheader",
"goimports",
"golint",
"gomnd",
"gomoddirectives",
"gomodguard",
"goprintffuncname",
Expand All @@ -280,6 +279,7 @@
"maligned",
"mirror",
"misspell",
"mnd",
"musttag",
"nakedret",
"nestif",
Expand Down Expand Up @@ -1394,50 +1394,6 @@
}
}
},
"gomnd": {
"type": "object",
"additionalProperties": false,
"properties": {
"ignored-files": {
"description": "List of file patterns to exclude from analysis.",
"examples": [["magic1_.*.go"]],
"type": "array",
"items": {
"type": "string"
}
},
"ignored-functions": {
"description": "Comma-separated list of function patterns to exclude from the analysis.",
"examples": [["math.*", "http.StatusText", "make"]],
"type": "array",
"items": {
"type": "string"
}
},
"ignored-numbers": {
"description": "List of numbers to exclude from analysis.",
"examples": [["1000", "1234_567_890", "3.14159264"]],
"type": "array",
"items": {
"type": "string"
}
},
"checks": {
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
"type": "array",
"items": {
"enum": [
"argument",
"case",
"condition",
"operation",
"return",
"assign"
]
}
}
}
},
"gomoddirectives": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -2027,6 +1983,50 @@
}
}
},
"mnd": {
"type": "object",
"additionalProperties": false,
"properties": {
"ignored-files": {
"description": "List of file patterns to exclude from analysis.",
"examples": [["magic1_.*.go"]],
"type": "array",
"items": {
"type": "string"
}
},
"ignored-functions": {
"description": "Comma-separated list of function patterns to exclude from the analysis.",
"examples": [["math.*", "http.StatusText", "make"]],
"type": "array",
"items": {
"type": "string"
}
},
"ignored-numbers": {
"description": "List of numbers to exclude from analysis.",
"examples": [["1000", "1234_567_890", "3.14159264"]],
"type": "array",
"items": {
"type": "string"
}
},
"checks": {
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
"type": "array",
"items": {
"enum": [
"argument",
"case",
"condition",
"operation",
"return",
"assign"
]
}
}
}
},
"nolintlint": {
"type": "object",
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) {
}

func (c *runCommand) printDeprecatedLinterMessages(enabledLinters map[string]*linter.Config) {
if c.cfg.InternalCmdTest {
if c.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
return
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ type LintersSettings struct {
MaintIdx MaintIdxSettings
Makezero MakezeroSettings
Misspell MisspellSettings
Mnd MndSettings
MustTag MustTagSettings
Nakedret NakedretSettings
Nestif NestifSettings
Expand Down Expand Up @@ -549,11 +550,9 @@ type GoImportsSettings struct {
LocalPrefixes string `mapstructure:"local-prefixes"`
}

// Deprecated: use MndSettings.
type GoMndSettings struct {
Checks []string `mapstructure:"checks"`
IgnoredNumbers []string `mapstructure:"ignored-numbers"`
IgnoredFiles []string `mapstructure:"ignored-files"`
IgnoredFunctions []string `mapstructure:"ignored-functions"`
MndSettings `mapstructure:",squash"`

// Deprecated: use root level settings instead.
Settings map[string]map[string]any
Expand Down Expand Up @@ -723,6 +722,13 @@ type NlreturnSettings struct {
BlockSize int `mapstructure:"block-size"`
}

type MndSettings struct {
Checks []string `mapstructure:"checks"`
IgnoredNumbers []string `mapstructure:"ignored-numbers"`
IgnoredFiles []string `mapstructure:"ignored-files"`
IgnoredFunctions []string `mapstructure:"ignored-functions"`
}

type NoLintLintSettings struct {
RequireExplanation bool `mapstructure:"require-explanation"`
RequireSpecific bool `mapstructure:"require-specific"`
Expand Down
58 changes: 0 additions & 58 deletions pkg/golinters/gomnd.go

This file was deleted.

Loading

0 comments on commit 82a623c

Please sign in to comment.