Skip to content

Commit 654c61d

Browse files
authored
add lint-rule to discourage native private fields (microsoft#186735)
1 parent 072d222 commit 654c61d

22 files changed

+74
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
8+
export = new class ApiProviderNaming implements eslint.Rule.RuleModule {
9+
10+
readonly meta: eslint.Rule.RuleMetaData = {
11+
messages: {
12+
slow: 'Native private fields are much slower and should only be used when needed. Ignore this warning if you know what you are doing, use compile-time private otherwise. See https://github.com/microsoft/vscode/issues/185991#issuecomment-1614468158 for details',
13+
}
14+
};
15+
16+
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
17+
18+
return {
19+
['PropertyDefinition PrivateIdentifier']: (node: any) => {
20+
context.report({
21+
node,
22+
messageId: 'slow'
23+
});
24+
},
25+
['MethodDefinition PrivateIdentifier']: (node: any) => {
26+
context.report({
27+
node,
28+
messageId: 'slow'
29+
});
30+
}
31+
};
32+
}
33+
};

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
}
7070
],
7171
"local/code-translation-remind": "warn",
72+
"local/code-no-native-private": "warn",
7273
"local/code-no-nls-in-standalone-editor": "warn",
7374
"local/code-no-standalone-editor": "warn",
7475
"local/code-no-unexternalized-strings": "warn",

src/vs/editor/contrib/codeAction/browser/codeActionController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { getDomNodePagePosition } from 'vs/base/browser/dom';
79
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
810
import { IAction } from 'vs/base/common/actions';

src/vs/editor/contrib/codeAction/browser/codeActionModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { CancelablePromise, createCancelablePromise, TimeoutTimer } from 'vs/base/common/async';
79
import { isCancellationError } from 'vs/base/common/errors';
810
import { Emitter } from 'vs/base/common/event';

src/vs/workbench/api/common/extHostCommands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { validateConstraint } from 'vs/base/common/types';
79
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
810
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';

src/vs/workbench/api/common/extHostDiagnostics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { localize } from 'vs/nls';
79
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
810
import { URI, UriComponents } from 'vs/base/common/uri';

src/vs/workbench/api/common/extHostExtensionService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import * as nls from 'vs/nls';
79
import * as path from 'vs/base/common/path';
810
import * as performance from 'vs/base/common/performance';

src/vs/workbench/api/common/extHostSCM.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { URI, UriComponents } from 'vs/base/common/uri';
79
import { Event, Emitter } from 'vs/base/common/event';
810
import { debounce } from 'vs/base/common/decorators';

src/vs/workbench/api/common/extHostSecrets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import type * as vscode from 'vscode';
79

810
import { ExtHostSecretState } from 'vs/workbench/api/common/extHostSecretState';

src/vs/workbench/api/common/extHostStatusBar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/* eslint-disable local/code-no-native-private */
7+
68
import { StatusBarAlignment as ExtHostStatusBarAlignment, Disposable, ThemeColor, asStatusBarItemIdentifier } from './extHostTypes';
79
import type * as vscode from 'vscode';
810
import { MainContext, MainThreadStatusBarShape, IMainContext, ICommandDto, ExtHostStatusBarShape, StatusBarItemDto } from './extHost.protocol';

0 commit comments

Comments
 (0)