Skip to content

Commit 4760885

Browse files
committed
Improves import protection in webviews
1 parent 5505dcd commit 4760885

File tree

262 files changed

+830
-708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+830
-708
lines changed

eslint.config.mjs

Lines changed: 112 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -43,67 +43,7 @@ export default ts.config(
4343
'no-loop-func': 'error',
4444
'no-mixed-spaces-and-tabs': 'off',
4545
'no-restricted-globals': ['error', 'process'],
46-
'no-restricted-imports': [
47-
'error',
48-
{
49-
paths: [
50-
'assert',
51-
'buffer',
52-
'child_process',
53-
'cluster',
54-
'crypto',
55-
'dgram',
56-
'dns',
57-
'domain',
58-
'events',
59-
'freelist',
60-
'fs',
61-
'http',
62-
'https',
63-
'module',
64-
'net',
65-
'os',
66-
'path',
67-
'process',
68-
'punycode',
69-
'querystring',
70-
'readline',
71-
'repl',
72-
'smalloc',
73-
'stream',
74-
'string_decoder',
75-
'sys',
76-
'timers',
77-
'tls',
78-
'tracing',
79-
'tty',
80-
'url',
81-
'util',
82-
'vm',
83-
'zlib',
84-
],
85-
patterns: [
86-
{
87-
group: ['**/env/**/*'],
88-
message: 'Use @env/ instead',
89-
},
90-
{
91-
group: ['src/*'],
92-
message: 'Use relative paths instead',
93-
},
94-
{
95-
group: ['react-dom'],
96-
importNames: ['Container'],
97-
message: 'Use our Container instead',
98-
},
99-
{
100-
group: ['vscode'],
101-
importNames: ['CancellationError'],
102-
message: 'Use our CancellationError instead',
103-
},
104-
],
105-
},
106-
],
46+
'no-restricted-imports': 'off',
10747
'no-return-assign': 'error',
10848
'no-return-await': 'warn',
10949
'no-self-compare': 'error',
@@ -239,6 +179,67 @@ export default ts.config(
239179
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
240180
'@typescript-eslint/no-non-null-assertion': 'off',
241181
'@typescript-eslint/no-redundant-type-constituents': 'off',
182+
'@typescript-eslint/no-restricted-imports': [
183+
'error',
184+
{
185+
paths: [
186+
'assert',
187+
'buffer',
188+
'child_process',
189+
'cluster',
190+
'crypto',
191+
'dgram',
192+
'dns',
193+
'domain',
194+
'events',
195+
'freelist',
196+
'fs',
197+
'http',
198+
'https',
199+
'module',
200+
'net',
201+
'os',
202+
'path',
203+
'process',
204+
'punycode',
205+
'querystring',
206+
'readline',
207+
'repl',
208+
'smalloc',
209+
'stream',
210+
'string_decoder',
211+
'sys',
212+
'timers',
213+
'tls',
214+
'tracing',
215+
'tty',
216+
'url',
217+
'util',
218+
'vm',
219+
'zlib',
220+
],
221+
patterns: [
222+
{
223+
group: ['**/env/**/*'],
224+
message: 'Use @env/ instead',
225+
},
226+
{
227+
group: ['src/*'],
228+
message: 'Use relative paths instead',
229+
},
230+
{
231+
group: ['react-dom'],
232+
importNames: ['Container'],
233+
message: 'Use our Container instead',
234+
},
235+
{
236+
group: ['vscode'],
237+
importNames: ['CancellationError'],
238+
message: 'Use our CancellationError instead',
239+
},
240+
],
241+
},
242+
],
242243
'@typescript-eslint/no-unnecessary-condition': 'off',
243244
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
244245
'@typescript-eslint/no-unnecessary-type-parameters': 'off', // https://github.com/typescript-eslint/typescript-eslint/issues/9705
@@ -308,7 +309,7 @@ export default ts.config(
308309
{
309310
files: ['src/env/node/**/*'],
310311
rules: {
311-
'no-restricted-imports': [
312+
'@typescript-eslint/no-restricted-imports': [
312313
'error',
313314
{
314315
patterns: [
@@ -321,6 +322,11 @@ export default ts.config(
321322
importNames: ['Container'],
322323
message: 'Use our Container instead',
323324
},
325+
{
326+
group: ['vscode'],
327+
importNames: ['CancellationError'],
328+
message: 'Use our CancellationError instead',
329+
},
324330
],
325331
},
326332
],
@@ -349,7 +355,24 @@ export default ts.config(
349355
name: 'webviews',
350356
...litConfigs['flat/recommended'],
351357
...wcConfigs['flat/recommended'],
352-
files: ['src/webviews/apps/**/*', 'src/env/browser/**/*'],
358+
// Keep in sync with `src/webviews/apps/tsconfig.json`
359+
files: [
360+
'src/webviews/apps/**/*',
361+
'src/@types/**/*',
362+
'src/env/browser/**/*',
363+
'src/plus/gk/account/promos.ts',
364+
'src/plus/gk/account/subscription.ts',
365+
'src/plus/webviews/**/protocol.ts',
366+
'src/webviews/protocol.ts',
367+
'src/webviews/**/protocol.ts',
368+
'src/config.ts',
369+
'src/constants.ts',
370+
'src/constants.*.ts',
371+
'src/features.ts',
372+
'src/subscription.ts',
373+
'src/system/*.ts',
374+
'src/system/decorators/log.ts',
375+
],
353376
languageOptions: {
354377
globals: {
355378
...globals.browser,
@@ -364,6 +387,29 @@ export default ts.config(
364387
projectService: true,
365388
},
366389
},
390+
rules: {
391+
'@typescript-eslint/no-restricted-imports': [
392+
'error',
393+
{
394+
patterns: [
395+
{
396+
group: ['src/*'],
397+
message: 'Use relative paths instead',
398+
},
399+
{
400+
group: ['react-dom'],
401+
importNames: ['Container'],
402+
message: 'Use our Container instead',
403+
},
404+
{
405+
group: ['vscode'],
406+
message: "Can't use vscode in webviews",
407+
allowTypeImports: true,
408+
},
409+
],
410+
},
411+
],
412+
},
367413
settings: {
368414
wc: {
369415
elementBaseClasses: [
@@ -390,6 +436,9 @@ export default ts.config(
390436
projectService: true,
391437
},
392438
},
439+
rules: {
440+
'@typescript-eslint/no-restricted-imports': 'off',
441+
},
393442
},
394443
// {
395444
// name: 'tests:unit',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18009,7 +18009,7 @@
1800918009
"sortablejs": "1.15.0"
1801018010
},
1801118011
"devDependencies": {
18012-
"@eamodio/eslint-lite-webpack-plugin": "0.0.8",
18012+
"@eamodio/eslint-lite-webpack-plugin": "0.1.0",
1801318013
"@eslint/js": "9.10.0",
1801418014
"@playwright/test": "1.47.1",
1801518015
"@swc/core": "1.7.26",

src/ai/aiProviderService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import type { GitRevisionReference } from '../git/models/reference';
1111
import type { Repository } from '../git/models/repository';
1212
import { isRepository } from '../git/models/repository';
1313
import { showAIModelPicker } from '../quickpicks/aiModelPicker';
14-
import { configuration } from '../system/configuration';
1514
import { getSettledValue } from '../system/promise';
16-
import type { Storage } from '../system/storage';
17-
import { supportedInVSCodeVersion } from '../system/utils';
15+
import { configuration } from '../system/vscode/configuration';
16+
import type { Storage } from '../system/vscode/storage';
17+
import { supportedInVSCodeVersion } from '../system/vscode/utils';
1818
import type { TelemetryService } from '../telemetry/telemetry';
1919
import { AnthropicProvider } from './anthropicProvider';
2020
import { GeminiProvider } from './geminiProvider';

src/ai/anthropicProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { window } from 'vscode';
44
import type { TelemetryEvents } from '../constants.telemetry';
55
import type { Container } from '../container';
66
import { CancellationError } from '../errors';
7-
import { configuration } from '../system/configuration';
87
import { sum } from '../system/iterable';
9-
import type { Storage } from '../system/storage';
8+
import { configuration } from '../system/vscode/configuration';
9+
import type { Storage } from '../system/vscode/storage';
1010
import type { AIModel, AIProvider } from './aiProviderService';
1111
import { getApiKey as getApiKeyCore, getMaxCharacters } from './aiProviderService';
1212
import { cloudPatchMessageSystemPrompt, codeSuggestMessageSystemPrompt, commitMessageSystemPrompt } from './prompts';

src/ai/geminiProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { window } from 'vscode';
44
import type { TelemetryEvents } from '../constants.telemetry';
55
import type { Container } from '../container';
66
import { CancellationError } from '../errors';
7-
import { configuration } from '../system/configuration';
87
import { sum } from '../system/iterable';
9-
import type { Storage } from '../system/storage';
8+
import { configuration } from '../system/vscode/configuration';
9+
import type { Storage } from '../system/vscode/storage';
1010
import type { AIModel, AIProvider } from './aiProviderService';
1111
import { getApiKey as getApiKeyCore, getMaxCharacters } from './aiProviderService';
1212
import { cloudPatchMessageSystemPrompt, codeSuggestMessageSystemPrompt, commitMessageSystemPrompt } from './prompts';

src/ai/openaiProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { window } from 'vscode';
44
import type { TelemetryEvents } from '../constants.telemetry';
55
import type { Container } from '../container';
66
import { CancellationError } from '../errors';
7-
import { configuration } from '../system/configuration';
87
import { sum } from '../system/iterable';
9-
import type { Storage } from '../system/storage';
8+
import { configuration } from '../system/vscode/configuration';
9+
import type { Storage } from '../system/vscode/storage';
1010
import type { AIModel, AIProvider } from './aiProviderService';
1111
import { getApiKey as getApiKeyCore, getMaxCharacters } from './aiProviderService';
1212
import { cloudPatchMessageSystemPrompt, codeSuggestMessageSystemPrompt, commitMessageSystemPrompt } from './prompts';

src/ai/vscodeProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { CancellationToken, LanguageModelChat, LanguageModelChatSelector }
22
import { CancellationTokenSource, LanguageModelChatMessage, lm, window } from 'vscode';
33
import type { TelemetryEvents } from '../constants.telemetry';
44
import type { Container } from '../container';
5-
import { configuration } from '../system/configuration';
65
import { sum } from '../system/iterable';
76
import { capitalize } from '../system/string';
7+
import { configuration } from '../system/vscode/configuration';
88
import type { AIModel, AIProvider } from './aiProviderService';
99
import { getMaxCharacters } from './aiProviderService';
1010
import { cloudPatchMessageSystemPrompt, codeSuggestMessageSystemPrompt, commitMessageSystemPrompt } from './prompts';

src/annotations/annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type { CommitFormatOptions } from '../git/formatters/commitFormatter';
1414
import { CommitFormatter } from '../git/formatters/commitFormatter';
1515
import type { GitCommit } from '../git/models/commit';
1616
import { scale, toRgba } from '../system/color';
17-
import { configuration } from '../system/configuration';
1817
import { getWidth, interpolate, pad } from '../system/string';
18+
import { configuration } from '../system/vscode/configuration';
1919
import type { BlameFontOptions } from './gutterBlameAnnotationProvider';
2020

2121
export interface ComputedHeatmap {

src/annotations/autolinks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import type { ProviderReference } from '../git/models/remoteProvider';
1010
import type { ResourceDescriptor } from '../plus/integrations/integration';
1111
import type { IntegrationId } from '../plus/integrations/providers/models';
1212
import { IssueIntegrationId } from '../plus/integrations/providers/models';
13-
import { configuration } from '../system/configuration';
1413
import { fromNow } from '../system/date';
1514
import { debug } from '../system/decorators/log';
1615
import { encodeUrl } from '../system/encoding';
1716
import { join, map } from '../system/iterable';
1817
import { Logger } from '../system/logger';
1918
import type { MaybePausedResult } from '../system/promise';
2019
import { capitalize, encodeHtmlWeak, escapeMarkdown, escapeRegex, getSuperscript } from '../system/string';
20+
import { configuration } from '../system/vscode/configuration';
2121

2222
const emptyAutolinkMap = Object.freeze(new Map<string, Autolink>());
2323

src/annotations/blameAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { GitUri } from '../git/gitUri';
66
import type { GitBlame } from '../git/models/blame';
77
import type { GitCommit } from '../git/models/commit';
88
import { changesMessage, detailsMessage } from '../hovers/hovers';
9-
import { configuration } from '../system/configuration';
109
import { log } from '../system/decorators/log';
10+
import { configuration } from '../system/vscode/configuration';
1111
import type { TrackedGitDocument } from '../trackers/trackedDocument';
1212
import type { DidChangeStatusCallback } from './annotationProvider';
1313
import { AnnotationProviderBase } from './annotationProvider';

0 commit comments

Comments
 (0)