Skip to content

Commit c67349a

Browse files
committed
feat: remove typecheck from the linter list
1 parent 812cad9 commit c67349a

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

pkg/commands/help.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func printLinterConfigs(lcs []*linter.Config) {
6363
func (e *Executor) executeLintersHelp(_ *cobra.Command, _ []string) {
6464
var enabledLCs, disabledLCs []*linter.Config
6565
for _, lc := range e.DBManager.GetAllSupportedLinterConfigs() {
66+
if lc.Internal {
67+
continue
68+
}
69+
6670
if lc.EnabledByDefault {
6771
enabledLCs = append(enabledLCs, lc)
6872
} else {
@@ -78,8 +82,12 @@ func (e *Executor) executeLintersHelp(_ *cobra.Command, _ []string) {
7882
color.Green("\nLinters presets:")
7983
for _, p := range e.DBManager.AllPresets() {
8084
linters := e.DBManager.GetAllLinterConfigsForPreset(p)
81-
linterNames := make([]string, 0, len(linters))
85+
var linterNames []string
8286
for _, lc := range linters {
87+
if lc.Internal {
88+
continue
89+
}
90+
8391
linterNames = append(linterNames, lc.Name())
8492
}
8593
sort.Strings(linterNames)

pkg/commands/linters.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ func (e *Executor) executeLinters(_ *cobra.Command, _ []string) error {
2929
}
3030

3131
color.Green("Enabled by your configuration linters:\n")
32-
enabledLinters := make([]*linter.Config, 0, len(enabledLintersMap))
33-
for _, linter := range enabledLintersMap {
34-
enabledLinters = append(enabledLinters, linter)
32+
var enabledLinters []*linter.Config
33+
for _, lc := range enabledLintersMap {
34+
if lc.Internal {
35+
continue
36+
}
37+
38+
enabledLinters = append(enabledLinters, lc)
3539
}
3640
printLinterConfigs(enabledLinters)
3741

3842
var disabledLCs []*linter.Config
3943
for _, lc := range e.DBManager.GetAllSupportedLinterConfigs() {
44+
if lc.Internal {
45+
continue
46+
}
47+
4048
if enabledLintersMap[lc.Name()] == nil {
4149
disabledLCs = append(disabledLCs, lc)
4250
}

pkg/lint/linter/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Config struct {
4242
AlternativeNames []string
4343

4444
OriginalURL string // URL of original (not forked) repo, needed for autogenerated README
45+
Internal bool // Internal linters cannot be disabled (ex: typecheck).
4546
CanAutoFix bool
4647
IsSlow bool
4748
DoesChangeTypes bool
@@ -55,6 +56,11 @@ func (lc *Config) WithEnabledByDefault() *Config {
5556
return lc
5657
}
5758

59+
func (lc *Config) WithInternal() *Config {
60+
lc.Internal = true
61+
return lc
62+
}
63+
5864
func (lc *Config) ConsiderSlow() *Config {
5965
lc.IsSlow = true
6066
return lc

pkg/lint/lintersdb/enabled_set.go

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func NewEnabledSet(m *Manager, v *Validator, log logutils.Log, cfg *config.Confi
3333

3434
func (es EnabledSet) build(lcfg *config.Linters, enabledByDefaultLinters []*linter.Config) map[string]*linter.Config {
3535
es.debugf("Linters config: %#v", lcfg)
36+
3637
resultLintersSet := map[string]*linter.Config{}
3738
switch {
3839
case len(lcfg.Presets) != 0:
@@ -78,6 +79,14 @@ func (es EnabledSet) build(lcfg *config.Linters, enabledByDefaultLinters []*lint
7879
}
7980
}
8081

82+
// typecheck is not a real linter and cannot be disabled.
83+
if _, ok := resultLintersSet["typecheck"]; !ok {
84+
for _, lc := range es.m.GetLinterConfigs("typecheck") {
85+
// it's important to use lc.Name() nor name because name can be alias
86+
resultLintersSet[lc.Name()] = lc
87+
}
88+
}
89+
8190
return resultLintersSet
8291
}
8392

pkg/lint/lintersdb/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
804804
WithURL("https://github.com/moricho/tparallel"),
805805

806806
linter.NewConfig(golinters.NewTypecheck()).
807+
WithInternal().
807808
WithEnabledByDefault().
808809
WithSince("v1.3.0").
809810
WithLoadForGoAnalysis().

scripts/expand_website_templates/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func getLintersListMarkdown(enabled bool) string {
238238
var neededLcs []*linter.Config
239239
lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
240240
for _, lc := range lcs {
241+
if lc.Internal {
242+
continue
243+
}
244+
241245
if lc.EnabledByDefault == enabled {
242246
neededLcs = append(neededLcs, lc)
243247
}

0 commit comments

Comments
 (0)