Skip to content

Commit

Permalink
Add filen linter (golangci#5081)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
DanilXO and ldez authored Oct 24, 2024
1 parent d998fc2 commit 29c5529
Show file tree
Hide file tree
Showing 15 changed files with 2,237 additions and 0 deletions.
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

0 comments on commit 29c5529

Please sign in to comment.