Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filen linter #5081

Merged
merged 14 commits into from
Oct 24, 2024
13 changes: 13 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ linters:
- exhaustruct
- exportloopref
- fatcontext
- filen
- forbidigo
- forcetypeassert
- funlen
Expand Down Expand Up @@ -152,6 +153,7 @@ linters:
- exhaustruct
- exportloopref
- fatcontext
- filen
- forbidigo
- forcetypeassert
- funlen
Expand Down Expand Up @@ -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)$"]
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ var defaultLintersSettings = LintersSettings{
ExplicitExhaustiveMap: false,
ExplicitExhaustiveSwitch: false,
},
Filen: FilenSettings{
MinLines: 5,
MaxLines: 1000,
IgnoreComments: false,
},
Forbidigo: ForbidigoSettings{
ExcludeGodocExamples: true,
},
Expand Down Expand Up @@ -214,6 +219,7 @@ type LintersSettings struct {
ErrorLint ErrorLintSettings
Exhaustive ExhaustiveSettings
Exhaustruct ExhaustructSettings
Filen FilenSettings
Forbidigo ForbidigoSettings
Funlen FunlenSettings
Gci GciSettings
Expand Down Expand Up @@ -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"`
Expand Down
24 changes: 24 additions & 0 deletions pkg/golinters/filen/filen.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions pkg/golinters/filen/filen_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package filen

import (
"testing"

"github.com/golangci/golangci-lint/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
Loading
Loading