Skip to content

Commit fe04b90

Browse files
committed
gci: add new option
1 parent 3bd5e21 commit fe04b90

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

.golangci.next.reference.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ linters-settings:
594594
- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
595595
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
596596

597+
# Checks that no inline Comments are present.
598+
# Default: false
599+
no-inline-comments: true
600+
601+
# Checks that no prefix Comments(comment lines above an import) are present.
602+
# Default: false
603+
no-prefix-comments: true
604+
597605
# Skip generated files.
598606
# Default: true
599607
skip-generated: false

jsonschema/golangci.next.jsonschema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,16 @@
11201120
"type": "boolean",
11211121
"default": true
11221122
},
1123+
"no-inline-comments": {
1124+
"description": "Checks that no inline Comments are present.",
1125+
"type": "boolean",
1126+
"default": false
1127+
},
1128+
"no-prefix-comments": {
1129+
"description": "Checks that no prefix Comments(comment lines above an import) are present.",
1130+
"type": "boolean",
1131+
"default": false
1132+
},
11231133
"custom-order": {
11241134
"description": "Enable custom order of sections.",
11251135
"type": "boolean",

pkg/config/linters_settings.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,12 @@ type FunlenSettings struct {
477477
}
478478

479479
type GciSettings struct {
480-
Sections []string `mapstructure:"sections"`
481-
SkipGenerated bool `mapstructure:"skip-generated"`
482-
CustomOrder bool `mapstructure:"custom-order"`
483-
NoLexOrder bool `mapstructure:"no-lex-order"`
480+
Sections []string `mapstructure:"sections"`
481+
NoInlineComments bool `mapstructure:"no-inline-comments"`
482+
NoPrefixComments bool `mapstructure:"no-prefix-comments"`
483+
SkipGenerated bool `mapstructure:"skip-generated"`
484+
CustomOrder bool `mapstructure:"custom-order"`
485+
NoLexOrder bool `mapstructure:"no-lex-order"`
484486

485487
// Deprecated: use Sections instead.
486488
LocalPrefixes string `mapstructure:"local-prefixes"`

pkg/golinters/gci/gci.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/daixiang0/gci/pkg/io"
1212
"github.com/daixiang0/gci/pkg/log"
1313
"github.com/daixiang0/gci/pkg/section"
14-
"github.com/golangci/modinfo"
1514
"github.com/hexops/gotextdiff"
1615
"github.com/hexops/gotextdiff/myers"
1716
"github.com/hexops/gotextdiff/span"
1817
"golang.org/x/tools/go/analysis"
18+
"golang.org/x/tools/go/analysis/passes/inspect"
1919

2020
"github.com/golangci/golangci-lint/pkg/config"
2121
"github.com/golangci/golangci-lint/pkg/goanalysis"
@@ -34,17 +34,19 @@ func New(settings *config.GciSettings) *goanalysis.Linter {
3434
Doc: goanalysis.TheOnlyanalyzerDoc,
3535
Run: goanalysis.DummyRun,
3636
Requires: []*analysis.Analyzer{
37-
modinfo.Analyzer,
37+
inspect.Analyzer,
3838
},
3939
}
4040

4141
var cfg *gcicfg.Config
4242
if settings != nil {
4343
rawCfg := gcicfg.YamlConfig{
4444
Cfg: gcicfg.BoolConfig{
45-
SkipGenerated: settings.SkipGenerated,
46-
CustomOrder: settings.CustomOrder,
47-
NoLexOrder: settings.NoLexOrder,
45+
NoInlineComments: settings.NoInlineComments,
46+
NoPrefixComments: settings.NoPrefixComments,
47+
SkipGenerated: settings.SkipGenerated,
48+
CustomOrder: settings.CustomOrder,
49+
NoLexOrder: settings.NoLexOrder,
4850
},
4951
SectionStrings: settings.Sections,
5052
}
@@ -158,16 +160,11 @@ func hackSectionList(pass *analysis.Pass, cfg *gcicfg.Config) (section.SectionLi
158160
for _, sect := range cfg.Sections {
159161
// local module hack
160162
if v, ok := sect.(*section.LocalModule); ok {
161-
info, err := modinfo.FindModuleFromPass(pass)
162-
if err != nil {
163-
return nil, err
164-
}
165-
166-
if info.Path == "" {
163+
if pass.Module == nil {
167164
continue
168165
}
169166

170-
v.Path = info.Path
167+
v.Path = pass.Module.Path
171168
}
172169

173170
sections = append(sections, sect)

0 commit comments

Comments
 (0)