Skip to content

Commit 82a623c

Browse files
committed
feat: deprecate gomnd, add mnd
1 parent 0d8e137 commit 82a623c

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
@@ -779,38 +779,6 @@ linters-settings:
779779
# Default: ""
780780
local-prefixes: github.com/org/project
781781

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

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

.golangci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,12 @@ issues:
178178
- path: pkg/golinters/gci.go
179179
linters: [staticcheck]
180180
text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead."
181-
- path: pkg/golinters/gomnd.go
181+
- path: pkg/golinters/mnd.go
182182
linters: [staticcheck]
183183
text: "SA1019: settings.Settings is deprecated: use root level settings instead."
184+
- path: pkg/golinters/mnd.go
185+
linters: [staticcheck]
186+
text: "SA1019: config.GoMndSettings is deprecated: use MndSettings."
184187

185188
# Related to `run.go`, it cannot be removed.
186189
- 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",
@@ -1394,50 +1394,6 @@
13941394
}
13951395
}
13961396
},
1397-
"gomnd": {
1398-
"type": "object",
1399-
"additionalProperties": false,
1400-
"properties": {
1401-
"ignored-files": {
1402-
"description": "List of file patterns to exclude from analysis.",
1403-
"examples": [["magic1_.*.go"]],
1404-
"type": "array",
1405-
"items": {
1406-
"type": "string"
1407-
}
1408-
},
1409-
"ignored-functions": {
1410-
"description": "Comma-separated list of function patterns to exclude from the analysis.",
1411-
"examples": [["math.*", "http.StatusText", "make"]],
1412-
"type": "array",
1413-
"items": {
1414-
"type": "string"
1415-
}
1416-
},
1417-
"ignored-numbers": {
1418-
"description": "List of numbers to exclude from analysis.",
1419-
"examples": [["1000", "1234_567_890", "3.14159264"]],
1420-
"type": "array",
1421-
"items": {
1422-
"type": "string"
1423-
}
1424-
},
1425-
"checks": {
1426-
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
1427-
"type": "array",
1428-
"items": {
1429-
"enum": [
1430-
"argument",
1431-
"case",
1432-
"condition",
1433-
"operation",
1434-
"return",
1435-
"assign"
1436-
]
1437-
}
1438-
}
1439-
}
1440-
},
14411397
"gomoddirectives": {
14421398
"type": "object",
14431399
"additionalProperties": false,
@@ -2027,6 +1983,50 @@
20271983
}
20281984
}
20291985
},
1986+
"mnd": {
1987+
"type": "object",
1988+
"additionalProperties": false,
1989+
"properties": {
1990+
"ignored-files": {
1991+
"description": "List of file patterns to exclude from analysis.",
1992+
"examples": [["magic1_.*.go"]],
1993+
"type": "array",
1994+
"items": {
1995+
"type": "string"
1996+
}
1997+
},
1998+
"ignored-functions": {
1999+
"description": "Comma-separated list of function patterns to exclude from the analysis.",
2000+
"examples": [["math.*", "http.StatusText", "make"]],
2001+
"type": "array",
2002+
"items": {
2003+
"type": "string"
2004+
}
2005+
},
2006+
"ignored-numbers": {
2007+
"description": "List of numbers to exclude from analysis.",
2008+
"examples": [["1000", "1234_567_890", "3.14159264"]],
2009+
"type": "array",
2010+
"items": {
2011+
"type": "string"
2012+
}
2013+
},
2014+
"checks": {
2015+
"description": "The list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.",
2016+
"type": "array",
2017+
"items": {
2018+
"enum": [
2019+
"argument",
2020+
"case",
2021+
"condition",
2022+
"operation",
2023+
"return",
2024+
"assign"
2025+
]
2026+
}
2027+
}
2028+
}
2029+
},
20302030
"nolintlint": {
20312031
"type": "object",
20322032
"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)