Skip to content

Commit 50808c2

Browse files
committed
Added parsing of t-prefix
1 parent c0f8c57 commit 50808c2

9 files changed

+41
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"extension:build": "turbo run vscode:build",
1414
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1515
"prepare": "husky install",
16-
"release": "turbo run publish:vsce publish:ovsx && node ./scripts/tag-extension.js"
16+
"release": "turbo run publish:vsce publish:ovsx && node ./scripts/tag-extension.js",
17+
"parser:dev": "turbo run dev --filter *parser"
1718
},
1819
"devDependencies": {
1920
"husky": ">=6",

packages/parser/src/tips.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ export const allTips = [
270270
};
271271
},
272272
),
273+
createInlineTip(
274+
't-prefix-in-generic-arguments',
275+
z.object({ loc: SourceLocationSchema, name: z.string().startsWith('T') }),
276+
({ parse, push }) => {
277+
return {
278+
TSTypeParameter: (path) => {
279+
safeParse(() => {
280+
const node = parse(path.node);
281+
push(node.loc);
282+
});
283+
},
284+
};
285+
},
286+
),
273287
createInlineTip(
274288
'bigint',
275289
z.object({

packages/parser/src/tips/genericSlotsInFunctions.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ it('Should work', () => {
1111

1212
expect(tips).toEqual([
1313
'generic-slots-in-functions',
14+
't-prefix-in-generic-arguments',
1415
'generic-slots-in-functions',
16+
't-prefix-in-generic-arguments',
1517
]);
1618
});

packages/parser/src/tips/inlineTips.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ import { getTipsFromFile } from '../getTipsFromFile';
44
it('Should figure out as const', () => {
55
const fileContents = `
66
const yeah = '' as const;
7-
`;
7+
`;
88

99
const tips = getTipsFromFile(fileContents).map((tip) => tip.type);
1010

1111
expect(tips).toEqual(['as-const']);
1212
});
1313

14+
it('t-prefix-in-generic-arguments', () => {
15+
const fileContents = `
16+
type Yeah<T> = T;
17+
`;
18+
19+
const tips = getTipsFromFile(fileContents).map((tip) => tip.type);
20+
21+
expect(tips).toContain('t-prefix-in-generic-arguments');
22+
});
23+
1424
it('Union type', () => {
1525
const fileContents = `
1626
type Yeah = string | number;

packages/parser/src/tips/interfaceWithGenerics.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ it('Should work', () => {
1212
expect(tips).toEqual([
1313
'interface-declaration',
1414
'interface-with-generics',
15+
't-prefix-in-generic-arguments',
1516
'type-alias-declaration',
1617
'type-alias-with-generics',
18+
't-prefix-in-generic-arguments',
1719
]);
1820
});

packages/parser/src/tips/interfaceWithMultipleGenerics.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ it('Should work', () => {
1313
'interface-declaration',
1414
'interface-with-generics',
1515
'interface-with-multiple-generics',
16+
't-prefix-in-generic-arguments',
17+
't-prefix-in-generic-arguments',
1618
'type-alias-declaration',
1719
'type-alias-with-generics',
1820
'type-alias-with-multiple-generics',
21+
't-prefix-in-generic-arguments',
22+
't-prefix-in-generic-arguments',
1923
]);
2024
});

packages/parser/src/tips/kInKeyof.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ it('Should work', () => {
1313
expect(tips).toEqual([
1414
'type-alias-declaration',
1515
'type-alias-with-generics',
16+
't-prefix-in-generic-arguments',
1617
'mapped-type',
1718
'k-in-keyof',
1819
'keyof',

packages/parser/src/tips/mappedType.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ it('Should work', () => {
1313
expect(tips).toEqual([
1414
'type-alias-declaration',
1515
'type-alias-with-generics',
16+
't-prefix-in-generic-arguments',
1617
'mapped-type',
1718
]);
1819
});

packages/parser/src/tips/multipleGenericSlotsInFunctions.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ it('Should work', () => {
1212
expect(tips).toEqual([
1313
'generic-slots-in-functions',
1414
'multiple-generic-slots-in-functions',
15+
't-prefix-in-generic-arguments',
16+
't-prefix-in-generic-arguments',
1517
'generic-slots-in-functions',
1618
'multiple-generic-slots-in-functions',
19+
't-prefix-in-generic-arguments',
20+
't-prefix-in-generic-arguments',
1721
]);
1822
});

0 commit comments

Comments
 (0)