diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 5e9afbb1eb74..f1bba3e1afa9 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -36,6 +36,7 @@ linters: - exhaustruct - exportloopref - fatcontext + - filen - forbidigo - forcetypeassert - funlen @@ -152,6 +153,7 @@ linters: - exhaustruct - exportloopref - fatcontext + - filen - forbidigo - forcetypeassert - funlen @@ -534,6 +536,17 @@ linters-settings: exclude: - '.+/cobra\.Command$' + filen: + # Ignore comments when counting lines. + # Default false + ignore-comments: true + # Max number of lines in a file. + # Default: 1000 + max-lines: 500 + # Min number of lines in a file. + # Default: 5 + min-lines: 1 + forbidigo: # Forbid the following identifiers (list of regexp). # Default: ["^(fmt\\.Print(|f|ln)|print|println)$"] diff --git a/go.mod b/go.mod index 6e48abaddeaf..adbcf99d9cf8 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/Antonboom/testifylint v1.5.0 github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/Crocmagnon/fatcontext v0.5.2 + github.com/DanilXO/filen v0.3.0 github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 github.com/OpenPeeDeeP/depguard/v2 v2.2.0 diff --git a/go.sum b/go.sum index 61ea9d20f80f..d349ebe05bc5 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Crocmagnon/fatcontext v0.5.2 h1:vhSEg8Gqng8awhPju2w7MKHqMlg4/NI+gSDHtR3xgwA= github.com/Crocmagnon/fatcontext v0.5.2/go.mod h1:87XhRMaInHP44Q7Tlc7jkgKKB7kZAOPiDkFMdKCC+74= +github.com/DanilXO/filen v0.3.0 h1:OWRv0T/EZYg8NFivCGkRQAVYOXl5Ioxl0CRuWc2W/pY= +github.com/DanilXO/filen v0.3.0/go.mod h1:VRxWVUk+WuR016dFLD+D74Ac0mGSMANQ3LHkSlZNipQ= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 h1:/fTUt5vmbkAcMBt4YQiuC23cV0kEsN1MVMNqeOW43cU= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 7a012ec288df..a9717569d2de 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -1012,6 +1012,27 @@ } } }, + "filen": { + "type": "object", + "additionalProperties": false, + "properties": { + "ignore-comments": { + "description": "Ignore comments when counting lines.", + "type": "boolean", + "default": false + }, + "max-lines": { + "description": "Max number of lines in a file.", + "type": "integer", + "default": 1000 + }, + "min-lines": { + "description": "Min number of lines in a file.", + "type": "integer", + "default": 5 + } + } + }, "forbidigo": { "type": "object", "additionalProperties": false, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 3760d6a40de8..064611e6088f 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -40,6 +40,11 @@ var defaultLintersSettings = LintersSettings{ ExplicitExhaustiveMap: false, ExplicitExhaustiveSwitch: false, }, + Filen: FilenSettings{ + MinLines: 5, + MaxLines: 1000, + IgnoreComments: false, + }, Forbidigo: ForbidigoSettings{ ExcludeGodocExamples: true, }, @@ -214,6 +219,7 @@ type LintersSettings struct { ErrorLint ErrorLintSettings Exhaustive ExhaustiveSettings Exhaustruct ExhaustructSettings + Filen FilenSettings Forbidigo ForbidigoSettings Funlen FunlenSettings Gci GciSettings @@ -418,6 +424,12 @@ type ExhaustructSettings struct { Exclude []string `mapstructure:"exclude"` } +type FilenSettings struct { + IgnoreComments bool `mapstructure:"ignore-comments"` + MaxLines int `mapstructure:"max-lines"` + MinLines int `mapstructure:"min-lines"` +} + type ForbidigoSettings struct { Forbid []ForbidigoPattern `mapstructure:"forbid"` ExcludeGodocExamples bool `mapstructure:"exclude-godoc-examples"` diff --git a/pkg/golinters/filen/filen.go b/pkg/golinters/filen/filen.go new file mode 100644 index 000000000000..90b302f8683c --- /dev/null +++ b/pkg/golinters/filen/filen.go @@ -0,0 +1,24 @@ +package filen + +import ( + "github.com/DanilXO/filen/pkg/filen" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/config" + "github.com/golangci/golangci-lint/pkg/goanalysis" +) + +func New(settings *config.FilenSettings) *goanalysis.Linter { + a := filen.NewAnalyzer(&filen.Runner{ + MaxLines: settings.MaxLines, + MinLines: settings.MinLines, + IgnoreComments: settings.IgnoreComments, + }) + + return goanalysis.NewLinter( + a.Name, + a.Doc, + []*analysis.Analyzer{a}, + nil, + ).WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/golinters/filen/filen_integration_test.go b/pkg/golinters/filen/filen_integration_test.go new file mode 100644 index 000000000000..ea5232a0468e --- /dev/null +++ b/pkg/golinters/filen/filen_integration_test.go @@ -0,0 +1,11 @@ +package filen + +import ( + "testing" + + "github.com/golangci/golangci-lint/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/filen/testdata/filen.go b/pkg/golinters/filen/testdata/filen.go new file mode 100644 index 000000000000..da194b2fd9de --- /dev/null +++ b/pkg/golinters/filen/testdata/filen.go @@ -0,0 +1,1006 @@ +//golangcitest:args -Efilen +package testdata // want `The number of lines exceeds the allowed value. \(maxLinesNum = 1000, fileLines = 1006\)` + +import "fmt" + +// foo0 test function +func foo0() string { + fmt.Println("foo0 is a test") + return "bar" +} + +// foo1 test function +func foo1() string { + fmt.Println("foo1 is a test") + return "bar" +} + +// foo2 test function +func foo2() string { + fmt.Println("foo2 is a test") + return "bar" +} + +// foo3 test function +func foo3() string { + fmt.Println("foo3 is a test") + return "bar" +} + +// foo4 test function +func foo4() string { + fmt.Println("foo4 is a test") + return "bar" +} + +// foo5 test function +func foo5() string { + fmt.Println("foo5 is a test") + return "bar" +} + +// foo6 test function +func foo6() string { + fmt.Println("foo6 is a test") + return "bar" +} + +// foo7 test function +func foo7() string { + fmt.Println("foo7 is a test") + return "bar" +} + +// foo8 test function +func foo8() string { + fmt.Println("foo8 is a test") + return "bar" +} + +// foo9 test function +func foo9() string { + fmt.Println("foo9 is a test") + return "bar" +} + +// foo10 test function +func foo10() string { + fmt.Println("foo10 is a test") + return "bar" +} + +// foo11 test function +func foo11() string { + fmt.Println("foo11 is a test") + return "bar" +} + +// foo12 test function +func foo12() string { + fmt.Println("foo12 is a test") + return "bar" +} + +// foo13 test function +func foo13() string { + fmt.Println("foo13 is a test") + return "bar" +} + +// foo14 test function +func foo14() string { + fmt.Println("foo14 is a test") + return "bar" +} + +// foo15 test function +func foo15() string { + fmt.Println("foo15 is a test") + return "bar" +} + +// foo16 test function +func foo16() string { + fmt.Println("foo16 is a test") + return "bar" +} + +// foo17 test function +func foo17() string { + fmt.Println("foo17 is a test") + return "bar" +} + +// foo18 test function +func foo18() string { + fmt.Println("foo18 is a test") + return "bar" +} + +// foo19 test function +func foo19() string { + fmt.Println("foo19 is a test") + return "bar" +} + +// foo20 test function +func foo20() string { + fmt.Println("foo20 is a test") + return "bar" +} + +// foo21 test function +func foo21() string { + fmt.Println("foo21 is a test") + return "bar" +} + +// foo22 test function +func foo22() string { + fmt.Println("foo22 is a test") + return "bar" +} + +// foo23 test function +func foo23() string { + fmt.Println("foo23 is a test") + return "bar" +} + +// foo24 test function +func foo24() string { + fmt.Println("foo24 is a test") + return "bar" +} + +// foo25 test function +func foo25() string { + fmt.Println("foo25 is a test") + return "bar" +} + +// foo26 test function +func foo26() string { + fmt.Println("foo26 is a test") + return "bar" +} + +// foo27 test function +func foo27() string { + fmt.Println("foo27 is a test") + return "bar" +} + +// foo28 test function +func foo28() string { + fmt.Println("foo28 is a test") + return "bar" +} + +// foo29 test function +func foo29() string { + fmt.Println("foo29 is a test") + return "bar" +} + +// foo30 test function +func foo30() string { + fmt.Println("foo30 is a test") + return "bar" +} + +// foo31 test function +func foo31() string { + fmt.Println("foo31 is a test") + return "bar" +} + +// foo32 test function +func foo32() string { + fmt.Println("foo32 is a test") + return "bar" +} + +// foo33 test function +func foo33() string { + fmt.Println("foo33 is a test") + return "bar" +} + +// foo34 test function +func foo34() string { + fmt.Println("foo34 is a test") + return "bar" +} + +// foo35 test function +func foo35() string { + fmt.Println("foo35 is a test") + return "bar" +} + +// foo36 test function +func foo36() string { + fmt.Println("foo36 is a test") + return "bar" +} + +// foo37 test function +func foo37() string { + fmt.Println("foo37 is a test") + return "bar" +} + +// foo38 test function +func foo38() string { + fmt.Println("foo38 is a test") + return "bar" +} + +// foo39 test function +func foo39() string { + fmt.Println("foo39 is a test") + return "bar" +} + +// foo40 test function +func foo40() string { + fmt.Println("foo40 is a test") + return "bar" +} + +// foo41 test function +func foo41() string { + fmt.Println("foo41 is a test") + return "bar" +} + +// foo42 test function +func foo42() string { + fmt.Println("foo42 is a test") + return "bar" +} + +// foo43 test function +func foo43() string { + fmt.Println("foo43 is a test") + return "bar" +} + +// foo44 test function +func foo44() string { + fmt.Println("foo44 is a test") + return "bar" +} + +// foo45 test function +func foo45() string { + fmt.Println("foo45 is a test") + return "bar" +} + +// foo46 test function +func foo46() string { + fmt.Println("foo46 is a test") + return "bar" +} + +// foo47 test function +func foo47() string { + fmt.Println("foo47 is a test") + return "bar" +} + +// foo48 test function +func foo48() string { + fmt.Println("foo48 is a test") + return "bar" +} + +// foo49 test function +func foo49() string { + fmt.Println("foo49 is a test") + return "bar" +} + +// foo50 test function +func foo50() string { + fmt.Println("foo50 is a test") + return "bar" +} + +// foo51 test function +func foo51() string { + fmt.Println("foo51 is a test") + return "bar" +} + +// foo52 test function +func foo52() string { + fmt.Println("foo52 is a test") + return "bar" +} + +// foo53 test function +func foo53() string { + fmt.Println("foo53 is a test") + return "bar" +} + +// foo54 test function +func foo54() string { + fmt.Println("foo54 is a test") + return "bar" +} + +// foo55 test function +func foo55() string { + fmt.Println("foo55 is a test") + return "bar" +} + +// foo56 test function +func foo56() string { + fmt.Println("foo56 is a test") + return "bar" +} + +// foo57 test function +func foo57() string { + fmt.Println("foo57 is a test") + return "bar" +} + +// foo58 test function +func foo58() string { + fmt.Println("foo58 is a test") + return "bar" +} + +// foo59 test function +func foo59() string { + fmt.Println("foo59 is a test") + return "bar" +} + +// foo60 test function +func foo60() string { + fmt.Println("foo60 is a test") + return "bar" +} + +// foo61 test function +func foo61() string { + fmt.Println("foo61 is a test") + return "bar" +} + +// foo62 test function +func foo62() string { + fmt.Println("foo62 is a test") + return "bar" +} + +// foo63 test function +func foo63() string { + fmt.Println("foo63 is a test") + return "bar" +} + +// foo64 test function +func foo64() string { + fmt.Println("foo64 is a test") + return "bar" +} + +// foo65 test function +func foo65() string { + fmt.Println("foo65 is a test") + return "bar" +} + +// foo66 test function +func foo66() string { + fmt.Println("foo66 is a test") + return "bar" +} + +// foo67 test function +func foo67() string { + fmt.Println("foo67 is a test") + return "bar" +} + +// foo68 test function +func foo68() string { + fmt.Println("foo68 is a test") + return "bar" +} + +// foo69 test function +func foo69() string { + fmt.Println("foo69 is a test") + return "bar" +} + +// foo70 test function +func foo70() string { + fmt.Println("foo70 is a test") + return "bar" +} + +// foo71 test function +func foo71() string { + fmt.Println("foo71 is a test") + return "bar" +} + +// foo72 test function +func foo72() string { + fmt.Println("foo72 is a test") + return "bar" +} + +// foo73 test function +func foo73() string { + fmt.Println("foo73 is a test") + return "bar" +} + +// foo74 test function +func foo74() string { + fmt.Println("foo74 is a test") + return "bar" +} + +// foo75 test function +func foo75() string { + fmt.Println("foo75 is a test") + return "bar" +} + +// foo76 test function +func foo76() string { + fmt.Println("foo76 is a test") + return "bar" +} + +// foo77 test function +func foo77() string { + fmt.Println("foo77 is a test") + return "bar" +} + +// foo78 test function +func foo78() string { + fmt.Println("foo78 is a test") + return "bar" +} + +// foo79 test function +func foo79() string { + fmt.Println("foo79 is a test") + return "bar" +} + +// foo80 test function +func foo80() string { + fmt.Println("foo80 is a test") + return "bar" +} + +// foo81 test function +func foo81() string { + fmt.Println("foo81 is a test") + return "bar" +} + +// foo82 test function +func foo82() string { + fmt.Println("foo82 is a test") + return "bar" +} + +// foo83 test function +func foo83() string { + fmt.Println("foo83 is a test") + return "bar" +} + +// foo84 test function +func foo84() string { + fmt.Println("foo84 is a test") + return "bar" +} + +// foo85 test function +func foo85() string { + fmt.Println("foo85 is a test") + return "bar" +} + +// foo86 test function +func foo86() string { + fmt.Println("foo86 is a test") + return "bar" +} + +// foo87 test function +func foo87() string { + fmt.Println("foo87 is a test") + return "bar" +} + +// foo88 test function +func foo88() string { + fmt.Println("foo88 is a test") + return "bar" +} + +// foo89 test function +func foo89() string { + fmt.Println("foo89 is a test") + return "bar" +} + +// foo90 test function +func foo90() string { + fmt.Println("foo90 is a test") + return "bar" +} + +// foo91 test function +func foo91() string { + fmt.Println("foo91 is a test") + return "bar" +} + +// foo92 test function +func foo92() string { + fmt.Println("foo92 is a test") + return "bar" +} + +// foo93 test function +func foo93() string { + fmt.Println("foo93 is a test") + return "bar" +} + +// foo94 test function +func foo94() string { + fmt.Println("foo94 is a test") + return "bar" +} + +// foo95 test function +func foo95() string { + fmt.Println("foo95 is a test") + return "bar" +} + +// foo96 test function +func foo96() string { + fmt.Println("foo96 is a test") + return "bar" +} + +// foo97 test function +func foo97() string { + fmt.Println("foo97 is a test") + return "bar" +} + +// foo98 test function +func foo98() string { + fmt.Println("foo98 is a test") + return "bar" +} + +// foo99 test function +func foo99() string { + fmt.Println("foo99 is a test") + return "bar" +} + +// foo100 test function +func foo100() string { + fmt.Println("foo100 is a test") + return "bar" +} + +// foo101 test function +func foo101() string { + fmt.Println("foo101 is a test") + return "bar" +} + +// foo102 test function +func foo102() string { + fmt.Println("foo102 is a test") + return "bar" +} + +// foo103 test function +func foo103() string { + fmt.Println("foo103 is a test") + return "bar" +} + +// foo104 test function +func foo104() string { + fmt.Println("foo104 is a test") + return "bar" +} + +// foo105 test function +func foo105() string { + fmt.Println("foo105 is a test") + return "bar" +} + +// foo106 test function +func foo106() string { + fmt.Println("foo106 is a test") + return "bar" +} + +// foo107 test function +func foo107() string { + fmt.Println("foo107 is a test") + return "bar" +} + +// foo108 test function +func foo108() string { + fmt.Println("foo108 is a test") + return "bar" +} + +// foo109 test function +func foo109() string { + fmt.Println("foo109 is a test") + return "bar" +} + +// foo110 test function +func foo110() string { + fmt.Println("foo110 is a test") + return "bar" +} + +// foo111 test function +func foo111() string { + fmt.Println("foo111 is a test") + return "bar" +} + +// foo112 test function +func foo112() string { + fmt.Println("foo112 is a test") + return "bar" +} + +// foo113 test function +func foo113() string { + fmt.Println("foo113 is a test") + return "bar" +} + +// foo114 test function +func foo114() string { + fmt.Println("foo114 is a test") + return "bar" +} + +// foo115 test function +func foo115() string { + fmt.Println("foo115 is a test") + return "bar" +} + +// foo116 test function +func foo116() string { + fmt.Println("foo116 is a test") + return "bar" +} + +// foo117 test function +func foo117() string { + fmt.Println("foo117 is a test") + return "bar" +} + +// foo118 test function +func foo118() string { + fmt.Println("foo118 is a test") + return "bar" +} + +// foo119 test function +func foo119() string { + fmt.Println("foo119 is a test") + return "bar" +} + +// foo120 test function +func foo120() string { + fmt.Println("foo120 is a test") + return "bar" +} + +// foo121 test function +func foo121() string { + fmt.Println("foo121 is a test") + return "bar" +} + +// foo122 test function +func foo122() string { + fmt.Println("foo122 is a test") + return "bar" +} + +// foo123 test function +func foo123() string { + fmt.Println("foo123 is a test") + return "bar" +} + +// foo124 test function +func foo124() string { + fmt.Println("foo124 is a test") + return "bar" +} + +// foo125 test function +func foo125() string { + fmt.Println("foo125 is a test") + return "bar" +} + +// foo126 test function +func foo126() string { + fmt.Println("foo126 is a test") + return "bar" +} + +// foo127 test function +func foo127() string { + fmt.Println("foo127 is a test") + return "bar" +} + +// foo128 test function +func foo128() string { + fmt.Println("foo128 is a test") + return "bar" +} + +// foo129 test function +func foo129() string { + fmt.Println("foo129 is a test") + return "bar" +} + +// foo130 test function +func foo130() string { + fmt.Println("foo130 is a test") + return "bar" +} + +// foo131 test function +func foo131() string { + fmt.Println("foo131 is a test") + return "bar" +} + +// foo132 test function +func foo132() string { + fmt.Println("foo132 is a test") + return "bar" +} + +// foo133 test function +func foo133() string { + fmt.Println("foo133 is a test") + return "bar" +} + +// foo134 test function +func foo134() string { + fmt.Println("foo134 is a test") + return "bar" +} + +// foo135 test function +func foo135() string { + fmt.Println("foo135 is a test") + return "bar" +} + +// foo136 test function +func foo136() string { + fmt.Println("foo136 is a test") + return "bar" +} + +// foo137 test function +func foo137() string { + fmt.Println("foo137 is a test") + return "bar" +} + +// foo138 test function +func foo138() string { + fmt.Println("foo138 is a test") + return "bar" +} + +// foo139 test function +func foo139() string { + fmt.Println("foo139 is a test") + return "bar" +} + +// foo140 test function +func foo140() string { + fmt.Println("foo140 is a test") + return "bar" +} + +// foo141 test function +func foo141() string { + fmt.Println("foo141 is a test") + return "bar" +} + +// foo142 test function +func foo142() string { + fmt.Println("foo142 is a test") + return "bar" +} + +// foo143 test function +func foo143() string { + fmt.Println("foo143 is a test") + return "bar" +} + +// foo144 test function +func foo144() string { + fmt.Println("foo144 is a test") + return "bar" +} + +// foo145 test function +func foo145() string { + fmt.Println("foo145 is a test") + return "bar" +} + +// foo146 test function +func foo146() string { + fmt.Println("foo146 is a test") + return "bar" +} + +// foo147 test function +func foo147() string { + fmt.Println("foo147 is a test") + return "bar" +} + +// foo148 test function +func foo148() string { + fmt.Println("foo148 is a test") + return "bar" +} + +// foo149 test function +func foo149() string { + fmt.Println("foo149 is a test") + return "bar" +} + +// foo150 test function +func foo150() string { + fmt.Println("foo150 is a test") + return "bar" +} + +// foo151 test function +func foo151() string { + fmt.Println("foo151 is a test") + return "bar" +} + +// foo152 test function +func foo152() string { + fmt.Println("foo152 is a test") + return "bar" +} + +// foo153 test function +func foo153() string { + fmt.Println("foo153 is a test") + return "bar" +} + +// foo154 test function +func foo154() string { + fmt.Println("foo154 is a test") + return "bar" +} + +// foo155 test function +func foo155() string { + fmt.Println("foo155 is a test") + return "bar" +} + +// foo156 test function +func foo156() string { + fmt.Println("foo156 is a test") + return "bar" +} + +// foo157 test function +func foo157() string { + fmt.Println("foo157 is a test") + return "bar" +} + +// foo158 test function +func foo158() string { + fmt.Println("foo158 is a test") + return "bar" +} + +// foo159 test function +func foo159() string { + fmt.Println("foo159 is a test") + return "bar" +} + +// foo160 test function +func foo160() string { + fmt.Println("foo160 is a test") + return "bar" +} + +// foo161 test function +func foo161() string { + fmt.Println("foo161 is a test") + return "bar" +} + +// foo162 test function +func foo162() string { + fmt.Println("foo162 is a test") + return "bar" +} + +// foo163 test function +func foo163() string { + fmt.Println("foo163 is a test") + return "bar" +} + +// foo164 test function +func foo164() string { + fmt.Println("foo164 is a test") + return "bar" +} + +// foo165 test function +func foo165() string { + fmt.Println("foo165 is a test") + return "bar" +} + +// foo166 test function +func foo166() string { + fmt.Println("foo166 is a test") + return "bar" +} diff --git a/pkg/golinters/filen/testdata/filen_ignore_comments.go b/pkg/golinters/filen/testdata/filen_ignore_comments.go new file mode 100644 index 000000000000..70f58aab65a6 --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_ignore_comments.go @@ -0,0 +1,1008 @@ +//golangcitest:args -Efilen +//golangcitest:config_path testdata/filen_ignore_comments.yml +//golangcitest:expected_exitcode 0 +package testdata + +import "fmt" + +// foo0 test function +func foo0() string { + fmt.Println("foo0 is a test") + return "bar" +} + +// foo1 test function +func foo1() string { + fmt.Println("foo1 is a test") + return "bar" +} + +// foo2 test function +func foo2() string { + fmt.Println("foo2 is a test") + return "bar" +} + +// foo3 test function +func foo3() string { + fmt.Println("foo3 is a test") + return "bar" +} + +// foo4 test function +func foo4() string { + fmt.Println("foo4 is a test") + return "bar" +} + +// foo5 test function +func foo5() string { + fmt.Println("foo5 is a test") + return "bar" +} + +// foo6 test function +func foo6() string { + fmt.Println("foo6 is a test") + return "bar" +} + +// foo7 test function +func foo7() string { + fmt.Println("foo7 is a test") + return "bar" +} + +// foo8 test function +func foo8() string { + fmt.Println("foo8 is a test") + return "bar" +} + +// foo9 test function +func foo9() string { + fmt.Println("foo9 is a test") + return "bar" +} + +// foo10 test function +func foo10() string { + fmt.Println("foo10 is a test") + return "bar" +} + +// foo11 test function +func foo11() string { + fmt.Println("foo11 is a test") + return "bar" +} + +// foo12 test function +func foo12() string { + fmt.Println("foo12 is a test") + return "bar" +} + +// foo13 test function +func foo13() string { + fmt.Println("foo13 is a test") + return "bar" +} + +// foo14 test function +func foo14() string { + fmt.Println("foo14 is a test") + return "bar" +} + +// foo15 test function +func foo15() string { + fmt.Println("foo15 is a test") + return "bar" +} + +// foo16 test function +func foo16() string { + fmt.Println("foo16 is a test") + return "bar" +} + +// foo17 test function +func foo17() string { + fmt.Println("foo17 is a test") + return "bar" +} + +// foo18 test function +func foo18() string { + fmt.Println("foo18 is a test") + return "bar" +} + +// foo19 test function +func foo19() string { + fmt.Println("foo19 is a test") + return "bar" +} + +// foo20 test function +func foo20() string { + fmt.Println("foo20 is a test") + return "bar" +} + +// foo21 test function +func foo21() string { + fmt.Println("foo21 is a test") + return "bar" +} + +// foo22 test function +func foo22() string { + fmt.Println("foo22 is a test") + return "bar" +} + +// foo23 test function +func foo23() string { + fmt.Println("foo23 is a test") + return "bar" +} + +// foo24 test function +func foo24() string { + fmt.Println("foo24 is a test") + return "bar" +} + +// foo25 test function +func foo25() string { + fmt.Println("foo25 is a test") + return "bar" +} + +// foo26 test function +func foo26() string { + fmt.Println("foo26 is a test") + return "bar" +} + +// foo27 test function +func foo27() string { + fmt.Println("foo27 is a test") + return "bar" +} + +// foo28 test function +func foo28() string { + fmt.Println("foo28 is a test") + return "bar" +} + +// foo29 test function +func foo29() string { + fmt.Println("foo29 is a test") + return "bar" +} + +// foo30 test function +func foo30() string { + fmt.Println("foo30 is a test") + return "bar" +} + +// foo31 test function +func foo31() string { + fmt.Println("foo31 is a test") + return "bar" +} + +// foo32 test function +func foo32() string { + fmt.Println("foo32 is a test") + return "bar" +} + +// foo33 test function +func foo33() string { + fmt.Println("foo33 is a test") + return "bar" +} + +// foo34 test function +func foo34() string { + fmt.Println("foo34 is a test") + return "bar" +} + +// foo35 test function +func foo35() string { + fmt.Println("foo35 is a test") + return "bar" +} + +// foo36 test function +func foo36() string { + fmt.Println("foo36 is a test") + return "bar" +} + +// foo37 test function +func foo37() string { + fmt.Println("foo37 is a test") + return "bar" +} + +// foo38 test function +func foo38() string { + fmt.Println("foo38 is a test") + return "bar" +} + +// foo39 test function +func foo39() string { + fmt.Println("foo39 is a test") + return "bar" +} + +// foo40 test function +func foo40() string { + fmt.Println("foo40 is a test") + return "bar" +} + +// foo41 test function +func foo41() string { + fmt.Println("foo41 is a test") + return "bar" +} + +// foo42 test function +func foo42() string { + fmt.Println("foo42 is a test") + return "bar" +} + +// foo43 test function +func foo43() string { + fmt.Println("foo43 is a test") + return "bar" +} + +// foo44 test function +func foo44() string { + fmt.Println("foo44 is a test") + return "bar" +} + +// foo45 test function +func foo45() string { + fmt.Println("foo45 is a test") + return "bar" +} + +// foo46 test function +func foo46() string { + fmt.Println("foo46 is a test") + return "bar" +} + +// foo47 test function +func foo47() string { + fmt.Println("foo47 is a test") + return "bar" +} + +// foo48 test function +func foo48() string { + fmt.Println("foo48 is a test") + return "bar" +} + +// foo49 test function +func foo49() string { + fmt.Println("foo49 is a test") + return "bar" +} + +// foo50 test function +func foo50() string { + fmt.Println("foo50 is a test") + return "bar" +} + +// foo51 test function +func foo51() string { + fmt.Println("foo51 is a test") + return "bar" +} + +// foo52 test function +func foo52() string { + fmt.Println("foo52 is a test") + return "bar" +} + +// foo53 test function +func foo53() string { + fmt.Println("foo53 is a test") + return "bar" +} + +// foo54 test function +func foo54() string { + fmt.Println("foo54 is a test") + return "bar" +} + +// foo55 test function +func foo55() string { + fmt.Println("foo55 is a test") + return "bar" +} + +// foo56 test function +func foo56() string { + fmt.Println("foo56 is a test") + return "bar" +} + +// foo57 test function +func foo57() string { + fmt.Println("foo57 is a test") + return "bar" +} + +// foo58 test function +func foo58() string { + fmt.Println("foo58 is a test") + return "bar" +} + +// foo59 test function +func foo59() string { + fmt.Println("foo59 is a test") + return "bar" +} + +// foo60 test function +func foo60() string { + fmt.Println("foo60 is a test") + return "bar" +} + +// foo61 test function +func foo61() string { + fmt.Println("foo61 is a test") + return "bar" +} + +// foo62 test function +func foo62() string { + fmt.Println("foo62 is a test") + return "bar" +} + +// foo63 test function +func foo63() string { + fmt.Println("foo63 is a test") + return "bar" +} + +// foo64 test function +func foo64() string { + fmt.Println("foo64 is a test") + return "bar" +} + +// foo65 test function +func foo65() string { + fmt.Println("foo65 is a test") + return "bar" +} + +// foo66 test function +func foo66() string { + fmt.Println("foo66 is a test") + return "bar" +} + +// foo67 test function +func foo67() string { + fmt.Println("foo67 is a test") + return "bar" +} + +// foo68 test function +func foo68() string { + fmt.Println("foo68 is a test") + return "bar" +} + +// foo69 test function +func foo69() string { + fmt.Println("foo69 is a test") + return "bar" +} + +// foo70 test function +func foo70() string { + fmt.Println("foo70 is a test") + return "bar" +} + +// foo71 test function +func foo71() string { + fmt.Println("foo71 is a test") + return "bar" +} + +// foo72 test function +func foo72() string { + fmt.Println("foo72 is a test") + return "bar" +} + +// foo73 test function +func foo73() string { + fmt.Println("foo73 is a test") + return "bar" +} + +// foo74 test function +func foo74() string { + fmt.Println("foo74 is a test") + return "bar" +} + +// foo75 test function +func foo75() string { + fmt.Println("foo75 is a test") + return "bar" +} + +// foo76 test function +func foo76() string { + fmt.Println("foo76 is a test") + return "bar" +} + +// foo77 test function +func foo77() string { + fmt.Println("foo77 is a test") + return "bar" +} + +// foo78 test function +func foo78() string { + fmt.Println("foo78 is a test") + return "bar" +} + +// foo79 test function +func foo79() string { + fmt.Println("foo79 is a test") + return "bar" +} + +// foo80 test function +func foo80() string { + fmt.Println("foo80 is a test") + return "bar" +} + +// foo81 test function +func foo81() string { + fmt.Println("foo81 is a test") + return "bar" +} + +// foo82 test function +func foo82() string { + fmt.Println("foo82 is a test") + return "bar" +} + +// foo83 test function +func foo83() string { + fmt.Println("foo83 is a test") + return "bar" +} + +// foo84 test function +func foo84() string { + fmt.Println("foo84 is a test") + return "bar" +} + +// foo85 test function +func foo85() string { + fmt.Println("foo85 is a test") + return "bar" +} + +// foo86 test function +func foo86() string { + fmt.Println("foo86 is a test") + return "bar" +} + +// foo87 test function +func foo87() string { + fmt.Println("foo87 is a test") + return "bar" +} + +// foo88 test function +func foo88() string { + fmt.Println("foo88 is a test") + return "bar" +} + +// foo89 test function +func foo89() string { + fmt.Println("foo89 is a test") + return "bar" +} + +// foo90 test function +func foo90() string { + fmt.Println("foo90 is a test") + return "bar" +} + +// foo91 test function +func foo91() string { + fmt.Println("foo91 is a test") + return "bar" +} + +// foo92 test function +func foo92() string { + fmt.Println("foo92 is a test") + return "bar" +} + +// foo93 test function +func foo93() string { + fmt.Println("foo93 is a test") + return "bar" +} + +// foo94 test function +func foo94() string { + fmt.Println("foo94 is a test") + return "bar" +} + +// foo95 test function +func foo95() string { + fmt.Println("foo95 is a test") + return "bar" +} + +// foo96 test function +func foo96() string { + fmt.Println("foo96 is a test") + return "bar" +} + +// foo97 test function +func foo97() string { + fmt.Println("foo97 is a test") + return "bar" +} + +// foo98 test function +func foo98() string { + fmt.Println("foo98 is a test") + return "bar" +} + +// foo99 test function +func foo99() string { + fmt.Println("foo99 is a test") + return "bar" +} + +// foo100 test function +func foo100() string { + fmt.Println("foo100 is a test") + return "bar" +} + +// foo101 test function +func foo101() string { + fmt.Println("foo101 is a test") + return "bar" +} + +// foo102 test function +func foo102() string { + fmt.Println("foo102 is a test") + return "bar" +} + +// foo103 test function +func foo103() string { + fmt.Println("foo103 is a test") + return "bar" +} + +// foo104 test function +func foo104() string { + fmt.Println("foo104 is a test") + return "bar" +} + +// foo105 test function +func foo105() string { + fmt.Println("foo105 is a test") + return "bar" +} + +// foo106 test function +func foo106() string { + fmt.Println("foo106 is a test") + return "bar" +} + +// foo107 test function +func foo107() string { + fmt.Println("foo107 is a test") + return "bar" +} + +// foo108 test function +func foo108() string { + fmt.Println("foo108 is a test") + return "bar" +} + +// foo109 test function +func foo109() string { + fmt.Println("foo109 is a test") + return "bar" +} + +// foo110 test function +func foo110() string { + fmt.Println("foo110 is a test") + return "bar" +} + +// foo111 test function +func foo111() string { + fmt.Println("foo111 is a test") + return "bar" +} + +// foo112 test function +func foo112() string { + fmt.Println("foo112 is a test") + return "bar" +} + +// foo113 test function +func foo113() string { + fmt.Println("foo113 is a test") + return "bar" +} + +// foo114 test function +func foo114() string { + fmt.Println("foo114 is a test") + return "bar" +} + +// foo115 test function +func foo115() string { + fmt.Println("foo115 is a test") + return "bar" +} + +// foo116 test function +func foo116() string { + fmt.Println("foo116 is a test") + return "bar" +} + +// foo117 test function +func foo117() string { + fmt.Println("foo117 is a test") + return "bar" +} + +// foo118 test function +func foo118() string { + fmt.Println("foo118 is a test") + return "bar" +} + +// foo119 test function +func foo119() string { + fmt.Println("foo119 is a test") + return "bar" +} + +// foo120 test function +func foo120() string { + fmt.Println("foo120 is a test") + return "bar" +} + +// foo121 test function +func foo121() string { + fmt.Println("foo121 is a test") + return "bar" +} + +// foo122 test function +func foo122() string { + fmt.Println("foo122 is a test") + return "bar" +} + +// foo123 test function +func foo123() string { + fmt.Println("foo123 is a test") + return "bar" +} + +// foo124 test function +func foo124() string { + fmt.Println("foo124 is a test") + return "bar" +} + +// foo125 test function +func foo125() string { + fmt.Println("foo125 is a test") + return "bar" +} + +// foo126 test function +func foo126() string { + fmt.Println("foo126 is a test") + return "bar" +} + +// foo127 test function +func foo127() string { + fmt.Println("foo127 is a test") + return "bar" +} + +// foo128 test function +func foo128() string { + fmt.Println("foo128 is a test") + return "bar" +} + +// foo129 test function +func foo129() string { + fmt.Println("foo129 is a test") + return "bar" +} + +// foo130 test function +func foo130() string { + fmt.Println("foo130 is a test") + return "bar" +} + +// foo131 test function +func foo131() string { + fmt.Println("foo131 is a test") + return "bar" +} + +// foo132 test function +func foo132() string { + fmt.Println("foo132 is a test") + return "bar" +} + +// foo133 test function +func foo133() string { + fmt.Println("foo133 is a test") + return "bar" +} + +// foo134 test function +func foo134() string { + fmt.Println("foo134 is a test") + return "bar" +} + +// foo135 test function +func foo135() string { + fmt.Println("foo135 is a test") + return "bar" +} + +// foo136 test function +func foo136() string { + fmt.Println("foo136 is a test") + return "bar" +} + +// foo137 test function +func foo137() string { + fmt.Println("foo137 is a test") + return "bar" +} + +// foo138 test function +func foo138() string { + fmt.Println("foo138 is a test") + return "bar" +} + +// foo139 test function +func foo139() string { + fmt.Println("foo139 is a test") + return "bar" +} + +// foo140 test function +func foo140() string { + fmt.Println("foo140 is a test") + return "bar" +} + +// foo141 test function +func foo141() string { + fmt.Println("foo141 is a test") + return "bar" +} + +// foo142 test function +func foo142() string { + fmt.Println("foo142 is a test") + return "bar" +} + +// foo143 test function +func foo143() string { + fmt.Println("foo143 is a test") + return "bar" +} + +// foo144 test function +func foo144() string { + fmt.Println("foo144 is a test") + return "bar" +} + +// foo145 test function +func foo145() string { + fmt.Println("foo145 is a test") + return "bar" +} + +// foo146 test function +func foo146() string { + fmt.Println("foo146 is a test") + return "bar" +} + +// foo147 test function +func foo147() string { + fmt.Println("foo147 is a test") + return "bar" +} + +// foo148 test function +func foo148() string { + fmt.Println("foo148 is a test") + return "bar" +} + +// foo149 test function +func foo149() string { + fmt.Println("foo149 is a test") + return "bar" +} + +// foo150 test function +func foo150() string { + fmt.Println("foo150 is a test") + return "bar" +} + +// foo151 test function +func foo151() string { + fmt.Println("foo151 is a test") + return "bar" +} + +// foo152 test function +func foo152() string { + fmt.Println("foo152 is a test") + return "bar" +} + +// foo153 test function +func foo153() string { + fmt.Println("foo153 is a test") + return "bar" +} + +// foo154 test function +func foo154() string { + fmt.Println("foo154 is a test") + return "bar" +} + +// foo155 test function +func foo155() string { + fmt.Println("foo155 is a test") + return "bar" +} + +// foo156 test function +func foo156() string { + fmt.Println("foo156 is a test") + return "bar" +} + +// foo157 test function +func foo157() string { + fmt.Println("foo157 is a test") + return "bar" +} + +// foo158 test function +func foo158() string { + fmt.Println("foo158 is a test") + return "bar" +} + +// foo159 test function +func foo159() string { + fmt.Println("foo159 is a test") + return "bar" +} + +// foo160 test function +func foo160() string { + fmt.Println("foo160 is a test") + return "bar" +} + +// foo161 test function +func foo161() string { + fmt.Println("foo161 is a test") + return "bar" +} + +// foo162 test function +func foo162() string { + fmt.Println("foo162 is a test") + return "bar" +} + +// foo163 test function +func foo163() string { + fmt.Println("foo163 is a test") + return "bar" +} + +// foo164 test function +func foo164() string { + fmt.Println("foo164 is a test") + return "bar" +} + +// foo165 test function +func foo165() string { + fmt.Println("foo165 is a test") + return "bar" +} + +// foo166 test function +func foo166() string { + fmt.Println("foo166 is a test") + return "bar" +} diff --git a/pkg/golinters/filen/testdata/filen_ignore_comments.yml b/pkg/golinters/filen/testdata/filen_ignore_comments.yml new file mode 100644 index 000000000000..a8a7cbd9e6bd --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_ignore_comments.yml @@ -0,0 +1,3 @@ +linters-settings: + filen: + ignore-comments: true diff --git a/pkg/golinters/filen/testdata/filen_max_lines.go b/pkg/golinters/filen/testdata/filen_max_lines.go new file mode 100644 index 000000000000..bbd06771ea3c --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_max_lines.go @@ -0,0 +1,107 @@ +//golangcitest:args -Efilen +//golangcitest:config_path testdata/filen_max_lines.yml +package testdata // want `The number of lines exceeds the allowed value. \(maxLinesNum = 100, fileLines = 107\)` + +import "fmt" + +// foo0 test function +func foo0() string { + fmt.Println("foo0 is a test") + return "bar" +} + +// foo1 test function +func foo1() string { + fmt.Println("foo1 is a test") + return "bar" +} + +// foo2 test function +func foo2() string { + fmt.Println("foo2 is a test") + return "bar" +} + +// foo3 test function +func foo3() string { + fmt.Println("foo3 is a test") + return "bar" +} + +// foo4 test function +func foo4() string { + fmt.Println("foo4 is a test") + return "bar" +} + +// foo5 test function +func foo5() string { + fmt.Println("foo5 is a test") + return "bar" +} + +// foo6 test function +func foo6() string { + fmt.Println("foo6 is a test") + return "bar" +} + +// foo7 test function +func foo7() string { + fmt.Println("foo7 is a test") + return "bar" +} + +// foo8 test function +func foo8() string { + fmt.Println("foo8 is a test") + return "bar" +} + +// foo9 test function +func foo9() string { + fmt.Println("foo9 is a test") + return "bar" +} + +// foo10 test function +func foo10() string { + fmt.Println("foo10 is a test") + return "bar" +} + +// foo11 test function +func foo11() string { + fmt.Println("foo11 is a test") + return "bar" +} + +// foo12 test function +func foo12() string { + fmt.Println("foo12 is a test") + return "bar" +} + +// foo13 test function +func foo13() string { + fmt.Println("foo13 is a test") + return "bar" +} + +// foo14 test function +func foo14() string { + fmt.Println("foo14 is a test") + return "bar" +} + +// foo15 test function +func foo15() string { + fmt.Println("foo15 is a test") + return "bar" +} + +// foo16 test function +func foo16() string { + fmt.Println("foo16 is a test") + return "bar" +} diff --git a/pkg/golinters/filen/testdata/filen_max_lines.yml b/pkg/golinters/filen/testdata/filen_max_lines.yml new file mode 100644 index 000000000000..e73b1703a4a8 --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_max_lines.yml @@ -0,0 +1,3 @@ +linters-settings: + filen: + max-lines: 100 diff --git a/pkg/golinters/filen/testdata/filen_min_lines.go b/pkg/golinters/filen/testdata/filen_min_lines.go new file mode 100644 index 000000000000..34050218947a --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_min_lines.go @@ -0,0 +1,17 @@ +//golangcitest:args -Efilen +//golangcitest:config_path testdata/filen_min_lines.yml +package testdata // want `The number of lines in less the allowed value. \(minLinesNum = 100, fileLines = 17\)` + +import "fmt" + +// foo0 test function +func foo0() string { + fmt.Println("foo0 is a test") + return "bar" +} + +// foo1 test function +func foo1() string { + fmt.Println("foo1 is a test") + return "bar" +} diff --git a/pkg/golinters/filen/testdata/filen_min_lines.yml b/pkg/golinters/filen/testdata/filen_min_lines.yml new file mode 100644 index 000000000000..341da09ddee2 --- /dev/null +++ b/pkg/golinters/filen/testdata/filen_min_lines.yml @@ -0,0 +1,3 @@ +linters-settings: + filen: + min-lines: 100 diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 3db2ca393cfc..5195abc78272 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -28,6 +28,7 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/exhaustruct" "github.com/golangci/golangci-lint/pkg/golinters/exportloopref" "github.com/golangci/golangci-lint/pkg/golinters/fatcontext" + "github.com/golangci/golangci-lint/pkg/golinters/filen" "github.com/golangci/golangci-lint/pkg/golinters/forbidigo" "github.com/golangci/golangci-lint/pkg/golinters/forcetypeassert" "github.com/golangci/golangci-lint/pkg/golinters/funlen" @@ -283,6 +284,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithURL("https://github.com/kyoh86/exportloopref"). DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"), + linter.NewConfig(filen.New(&cfg.LintersSettings.Filen)). + WithSince("v1.62.0"). + WithPresets(linter.PresetComplexity, linter.PresetStyle). + WithURL("https://github.com/DanilXO/filen"), + linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)). WithSince("v1.34.0"). WithPresets(linter.PresetStyle).