Skip to content

Commit 29c5529

Browse files
DanilXOldez
andauthored
Add filen linter (#5081)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent d998fc2 commit 29c5529

15 files changed

+2237
-0
lines changed

.golangci.next.reference.yml

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ linters:
3636
- exhaustruct
3737
- exportloopref
3838
- fatcontext
39+
- filen
3940
- forbidigo
4041
- forcetypeassert
4142
- funlen
@@ -152,6 +153,7 @@ linters:
152153
- exhaustruct
153154
- exportloopref
154155
- fatcontext
156+
- filen
155157
- forbidigo
156158
- forcetypeassert
157159
- funlen
@@ -534,6 +536,17 @@ linters-settings:
534536
exclude:
535537
- '.+/cobra\.Command$'
536538

539+
filen:
540+
# Ignore comments when counting lines.
541+
# Default false
542+
ignore-comments: true
543+
# Max number of lines in a file.
544+
# Default: 1000
545+
max-lines: 500
546+
# Min number of lines in a file.
547+
# Default: 5
548+
min-lines: 1
549+
537550
forbidigo:
538551
# Forbid the following identifiers (list of regexp).
539552
# Default: ["^(fmt\\.Print(|f|ln)|print|println)$"]

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/Antonboom/testifylint v1.5.0
1313
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
1414
github.com/Crocmagnon/fatcontext v0.5.2
15+
github.com/DanilXO/filen v0.3.0
1516
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
1617
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0
1718
github.com/OpenPeeDeeP/depguard/v2 v2.2.0

go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

+21
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,27 @@
10121012
}
10131013
}
10141014
},
1015+
"filen": {
1016+
"type": "object",
1017+
"additionalProperties": false,
1018+
"properties": {
1019+
"ignore-comments": {
1020+
"description": "Ignore comments when counting lines.",
1021+
"type": "boolean",
1022+
"default": false
1023+
},
1024+
"max-lines": {
1025+
"description": "Max number of lines in a file.",
1026+
"type": "integer",
1027+
"default": 1000
1028+
},
1029+
"min-lines": {
1030+
"description": "Min number of lines in a file.",
1031+
"type": "integer",
1032+
"default": 5
1033+
}
1034+
}
1035+
},
10151036
"forbidigo": {
10161037
"type": "object",
10171038
"additionalProperties": false,

pkg/config/linters_settings.go

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ var defaultLintersSettings = LintersSettings{
4040
ExplicitExhaustiveMap: false,
4141
ExplicitExhaustiveSwitch: false,
4242
},
43+
Filen: FilenSettings{
44+
MinLines: 5,
45+
MaxLines: 1000,
46+
IgnoreComments: false,
47+
},
4348
Forbidigo: ForbidigoSettings{
4449
ExcludeGodocExamples: true,
4550
},
@@ -214,6 +219,7 @@ type LintersSettings struct {
214219
ErrorLint ErrorLintSettings
215220
Exhaustive ExhaustiveSettings
216221
Exhaustruct ExhaustructSettings
222+
Filen FilenSettings
217223
Forbidigo ForbidigoSettings
218224
Funlen FunlenSettings
219225
Gci GciSettings
@@ -418,6 +424,12 @@ type ExhaustructSettings struct {
418424
Exclude []string `mapstructure:"exclude"`
419425
}
420426

427+
type FilenSettings struct {
428+
IgnoreComments bool `mapstructure:"ignore-comments"`
429+
MaxLines int `mapstructure:"max-lines"`
430+
MinLines int `mapstructure:"min-lines"`
431+
}
432+
421433
type ForbidigoSettings struct {
422434
Forbid []ForbidigoPattern `mapstructure:"forbid"`
423435
ExcludeGodocExamples bool `mapstructure:"exclude-godoc-examples"`

pkg/golinters/filen/filen.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package filen
2+
3+
import (
4+
"github.com/DanilXO/filen/pkg/filen"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/config"
8+
"github.com/golangci/golangci-lint/pkg/goanalysis"
9+
)
10+
11+
func New(settings *config.FilenSettings) *goanalysis.Linter {
12+
a := filen.NewAnalyzer(&filen.Runner{
13+
MaxLines: settings.MaxLines,
14+
MinLines: settings.MinLines,
15+
IgnoreComments: settings.IgnoreComments,
16+
})
17+
18+
return goanalysis.NewLinter(
19+
a.Name,
20+
a.Doc,
21+
[]*analysis.Analyzer{a},
22+
nil,
23+
).WithLoadMode(goanalysis.LoadModeSyntax)
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package filen
2+
3+
import (
4+
"testing"
5+
6+
"github.com/golangci/golangci-lint/test/testshared/integration"
7+
)
8+
9+
func TestFromTestdata(t *testing.T) {
10+
integration.RunTestdata(t)
11+
}

0 commit comments

Comments
 (0)