Skip to content

Commit b59efbc

Browse files
committed
test: add test for linting files outside a project
1 parent df0f96a commit b59efbc

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

e2e/__snapshots__/snapshot.test.ts.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
exports[`TSGoLint E2E Snapshot Tests > should correctly evaluate project references 1`] = `[]`;
44

5+
exports[`TSGoLint E2E Snapshot Tests > should correctly lint files not inside a project 1`] = `
6+
[
7+
{
8+
"file_path": "fixtures/with-unmatched-files/src/index.ts",
9+
"fixes": [],
10+
"message": {
11+
"description": "Unsafe argument of type any assigned to a parameter of type string.",
12+
"id": "unsafeArgument",
13+
},
14+
"range": {
15+
"end": 45,
16+
"pos": 36,
17+
},
18+
"rule": "no-unsafe-argument",
19+
"suggestions": [],
20+
},
21+
{
22+
"file_path": "fixtures/with-unmatched-files/test.ts",
23+
"fixes": [],
24+
"message": {
25+
"description": "Unsafe argument of type any assigned to a parameter of type string.",
26+
"id": "unsafeArgument",
27+
},
28+
"range": {
29+
"end": 45,
30+
"pos": 36,
31+
},
32+
"rule": "no-unsafe-argument",
33+
"suggestions": [],
34+
},
35+
]
36+
`;
37+
538
exports[`TSGoLint E2E Snapshot Tests > should generate consistent diagnostics snapshot 1`] = `
639
[
740
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo(_arg0: string) {}
2+
3+
foo('' as any);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo(_arg0: string) {}
2+
3+
foo('' as any);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"compilerOptions": {},
3+
"include": ["src/**/*"]
4+
}

e2e/snapshot.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,23 @@ describe('TSGoLint E2E Snapshot Tests', () => {
233233

234234
expect(diagnostics).toMatchSnapshot();
235235
});
236+
237+
it('should correctly lint files not inside a project', async () => {
238+
const testFiles = await getTestFiles('with-unmatched-files');
239+
expect(testFiles.length).toBeGreaterThan(0);
240+
241+
const config = generateConfig(testFiles, ['no-unsafe-argument']);
242+
243+
const env = { ...process.env, GOMAXPROCS: '1' };
244+
245+
const output = execFileSync(TSGOLINT_BIN, ['headless'], {
246+
input: config,
247+
env,
248+
});
249+
250+
let diagnostics = parseHeadlessOutput(output);
251+
diagnostics = sortDiagnostics(diagnostics);
252+
253+
expect(diagnostics).toMatchSnapshot();
254+
});
236255
});

0 commit comments

Comments
 (0)