Skip to content

Commit d0f79da

Browse files
committed
refactor: extract Snippet union types to break import cycle
1 parent eabe839 commit d0f79da

5 files changed

Lines changed: 53 additions & 52 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ First release under the **r5n** publisher with full React 17–19 support and a
4545
- Babel/Jest ESLint plugins and `@babel/eslint-parser` (unused — repo has no test suite or `.js` source files).
4646
- Legacy `@babel/cli`, `@babel/preset-typescript` devDependencies.
4747

48-
### Known issues
49-
50-
- Circular dependency between `src/helpers/parseSnippetToBody.ts` and `src/helpers/generateSnippets.ts` (type-only import of `Snippet`). Currently surfaced as a lint warning; will be fixed before `5.0.0` GA by extracting shared types to `src/types.ts`.
51-
5248
## [4.4.0] - 2020-12-18
5349

5450
- Enable extension after startup finish to respect and parse snippets on settings change.

‎src/helpers/generateSnippets.ts‎

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import path from 'path';
22
import { window } from 'vscode';
33

4-
import componentsSnippets, {
5-
ComponentsSnippet,
6-
} from '../sourceSnippets/components';
7-
import consoleSnippets, { ConsoleSnippet } from '../sourceSnippets/console';
8-
import hooksSnippets, { HooksSnippet } from '../sourceSnippets/hooks';
9-
import importsSnippets, { ImportsSnippet } from '../sourceSnippets/imports';
10-
import othersSnippets, { OthersSnippet } from '../sourceSnippets/others';
11-
import propTypesSnippets, {
12-
PropTypesSnippet,
13-
} from '../sourceSnippets/propTypes';
14-
import reactNativeSnippets, {
15-
ReactNativeSnippet,
16-
} from '../sourceSnippets/reactNative';
17-
import reduxSnippets, { ReduxSnippet } from '../sourceSnippets/redux';
18-
import testsSnippets, { TestsSnippet } from '../sourceSnippets/tests';
19-
import typescriptSnippets, {
20-
TypescriptSnippet,
21-
} from '../sourceSnippets/typescript';
4+
import componentsSnippets from '../sourceSnippets/components';
5+
import consoleSnippets from '../sourceSnippets/console';
6+
import hooksSnippets from '../sourceSnippets/hooks';
7+
import importsSnippets from '../sourceSnippets/imports';
8+
import othersSnippets from '../sourceSnippets/others';
9+
import propTypesSnippets from '../sourceSnippets/propTypes';
10+
import reactNativeSnippets from '../sourceSnippets/reactNative';
11+
import reduxSnippets from '../sourceSnippets/redux';
12+
import testsSnippets from '../sourceSnippets/tests';
13+
import typescriptSnippets from '../sourceSnippets/typescript';
14+
import { Snippets } from '../snippetTypes';
2215
import { writeFile } from 'fs/promises';
2316

2417
import extensionConfig from './extensionConfig';
@@ -49,34 +42,6 @@ const validateLanguageScopes = (scopes: string) => {
4942
return valid.length > 0 ? valid.join(',') : VALID_LANGUAGE_SCOPES.join(',');
5043
};
5144

52-
export type SnippetKeys =
53-
| OthersSnippet['key']
54-
| HooksSnippet['key']
55-
| ImportsSnippet['key']
56-
| ReactNativeSnippet['key']
57-
| TypescriptSnippet['key']
58-
| ReduxSnippet['key']
59-
| ComponentsSnippet['key']
60-
| ConsoleSnippet['key']
61-
| PropTypesSnippet['key']
62-
| TestsSnippet['key'];
63-
64-
export type Snippet =
65-
| OthersSnippet
66-
| HooksSnippet
67-
| ImportsSnippet
68-
| ReactNativeSnippet
69-
| TypescriptSnippet
70-
| ReduxSnippet
71-
| ComponentsSnippet
72-
| ConsoleSnippet
73-
| PropTypesSnippet
74-
| TestsSnippet;
75-
76-
export type Snippets = {
77-
[key in SnippetKeys]: Snippet;
78-
};
79-
8045
const getSnippets = () => {
8146
const { typescript, languageScopes: rawScopes } = extensionConfig();
8247
const languageScopes = validateLanguageScopes(rawScopes);

‎src/helpers/parseSnippetToBody.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { Snippet } from '../snippetTypes';
2+
13
import extensionConfig from './extensionConfig';
2-
import { Snippet } from './generateSnippets';
34
import replaceOrRemoveReactImport from './replaceOrRemoveReactImport';
45

56
const parseSnippetToBody = (snippet: Snippet) => {

‎src/helpers/snippetSearch.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { commands, SnippetString, window } from 'vscode';
33

44
import { readFile } from 'fs/promises';
55

6+
import { Snippet } from '../snippetTypes';
7+
68
import { parseSnippet } from './formatters';
7-
import { Snippet } from './generateSnippets';
89

910
const snippetSearch = async () => {
1011
const { showQuickPick, activeTextEditor } = window;

‎src/snippetTypes.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ComponentsSnippet } from './sourceSnippets/components';
2+
import { ConsoleSnippet } from './sourceSnippets/console';
3+
import { HooksSnippet } from './sourceSnippets/hooks';
4+
import { ImportsSnippet } from './sourceSnippets/imports';
5+
import { OthersSnippet } from './sourceSnippets/others';
6+
import { PropTypesSnippet } from './sourceSnippets/propTypes';
7+
import { ReactNativeSnippet } from './sourceSnippets/reactNative';
8+
import { ReduxSnippet } from './sourceSnippets/redux';
9+
import { TestsSnippet } from './sourceSnippets/tests';
10+
import { TypescriptSnippet } from './sourceSnippets/typescript';
11+
12+
export type SnippetKeys =
13+
| OthersSnippet['key']
14+
| HooksSnippet['key']
15+
| ImportsSnippet['key']
16+
| ReactNativeSnippet['key']
17+
| TypescriptSnippet['key']
18+
| ReduxSnippet['key']
19+
| ComponentsSnippet['key']
20+
| ConsoleSnippet['key']
21+
| PropTypesSnippet['key']
22+
| TestsSnippet['key'];
23+
24+
export type Snippet =
25+
| OthersSnippet
26+
| HooksSnippet
27+
| ImportsSnippet
28+
| ReactNativeSnippet
29+
| TypescriptSnippet
30+
| ReduxSnippet
31+
| ComponentsSnippet
32+
| ConsoleSnippet
33+
| PropTypesSnippet
34+
| TestsSnippet;
35+
36+
export type Snippets = {
37+
[key in SnippetKeys]: Snippet;
38+
};

0 commit comments

Comments
 (0)