Skip to content

Commit acec4e8

Browse files
committed
feat: deprecate gomnd, add mnd
1 parent 9219328 commit acec4e8

File tree

12 files changed

+167
-148
lines changed

12 files changed

+167
-148
lines changed

.golangci.next.reference.yml

+35-34
Original file line numberDiff line numberDiff line change
@@ -780,38 +780,6 @@ linters-settings:
780780
# Default: ""
781781
local-prefixes: github.com/org/project
782782

783-
gomnd:
784-
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
785-
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
786-
checks:
787-
- argument
788-
- case
789-
- condition
790-
- operation
791-
- return
792-
- assign
793-
# List of numbers to exclude from analysis.
794-
# The numbers should be written as string.
795-
# Values always ignored: "1", "1.0", "0" and "0.0"
796-
# Default: []
797-
ignored-numbers:
798-
- '0666'
799-
- '0755'
800-
- '42'
801-
# List of file patterns to exclude from analysis.
802-
# Values always ignored: `.+_test.go`
803-
# Default: []
804-
ignored-files:
805-
- 'magic1_.+\.go$'
806-
# List of function patterns to exclude from analysis.
807-
# Following functions are always ignored: `time.Date`,
808-
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
809-
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
810-
# Default: []
811-
ignored-functions:
812-
- '^math\.'
813-
- '^http\.StatusText$'
814-
815783
gomoddirectives:
816784
# Allow local `replace` directives.
817785
# Default: false
@@ -1368,6 +1336,38 @@ linters-settings:
13681336
# Default: ""
13691337
mode: restricted
13701338

1339+
mnd:
1340+
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
1341+
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
1342+
checks:
1343+
- argument
1344+
- case
1345+
- condition
1346+
- operation
1347+
- return
1348+
- assign
1349+
# List of numbers to exclude from analysis.
1350+
# The numbers should be written as string.
1351+
# Values always ignored: "1", "1.0", "0" and "0.0"
1352+
# Default: []
1353+
ignored-numbers:
1354+
- '0666'
1355+
- '0755'
1356+
- '42'
1357+
# List of file patterns to exclude from analysis.
1358+
# Values always ignored: `.+_test.go`
1359+
# Default: []
1360+
ignored-files:
1361+
- 'magic1_.+\.go$'
1362+
# List of function patterns to exclude from analysis.
1363+
# Following functions are always ignored: `time.Date`,
1364+
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
1365+
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
1366+
# Default: []
1367+
ignored-functions:
1368+
- '^math\.'
1369+
- '^http\.StatusText$'
1370+
13711371
musttag:
13721372
# A set of custom functions to check in addition to the builtin ones.
13731373
# Default: json, xml, gopkg.in/yaml.v3, BurntSushi/toml, mitchellh/mapstructure, jmoiron/sqlx
@@ -2553,7 +2553,6 @@ linters:
25532553
- gofumpt
25542554
- goheader
25552555
- goimports
2556-
- gomnd
25572556
- gomoddirectives
25582557
- gomodguard
25592558
- goprintffuncname
@@ -2574,6 +2573,7 @@ linters:
25742573
- makezero
25752574
- mirror
25762575
- misspell
2576+
- mnd
25772577
- musttag
25782578
- nakedret
25792579
- nestif
@@ -2666,7 +2666,6 @@ linters:
26662666
- gofumpt
26672667
- goheader
26682668
- goimports
2669-
- gomnd
26702669
- gomoddirectives
26712670
- gomodguard
26722671
- goprintffuncname
@@ -2687,6 +2686,7 @@ linters:
26872686
- makezero
26882687
- mirror
26892688
- misspell
2689+
- mnd
26902690
- musttag
26912691
- nakedret
26922692
- nestif
@@ -2736,6 +2736,7 @@ linters:
27362736
- ifshort # Deprecated
27372737
- interfacer # Deprecated
27382738
- maligned # Deprecated
2739+
- gomnd # Deprecated
27392740
- nosnakecase # Deprecated
27402741
- scopelint # Deprecated
27412742
- structcheck # Deprecated

.golangci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ issues:
182182
- path: pkg/golinters/gci.go
183183
linters: [staticcheck]
184184
text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead."
185-
- path: pkg/golinters/gomnd.go
185+
- path: pkg/golinters/mnd.go
186186
linters: [staticcheck]
187187
text: "SA1019: settings.Settings is deprecated: use root level settings instead."
188+
- path: pkg/golinters/mnd.go
189+
linters: [staticcheck]
190+
text: "SA1019: config.GoMndSettings is deprecated: use MndSettings."
188191

189192
# Related to `run.go`, it cannot be removed.
190193
- path: pkg/golinters/gofumpt.go

docs/src/docs/usage/false-positives.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ In the following example, all the reports from the linters (`linters`) that cont
4949
issues:
5050
exclude-rules:
5151
- linters:
52-
- gomnd
53-
text: "mnd: Magic number: 9"
52+
- mnd
53+
text: "Magic number: 9"
5454
```
5555

5656
In the following example, all the reports from the linters (`linters`) that originated from the source (`source`) are excluded:

jsonschema/golangci.next.jsonschema.json

+45-45
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@
256256
"goheader",
257257
"goimports",
258258
"golint",
259-
"gomnd",
260259
"gomoddirectives",
261260
"gomodguard",
262261
"goprintffuncname",
@@ -280,6 +279,7 @@
280279
"maligned",
281280
"mirror",
282281
"misspell",
282+
"mnd",
283283
"musttag",
284284
"nakedret",
285285
"nestif",
@@ -1408,50 +1408,6 @@
14081408
}
14091409
}
14101410
},
1411-
"gomnd": {
1412-
"type": "object",
1413-
"additionalProperties": false,
1414-
"properties": {
1415-
"ignored-files": {
1416-
"description": "List of file patterns to exclude from analysis.",
1417-
"examples": [["magic1_.*.go"]],
1418-
"type": "array",
1419-
"items": {
1420-
"type": "string"
1421-
}
1422-
},
1423-
"ignored-functions": {
1424-
"description": "Comma-separated list of function patterns to exclude from the analysis.",
1425-
"examples": [["math.*", "http.StatusText", "make"]],
1426-
"type": "array",
1427-
"items": {
1428-
"type": "string"
1429-
}
1430-
},
1431-
"ignored-numbers": {
1432-
"description": "List of numbers to exclude from analysis.",
1433-
"examples": [["1000", "1234_567_890", "3.14159264"]],
1434-
"type": "array",
1435-
"items": {
1436-
"type": "string"
1437-
}
1438-
},
1439-
"checks": {
1440-
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
1441-
"type": "array",
1442-
"items": {
1443-
"enum": [
1444-
"argument",
1445-
"case",
1446-
"condition",
1447-
"operation",
1448-
"return",
1449-
"assign"
1450-
]
1451-
}
1452-
}
1453-
}
1454-
},
14551411
"gomoddirectives": {
14561412
"type": "object",
14571413
"additionalProperties": false,
@@ -2041,6 +1997,50 @@
20411997
}
20421998
}
20431999
},
2000+
"mnd": {
2001+
"type": "object",
2002+
"additionalProperties": false,
2003+
"properties": {
2004+
"ignored-files": {
2005+
"description": "List of file patterns to exclude from analysis.",
2006+
"examples": [["magic1_.*.go"]],
2007+
"type": "array",
2008+
"items": {
2009+
"type": "string"
2010+
}
2011+
},
2012+
"ignored-functions": {
2013+
"description": "Comma-separated list of function patterns to exclude from the analysis.",
2014+
"examples": [["math.*", "http.StatusText", "make"]],
2015+
"type": "array",
2016+
"items": {
2017+
"type": "string"
2018+
}
2019+
},
2020+
"ignored-numbers": {
2021+
"description": "List of numbers to exclude from analysis.",
2022+
"examples": [["1000", "1234_567_890", "3.14159264"]],
2023+
"type": "array",
2024+
"items": {
2025+
"type": "string"
2026+
}
2027+
},
2028+
"checks": {
2029+
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
2030+
"type": "array",
2031+
"items": {
2032+
"enum": [
2033+
"argument",
2034+
"case",
2035+
"condition",
2036+
"operation",
2037+
"return",
2038+
"assign"
2039+
]
2040+
}
2041+
}
2042+
}
2043+
},
20442044
"nolintlint": {
20452045
"type": "object",
20462046
"additionalProperties": false,

pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) {
408408
}
409409

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

pkg/config/linters_settings.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ type LintersSettings struct {
243243
MaintIdx MaintIdxSettings
244244
Makezero MakezeroSettings
245245
Misspell MisspellSettings
246+
Mnd MndSettings
246247
MustTag MustTagSettings
247248
Nakedret NakedretSettings
248249
Nestif NestifSettings
@@ -549,11 +550,9 @@ type GoImportsSettings struct {
549550
LocalPrefixes string `mapstructure:"local-prefixes"`
550551
}
551552

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

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

725+
type MndSettings struct {
726+
Checks []string `mapstructure:"checks"`
727+
IgnoredNumbers []string `mapstructure:"ignored-numbers"`
728+
IgnoredFiles []string `mapstructure:"ignored-files"`
729+
IgnoredFunctions []string `mapstructure:"ignored-functions"`
730+
}
731+
726732
type NoLintLintSettings struct {
727733
RequireExplanation bool `mapstructure:"require-explanation"`
728734
RequireSpecific bool `mapstructure:"require-specific"`

pkg/golinters/gomnd.go

-58
This file was deleted.

0 commit comments

Comments
 (0)