Skip to content

Commit 0dbb041

Browse files
committed
feat(linter): add monorepo test cases
Add integration tests for the linter in a monorepo structure with foo and bar modules that have different linter configurations: - foo module has wsl enabled but unused disabled - bar module has both wsl and unused enabled - Added test fixtures with appropriate .golangci.yaml configs
1 parent 24b5290 commit 0dbb041

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

handler_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,79 @@ func TestLangHandler_lint_Integration(t *testing.T) {
166166
},
167167
},
168168
},
169+
{
170+
name: "monorepo (foo)",
171+
h: &langHandler{
172+
logger: newStdLogger(false),
173+
command: command,
174+
rootDir: filepath.Dir("./testdata/monorepo"),
175+
},
176+
filePath: "./testdata/monorepo/foo/main.go",
177+
want: []Diagnostic{
178+
{
179+
Range: Range{
180+
Start: Position{
181+
Line: 8,
182+
Character: 0,
183+
},
184+
End: Position{
185+
Line: 8,
186+
Character: 0,
187+
},
188+
},
189+
Severity: DSWarning,
190+
Code: nil,
191+
Source: pt("wsl"),
192+
Message: "wsl: block should not end with a whitespace (or comment)",
193+
RelatedInformation: nil,
194+
},
195+
},
196+
},
197+
{
198+
name: "monorepo (bar)",
199+
h: &langHandler{
200+
logger: newStdLogger(false),
201+
command: command,
202+
rootDir: filepath.Dir("./testdata/monorepo"),
203+
},
204+
filePath: "./testdata/monorepo/bar/main.go",
205+
want: []Diagnostic{
206+
{
207+
Range: Range{
208+
Start: Position{
209+
Line: 3,
210+
Character: 4,
211+
},
212+
End: Position{
213+
Line: 3,
214+
Character: 4,
215+
},
216+
},
217+
Severity: DSWarning,
218+
Code: nil,
219+
Source: pt("unused"),
220+
Message: "unused: var foo is unused",
221+
RelatedInformation: nil,
222+
},
223+
{
224+
Range: Range{
225+
Start: Position{
226+
Line: 8,
227+
Character: 0,
228+
},
229+
End: Position{
230+
Line: 8,
231+
Character: 0,
232+
},
233+
},
234+
Severity: DSWarning,
235+
Code: nil,
236+
Source: pt("wsl"),
237+
Message: "wsl: block should not end with a whitespace (or comment)",
238+
RelatedInformation: nil,
239+
},
240+
},
241+
},
169242
}
170243

171244
for _, tt := range tests {

testdata/monorepo/bar/.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- unused
5+
- wsl

testdata/monorepo/bar/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module foo
2+
3+
go 1.22.10

testdata/monorepo/bar/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
var bar = "bar"
4+
var foo = "foo"
5+
6+
func Bar() {
7+
_ = bar
8+
9+
}

testdata/monorepo/foo/.golangci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- wsl
5+
disable:
6+
- unused

testdata/monorepo/foo/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module foo
2+
3+
go 1.22.10

testdata/monorepo/foo/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
var bar = "bar"
4+
var foo = "foo"
5+
6+
func Bar() {
7+
_ = bar
8+
9+
}

0 commit comments

Comments
 (0)