Skip to content

Commit 5476570

Browse files
authored
Revert "Fix ExpectType with extra whitespace (microsoft#1011)" (microsoft#1013)
1 parent 9f96a4d commit 5476570

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

.changeset/rude-ways-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@definitelytyped/eslint-plugin": patch
3+
---
4+
5+
Revert ExpectType bugfix

packages/eslint-plugin/src/rules/expect.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function parseAssertions(sourceFile: ts.SourceFile): Assertions {
401401
const duplicates: number[] = [];
402402

403403
const { text } = sourceFile;
404-
const commentRegexp = /\/\/\s*\$ExpectType\s+(.*)/g;
404+
const commentRegexp = /\/\/(.*)/g;
405405
const lineStarts = sourceFile.getLineStarts();
406406
let curLine = 0;
407407

@@ -410,8 +410,13 @@ function parseAssertions(sourceFile: ts.SourceFile): Assertions {
410410
if (commentMatch === null) {
411411
break;
412412
}
413+
// Match on the contents of that comment so we do nothing in a commented-out assertion,
414+
// i.e. `// foo; // $ExpectType number`
415+
if (!commentMatch[1].startsWith(" $ExpectType ")) {
416+
continue;
417+
}
413418
const line = getLine(commentMatch.index);
414-
const expectedType = commentMatch[1].trim();
419+
const expectedType = commentMatch[1].slice(" $ExpectType ".length);
415420
// Don't bother with the assertion if there are 2 assertions on 1 line. Just fail for the duplicate.
416421
if (typeAssertions.delete(line)) {
417422
duplicates.push(line);

packages/eslint-plugin/test/__file_snapshots__/types/expect/expect-tests.ts.lint

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ types/expect/expect-tests.ts
33
number
44
got:
55
1234 @definitelytyped/expect
6-
16:1 error TypeScript expected type to be:
6+
14:1 error TypeScript expected type to be:
77
NotRightAtAll
88
got:
99
1234 @definitelytyped/expect
10-
47:1 error Cannot match a node to this assertion. If this is a multiline function call, ensure the assertion is on the line above @definitelytyped/expect
11-
51:1 error Cannot match a node to this assertion. If this is a multiline function call, ensure the assertion is on the line above @definitelytyped/expect
10+
45:1 error Cannot match a node to this assertion. If this is a multiline function call, ensure the assertion is on the line above @definitelytyped/expect
11+
49:1 error Cannot match a node to this assertion. If this is a multiline function call, ensure the assertion is on the line above @definitelytyped/expect
1212

1313
✖ 4 problems (4 errors, 0 warnings)
1414

@@ -30,8 +30,6 @@ got:
3030
// $ExpectType 1234
3131
expect.foo;
3232

33-
// $ExpectType 1234
34-
expect.foo;
3533

3634
// $ExpectType NotRightAtAll
3735
expect.foo;

packages/eslint-plugin/test/fixtures/types/expect/expect-tests.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ expect.foo;
99
// $ExpectType 1234
1010
expect.foo;
1111

12-
// $ExpectType 1234
13-
expect.foo;
1412

1513
// $ExpectType NotRightAtAll
1614
expect.foo;

0 commit comments

Comments
 (0)