Skip to content

Commit 1e765ad

Browse files
authored
Fix injected services becoming public by mistake (microsoft#209513)
* Fix injected services becoming public by mistake Fixes cases of `@IFooService readonly foo: IFooService`. This makes the service public, which is likely not expected and also means we can't mangle it * Fix name * Remove unused props
1 parent 641eb4c commit 1e765ad

File tree

14 files changed

+83
-43
lines changed

14 files changed

+83
-43
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as eslint from 'eslint';
7+
import { TSESTree } from '@typescript-eslint/experimental-utils';
8+
9+
/**
10+
* Enforces that all parameter properties have an explicit access modifier (public, protected, private).
11+
*
12+
* This catches a common bug where a service is accidentally made public by simply writing: `readonly prop: Foo`
13+
*/
14+
export = new class implements eslint.Rule.RuleModule {
15+
16+
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
17+
function check(inNode: any) {
18+
const node: TSESTree.TSParameterProperty = inNode;
19+
20+
// For now, only apply to injected services
21+
const firstDecorator = node.decorators?.at(0);
22+
if (
23+
firstDecorator?.expression.type !== 'Identifier'
24+
|| !firstDecorator.expression.name.endsWith('Service')
25+
) {
26+
return;
27+
}
28+
29+
if (!node.accessibility) {
30+
context.report({
31+
node: inNode,
32+
message: 'Parameter properties must have an explicit access modifier.'
33+
});
34+
}
35+
}
36+
37+
return {
38+
['TSParameterProperty']: check,
39+
};
40+
}
41+
};

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
],
7171
"local/code-translation-remind": "warn",
7272
"local/code-no-native-private": "warn",
73+
"local/code-parameter-properties-must-have-explicit-accessibility": "warn",
7374
"local/code-no-nls-in-standalone-editor": "warn",
7475
"local/code-no-standalone-editor": "warn",
7576
"local/code-no-unexternalized-strings": "warn",

src/vs/editor/contrib/stickyScroll/browser/stickyScrollModelProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export class StickyModelProvider extends Disposable implements IStickyModelProvi
5252
constructor(
5353
private readonly _editor: IActiveCodeEditor,
5454
onProviderUpdate: () => void,
55-
@IInstantiationService readonly _languageConfigurationService: ILanguageConfigurationService,
56-
@ILanguageFeaturesService readonly _languageFeaturesService: ILanguageFeaturesService,
55+
@IInstantiationService _languageConfigurationService: ILanguageConfigurationService,
56+
@ILanguageFeaturesService _languageFeaturesService: ILanguageFeaturesService,
5757
) {
5858
super();
5959

src/vs/workbench/contrib/accountEntitlements/browser/accountsEntitlements.contribution.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,16 @@ class EntitlementsContribution extends Disposable implements IWorkbenchContribut
5151
private accountsMenuBadgeDisposable = this._register(new MutableDisposable());
5252

5353
constructor(
54-
@IContextKeyService readonly contextService: IContextKeyService,
55-
@ICommandService readonly commandService: ICommandService,
56-
@ITelemetryService readonly telemetryService: ITelemetryService,
57-
@IAuthenticationService readonly authenticationService: IAuthenticationService,
58-
@IProductService readonly productService: IProductService,
59-
@IStorageService readonly storageService: IStorageService,
60-
@IExtensionManagementService readonly extensionManagementService: IExtensionManagementService,
61-
@IActivityService readonly activityService: IActivityService,
62-
@IExtensionService readonly extensionService: IExtensionService,
63-
@IConfigurationService readonly configurationService: IConfigurationService,
64-
@IRequestService readonly requestService: IRequestService) {
54+
@IContextKeyService private readonly contextService: IContextKeyService,
55+
@ITelemetryService private readonly telemetryService: ITelemetryService,
56+
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
57+
@IProductService private readonly productService: IProductService,
58+
@IStorageService private readonly storageService: IStorageService,
59+
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
60+
@IActivityService private readonly activityService: IActivityService,
61+
@IExtensionService private readonly extensionService: IExtensionService,
62+
@IConfigurationService private readonly configurationService: IConfigurationService,
63+
@IRequestService private readonly requestService: IRequestService) {
6564
super();
6665

6766
if (!this.productService.gitHubEntitlement || isWeb) {

src/vs/workbench/contrib/chat/browser/chatOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ChatEditorOptions extends Disposable {
7979
private readonly resultEditorBackgroundColor: string,
8080
@IConfigurationService private readonly configurationService: IConfigurationService,
8181
@IThemeService private readonly themeService: IThemeService,
82-
@IViewDescriptorService readonly viewDescriptorService: IViewDescriptorService
82+
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService
8383
) {
8484
super();
8585

src/vs/workbench/contrib/chat/common/chatViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export class ChatRequestViewModel implements IChatRequestViewModel {
348348
currentRenderedHeight: number | undefined;
349349

350350
constructor(
351-
readonly _model: IChatRequestModel,
351+
private readonly _model: IChatRequestModel,
352352
) { }
353353
}
354354

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
303303
@INotebookExecutionService private readonly notebookExecutionService: INotebookExecutionService,
304304
@INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService,
305305
@IEditorProgressService private editorProgressService: IEditorProgressService,
306-
@INotebookLoggingService readonly logService: INotebookLoggingService,
307-
@IKeybindingService readonly keybindingService: IKeybindingService,
306+
@INotebookLoggingService private readonly logService: INotebookLoggingService,
307+
@IKeybindingService private readonly keybindingService: IKeybindingService,
308308
@ICodeEditorService codeEditorService: ICodeEditorService
309309
) {
310310
super();

src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
3737
private readonly _borrowableEditors = new Map<number, ResourceMap<{ widget: NotebookEditorWidget; token: number | undefined }>>();
3838

3939
constructor(
40-
@IEditorGroupsService readonly editorGroupService: IEditorGroupsService,
40+
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
4141
@IEditorService editorService: IEditorService,
4242
@IContextKeyService contextKeyService: IContextKeyService
4343
) {

src/vs/workbench/contrib/remote/browser/remoteExplorer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ export class AutomaticPortForwarding extends Disposable implements IWorkbenchCon
185185
@IOpenerService private readonly openerService: IOpenerService,
186186
@IExternalUriOpenerService private readonly externalOpenerService: IExternalUriOpenerService,
187187
@IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService,
188-
@IWorkbenchEnvironmentService readonly environmentService: IWorkbenchEnvironmentService,
188+
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
189189
@IContextKeyService private readonly contextKeyService: IContextKeyService,
190190
@IWorkbenchConfigurationService private readonly configurationService: IWorkbenchConfigurationService,
191191
@IDebugService private readonly debugService: IDebugService,
192-
@IRemoteAgentService readonly remoteAgentService: IRemoteAgentService,
192+
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
193193
@ITunnelService private readonly tunnelService: ITunnelService,
194194
@IHostService private readonly hostService: IHostService,
195195
@ILogService private readonly logService: ILogService,

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,12 @@ class HistoryItemGroupRenderer implements ICompressibleTreeRenderer<SCMHistoryIt
799799

800800
constructor(
801801
readonly actionRunner: ActionRunner,
802-
@IContextKeyService readonly contextKeyService: IContextKeyService,
803-
@IContextMenuService readonly contextMenuService: IContextMenuService,
804-
@IKeybindingService readonly keybindingService: IKeybindingService,
805-
@IMenuService readonly menuService: IMenuService,
802+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
803+
@IContextMenuService private readonly contextMenuService: IContextMenuService,
804+
@IKeybindingService private readonly keybindingService: IKeybindingService,
805+
@IMenuService private readonly menuService: IMenuService,
806806
@ISCMViewService private readonly scmViewService: ISCMViewService,
807-
@ITelemetryService readonly telemetryService: ITelemetryService
807+
@ITelemetryService private readonly telemetryService: ITelemetryService
808808
) { }
809809

810810
renderTemplate(container: HTMLElement) {
@@ -1115,11 +1115,11 @@ class SeparatorRenderer implements ICompressibleTreeRenderer<SCMViewSeparatorEle
11151115
get templateId(): string { return SeparatorRenderer.TEMPLATE_ID; }
11161116

11171117
constructor(
1118-
@IContextKeyService readonly contextKeyService: IContextKeyService,
1119-
@IContextMenuService readonly contextMenuService: IContextMenuService,
1120-
@IKeybindingService readonly keybindingService: IKeybindingService,
1121-
@IMenuService readonly menuService: IMenuService,
1122-
@ITelemetryService readonly telemetryService: ITelemetryService
1118+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
1119+
@IContextMenuService private readonly contextMenuService: IContextMenuService,
1120+
@IKeybindingService private readonly keybindingService: IKeybindingService,
1121+
@IMenuService private readonly menuService: IMenuService,
1122+
@ITelemetryService private readonly telemetryService: ITelemetryService
11231123
) { }
11241124

11251125
renderTemplate(container: HTMLElement): SeparatorTemplate {

0 commit comments

Comments
 (0)