Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix injected services becoming public by mistake #209513

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as eslint from 'eslint';
import { TSESTree } from '@typescript-eslint/experimental-utils';

/**
* Enforces that all parameter properties have an explicit access modifier (public, protected, private).
*
* This catches a common bug where a service is accidentally made public by simply writing: `readonly prop: Foo`
*/
export = new class implements eslint.Rule.RuleModule {

create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
function check(inNode: any) {
const node: TSESTree.TSParameterProperty = inNode;

// For now, only apply to injected services
const firstDecorator = node.decorators?.at(0);
if (
firstDecorator?.expression.type !== 'Identifier'
|| !firstDecorator.expression.name.endsWith('Service')
) {
return;
}

if (!node.accessibility) {
context.report({
node: inNode,
message: 'Parameter properties must have an explicit access modifier.'
});
}
}

return {
['TSParameterProperty']: check,
};
}
};
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
],
"local/code-translation-remind": "warn",
"local/code-no-native-private": "warn",
"local/code-parameter-properties-must-have-explicit-accessibility": "warn",
"local/code-no-nls-in-standalone-editor": "warn",
"local/code-no-standalone-editor": "warn",
"local/code-no-unexternalized-strings": "warn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class StickyModelProvider extends Disposable implements IStickyModelProvi
constructor(
private readonly _editor: IActiveCodeEditor,
onProviderUpdate: () => void,
@IInstantiationService readonly _languageConfigurationService: ILanguageConfigurationService,
@ILanguageFeaturesService readonly _languageFeaturesService: ILanguageFeaturesService,
@IInstantiationService _languageConfigurationService: ILanguageConfigurationService,
@ILanguageFeaturesService _languageFeaturesService: ILanguageFeaturesService,
) {
super();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ class EntitlementsContribution extends Disposable implements IWorkbenchContribut
private accountsMenuBadgeDisposable = this._register(new MutableDisposable());

constructor(
@IContextKeyService readonly contextService: IContextKeyService,
@ICommandService readonly commandService: ICommandService,
@ITelemetryService readonly telemetryService: ITelemetryService,
@IAuthenticationService readonly authenticationService: IAuthenticationService,
@IProductService readonly productService: IProductService,
@IStorageService readonly storageService: IStorageService,
@IExtensionManagementService readonly extensionManagementService: IExtensionManagementService,
@IActivityService readonly activityService: IActivityService,
@IExtensionService readonly extensionService: IExtensionService,
@IConfigurationService readonly configurationService: IConfigurationService,
@IRequestService readonly requestService: IRequestService) {
@IContextKeyService private readonly contextService: IContextKeyService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
@IProductService private readonly productService: IProductService,
@IStorageService private readonly storageService: IStorageService,
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IActivityService private readonly activityService: IActivityService,
@IExtensionService private readonly extensionService: IExtensionService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IRequestService private readonly requestService: IRequestService) {
super();

if (!this.productService.gitHubEntitlement || isWeb) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/browser/chatOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ChatEditorOptions extends Disposable {
private readonly resultEditorBackgroundColor: string,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IThemeService private readonly themeService: IThemeService,
@IViewDescriptorService readonly viewDescriptorService: IViewDescriptorService
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService
) {
super();

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/common/chatViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class ChatRequestViewModel implements IChatRequestViewModel {
currentRenderedHeight: number | undefined;

constructor(
readonly _model: IChatRequestModel,
private readonly _model: IChatRequestModel,
) { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
@INotebookExecutionService private readonly notebookExecutionService: INotebookExecutionService,
@INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService,
@IEditorProgressService private editorProgressService: IEditorProgressService,
@INotebookLoggingService readonly logService: INotebookLoggingService,
@IKeybindingService readonly keybindingService: IKeybindingService,
@INotebookLoggingService private readonly logService: INotebookLoggingService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@ICodeEditorService codeEditorService: ICodeEditorService
) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
private readonly _borrowableEditors = new Map<number, ResourceMap<{ widget: NotebookEditorWidget; token: number | undefined }>>();

constructor(
@IEditorGroupsService readonly editorGroupService: IEditorGroupsService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IEditorService editorService: IEditorService,
@IContextKeyService contextKeyService: IContextKeyService
) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/remote/browser/remoteExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ export class AutomaticPortForwarding extends Disposable implements IWorkbenchCon
@IOpenerService private readonly openerService: IOpenerService,
@IExternalUriOpenerService private readonly externalOpenerService: IExternalUriOpenerService,
@IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService,
@IWorkbenchEnvironmentService readonly environmentService: IWorkbenchEnvironmentService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IWorkbenchConfigurationService private readonly configurationService: IWorkbenchConfigurationService,
@IDebugService private readonly debugService: IDebugService,
@IRemoteAgentService readonly remoteAgentService: IRemoteAgentService,
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
@ITunnelService private readonly tunnelService: ITunnelService,
@IHostService private readonly hostService: IHostService,
@ILogService private readonly logService: ILogService,
Expand Down
20 changes: 10 additions & 10 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,12 @@ class HistoryItemGroupRenderer implements ICompressibleTreeRenderer<SCMHistoryIt

constructor(
readonly actionRunner: ActionRunner,
@IContextKeyService readonly contextKeyService: IContextKeyService,
@IContextMenuService readonly contextMenuService: IContextMenuService,
@IKeybindingService readonly keybindingService: IKeybindingService,
@IMenuService readonly menuService: IMenuService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IMenuService private readonly menuService: IMenuService,
@ISCMViewService private readonly scmViewService: ISCMViewService,
@ITelemetryService readonly telemetryService: ITelemetryService
@ITelemetryService private readonly telemetryService: ITelemetryService
) { }

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

constructor(
@IContextKeyService readonly contextKeyService: IContextKeyService,
@IContextMenuService readonly contextMenuService: IContextMenuService,
@IKeybindingService readonly keybindingService: IKeybindingService,
@IMenuService readonly menuService: IMenuService,
@ITelemetryService readonly telemetryService: ITelemetryService
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IMenuService private readonly menuService: IMenuService,
@ITelemetryService private readonly telemetryService: ITelemetryService
) { }

renderTemplate(container: HTMLElement): SeparatorTemplate {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export class FileMatch extends Disposable implements IFileMatch {
private readonly searchInstanceID: string,
@IModelService private readonly modelService: IModelService,
@IReplaceService private readonly replaceService: IReplaceService,
@ILabelService readonly labelService: ILabelService,
@ILabelService labelService: ILabelService,
@INotebookEditorService private readonly notebookEditorService: INotebookEditorService,
) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export class TerminalInstanceService extends Disposable implements ITerminalInst
constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IWorkbenchEnvironmentService readonly _environmentService: IWorkbenchEnvironmentService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
) {
super();
this._terminalShellTypeContextKey = TerminalContextKeys.shellType.bindTo(this._contextKeyService);
this._terminalInRunCommandPicker = TerminalContextKeys.inTerminalRunCommandPicker.bindTo(this._contextKeyService);

for (const remoteAuthority of [undefined, _environmentService.remoteAuthority]) {
for (const remoteAuthority of [undefined, environmentService.remoteAuthority]) {
const { promise, resolve } = promiseWithResolvers<void>();
this._backendRegistration.set(remoteAuthority, { promise, resolve });
}
Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/contrib/terminal/browser/terminalVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export class TerminalVoiceSession extends Disposable {
private readonly _disposables: DisposableStore;
constructor(
@ISpeechService private readonly _speechService: ISpeechService,
@ITerminalService readonly _terminalService: ITerminalService,
@IConfigurationService readonly configurationService: IConfigurationService,
@IInstantiationService readonly _instantationService: IInstantiationService
@ITerminalService private readonly _terminalService: ITerminalService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
super();
this._register(this._terminalService.onDidChangeActiveInstance(() => this.stop()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class WelcomeDialogContribution extends Disposable implements IWorkbenchContribu
@IStorageService storageService: IStorageService,
@IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService,
@IConfigurationService configurationService: IConfigurationService,
@IContextKeyService readonly contextService: IContextKeyService,
@ICodeEditorService readonly codeEditorService: ICodeEditorService,
@IInstantiationService readonly instantiationService: IInstantiationService,
@ICommandService readonly commandService: ICommandService,
@ITelemetryService readonly telemetryService: ITelemetryService,
@IOpenerService readonly openerService: IOpenerService,
@IEditorService readonly editorService: IEditorService
@IContextKeyService contextService: IContextKeyService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@IInstantiationService instantiationService: IInstantiationService,
@ICommandService commandService: ICommandService,
@ITelemetryService telemetryService: ITelemetryService,
@IOpenerService openerService: IOpenerService,
@IEditorService editorService: IEditorService
) {
super();

Expand Down
Loading