Skip to content

Commit 96b9dae

Browse files
committed
chore: update tests
1 parent f939c27 commit 96b9dae

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

pkg/lint/lintersdb/enabled_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (es EnabledSet) build(lcfg *config.Linters, enabledByDefaultLinters []*lint
8181
}
8282

8383
// typecheck is not a real linter and cannot be disabled.
84-
if _, ok := resultLintersSet["typecheck"]; !ok && !es.cfg.InternalCmdTest {
84+
if _, ok := resultLintersSet["typecheck"]; !ok && (es.cfg == nil || !es.cfg.InternalCmdTest) {
8585
for _, lc := range es.m.GetLinterConfigs("typecheck") {
8686
// it's important to use lc.Name() nor name because name can be alias
8787
resultLintersSet[lc.Name()] = lc

pkg/lint/lintersdb/enabled_set_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,81 +16,86 @@ func TestGetEnabledLintersSet(t *testing.T) {
1616
def []string // enabled by default linters
1717
exp []string // alphabetically ordered enabled linter names
1818
}
19+
1920
allMegacheckLinterNames := []string{"gosimple", "staticcheck", "unused"}
21+
2022
cases := []cs{
2123
{
2224
cfg: config.Linters{
2325
Disable: []string{"megacheck"},
2426
},
2527
name: "disable all linters from megacheck",
2628
def: allMegacheckLinterNames,
27-
exp: nil, // all disabled
29+
exp: []string{"typecheck"}, // all disabled
2830
},
2931
{
3032
cfg: config.Linters{
3133
Disable: []string{"staticcheck"},
3234
},
3335
name: "disable only staticcheck",
3436
def: allMegacheckLinterNames,
35-
exp: []string{"gosimple", "unused"},
37+
exp: []string{"gosimple", "typecheck", "unused"},
3638
},
3739
{
3840
name: "don't merge into megacheck",
3941
def: allMegacheckLinterNames,
40-
exp: allMegacheckLinterNames,
42+
exp: []string{"gosimple", "staticcheck", "typecheck", "unused"},
4143
},
4244
{
4345
name: "expand megacheck",
4446
cfg: config.Linters{
4547
Enable: []string{"megacheck"},
4648
},
4749
def: nil,
48-
exp: allMegacheckLinterNames,
50+
exp: []string{"gosimple", "staticcheck", "typecheck", "unused"},
4951
},
5052
{
5153
name: "don't disable anything",
52-
def: []string{"gofmt", "govet"},
53-
exp: []string{"gofmt", "govet"},
54+
def: []string{"gofmt", "govet", "typecheck"},
55+
exp: []string{"gofmt", "govet", "typecheck"},
5456
},
5557
{
5658
name: "enable gosec by gas alias",
5759
cfg: config.Linters{
5860
Enable: []string{"gas"},
5961
},
60-
exp: []string{"gosec"},
62+
exp: []string{"gosec", "typecheck"},
6163
},
6264
{
6365
name: "enable gosec by primary name",
6466
cfg: config.Linters{
6567
Enable: []string{"gosec"},
6668
},
67-
exp: []string{"gosec"},
69+
exp: []string{"gosec", "typecheck"},
6870
},
6971
{
7072
name: "enable gosec by both names",
7173
cfg: config.Linters{
7274
Enable: []string{"gosec", "gas"},
7375
},
74-
exp: []string{"gosec"},
76+
exp: []string{"gosec", "typecheck"},
7577
},
7678
{
7779
name: "disable gosec by gas alias",
7880
cfg: config.Linters{
7981
Disable: []string{"gas"},
8082
},
8183
def: []string{"gosec"},
84+
exp: []string{"typecheck"},
8285
},
8386
{
8487
name: "disable gosec by primary name",
8588
cfg: config.Linters{
8689
Disable: []string{"gosec"},
8790
},
8891
def: []string{"gosec"},
92+
exp: []string{"typecheck"},
8993
},
9094
}
9195

9296
m := NewManager(nil, nil)
9397
es := NewEnabledSet(m, NewValidator(m), nil, nil)
98+
9499
for _, c := range cases {
95100
c := c
96101
t.Run(c.name, func(t *testing.T) {

pkg/result/processors/nolint_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,21 @@ func TestNolintUnused(t *testing.T) {
310310
}
311311

312312
t.Run("when an issue does not occur, it is not removed from the nolintlint issues", func(t *testing.T) {
313-
p := createProcessor(t, log, []string{"nolintlint", "varcheck"})
313+
p := createProcessor(t, log, []string{"nolintlint", "typecheck", "varcheck"})
314314
defer p.Finish()
315315

316316
processAssertSame(t, p, nolintlintIssueVarcheck)
317317
})
318318

319319
t.Run("when an issue does not occur but nolintlint is nolinted, it is removed from the nolintlint issues", func(t *testing.T) {
320-
p := createProcessor(t, log, []string{"nolintlint", "varcheck"})
320+
p := createProcessor(t, log, []string{"nolintlint", "typecheck", "varcheck"})
321321
defer p.Finish()
322322

323323
processAssertEmpty(t, p, nolintlintIssueVarcheckUnusedOK)
324324
})
325325

326326
t.Run("when an issue occurs, it is removed from the nolintlint issues", func(t *testing.T) {
327-
p := createProcessor(t, log, []string{"nolintlint", "varcheck"})
327+
p := createProcessor(t, log, []string{"nolintlint", "typecheck", "varcheck"})
328328
defer p.Finish()
329329

330330
processAssertEmpty(t, p, []result.Issue{{
@@ -338,7 +338,7 @@ func TestNolintUnused(t *testing.T) {
338338

339339
t.Run("when a linter is not enabled, it is removed from the nolintlint unused issues", func(t *testing.T) {
340340
enabledSetLog := logutils.NewMockLog()
341-
enabledSetLog.On("Infof", "Active %d linters: %s", 1, []string{"nolintlint"})
341+
enabledSetLog.On("Infof", "Active %d linters: %s", 2, []string{"nolintlint", "typecheck"})
342342

343343
cfg := &config.Config{Linters: config.Linters{DisableAll: true, Enable: []string{"nolintlint"}}}
344344
dbManager := lintersdb.NewManager(cfg, nil)

0 commit comments

Comments
 (0)