Skip to content

Commit 1b7b77e

Browse files
committed
Add new filen linter
1 parent d998fc2 commit 1b7b77e

File tree

9 files changed

+106
-1
lines changed

9 files changed

+106
-1
lines changed

.golangci.next.reference.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ linters:
3939
- forbidigo
4040
- forcetypeassert
4141
- funlen
42+
- filen
4243
- gci
4344
- ginkgolinter
4445
- gocheckcompilerdirectives
@@ -155,6 +156,7 @@ linters:
155156
- forbidigo
156157
- forcetypeassert
157158
- funlen
159+
- filen
158160
- gci
159161
- ginkgolinter
160162
- gocheckcompilerdirectives
@@ -577,6 +579,17 @@ linters-settings:
577579
# Default false
578580
ignore-comments: true
579581

582+
filen:
583+
# Min number of lines in a file setting
584+
# Default: 5
585+
min-lines-num: 5
586+
# Max number of lines in a file setting
587+
# Default: 5
588+
max-lines-num: 500
589+
# Ignore comments when counting lines.
590+
# Default false
591+
ignore-comments: false
592+
580593
gci:
581594
# Section configuration to compare against.
582595
# Section names are case-insensitive and may contain parameters in ().

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ linters:
2525
- errcheck
2626
- errorlint
2727
- funlen
28+
- filen
2829
- gocheckcompilerdirectives
2930
- gochecknoinits
3031
- gochecknoinits
@@ -76,6 +77,10 @@ linters-settings:
7677
funlen:
7778
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
7879
statements: 50
80+
filen:
81+
min-lines-num: 5
82+
max-lines-num: 500
83+
ignore-comments: false
7984
goconst:
8085
min-len: 2
8186
min-occurrences: 3

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/golangci/golangci-lint
22

3-
go 1.22.1
3+
go 1.23.2
44

55
require (
66
4d63.com/gocheckcompilerdirectives v1.2.1
@@ -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.0.2
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

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ var defaultLintersSettings = LintersSettings{
197197
ErrorVariableNames: []string{"err"},
198198
ForceExclusiveShortDeclarations: false,
199199
},
200+
Filen: FilenSettings{
201+
MinLinesNum: 5,
202+
MaxLinesNum: 500,
203+
IgnoreComments: false,
204+
},
200205
}
201206

202207
type LintersSettings struct {
@@ -282,6 +287,7 @@ type LintersSettings struct {
282287
Whitespace WhitespaceSettings
283288
Wrapcheck WrapcheckSettings
284289
WSL WSLSettings
290+
Filen FilenSettings
285291

286292
Custom map[string]CustomLinterSettings
287293
}
@@ -1013,6 +1019,12 @@ type WSLSettings struct {
10131019
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`
10141020
}
10151021

1022+
type FilenSettings struct {
1023+
MaxLinesNum int `mapstructure:"min-lines-num"`
1024+
MinLinesNum int `mapstructure:"max-lines-num"`
1025+
IgnoreComments bool `mapstructure:"ignore-comments"`
1026+
}
1027+
10161028
// CustomLinterSettings encapsulates the meta-data of a private linter.
10171029
type CustomLinterSettings struct {
10181030
// Type plugin type.

pkg/golinters/filen/filen.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package filen
2+
3+
import (
4+
"github.com/DanilXO/filen/pgk/filen"
5+
"github.com/golangci/golangci-lint/pkg/config"
6+
"github.com/golangci/golangci-lint/pkg/goanalysis"
7+
"golang.org/x/tools/go/analysis"
8+
)
9+
10+
func New(settings *config.FilenSettings) *goanalysis.Linter {
11+
a := filen.NewAnalyzer(&filen.Runner{
12+
MaxLinesNum: settings.MaxLinesNum,
13+
MinLinesNum: settings.MinLinesNum,
14+
IgnoreComments: settings.IgnoreComments,
15+
})
16+
17+
return goanalysis.NewLinter(
18+
a.Name,
19+
a.Doc,
20+
[]*analysis.Analyzer{a},
21+
nil,
22+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
23+
}

pkg/golinters/filen/filen_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package filen
2+
3+
import (
4+
"github.com/golangci/golangci-lint/test/testshared/integration"
5+
"testing"
6+
)
7+
8+
func TestFromTestdata(t *testing.T) {
9+
integration.RunTestdata(t)
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package samples - is the code for functional tests
2+
package samples
3+
4+
// foo - is test function
5+
func foo() string {
6+
return "bar"
7+
}
8+
9+
// foo1 - is test function
10+
func foo1() string {
11+
return "bar1"
12+
}
13+
14+
// foo2 - is test function
15+
func foo2() string {
16+
return "bar2"
17+
}
18+
19+
// foo3 - is test function
20+
func foo3() string {
21+
return "bar3"
22+
}
23+
24+
// foo4 - is test function
25+
func foo4() string {
26+
return "bar4"
27+
}
28+
29+
// foo5 - is test function
30+
func foo5() string {
31+
return "bar5"
32+
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/golangci/golangci-lint/pkg/golinters/exhaustruct"
2929
"github.com/golangci/golangci-lint/pkg/golinters/exportloopref"
3030
"github.com/golangci/golangci-lint/pkg/golinters/fatcontext"
31+
"github.com/golangci/golangci-lint/pkg/golinters/filen"
3132
"github.com/golangci/golangci-lint/pkg/golinters/forbidigo"
3233
"github.com/golangci/golangci-lint/pkg/golinters/forcetypeassert"
3334
"github.com/golangci/golangci-lint/pkg/golinters/funlen"
@@ -853,5 +854,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
853854
WithPresets(linter.PresetStyle).
854855
WithAutoFix().
855856
WithURL("https://github.com/golangci/golangci-lint/tree/master/pkg/golinters/nolintlint/internal"),
857+
858+
linter.NewConfig(filen.New(&cfg.LintersSettings.Filen)).
859+
WithSince("v1.62.0").
860+
WithPresets(linter.PresetComplexity).
861+
WithLoadForGoAnalysis().
862+
WithURL("https://github.com/DanilXO/filen"),
856863
}, nil
857864
}

0 commit comments

Comments
 (0)