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

feat(typescript-estree): typeof private identifiers #4832

Closed
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -105,10 +105,10 @@
"tmp": "^0.2.1",
"ts-node": "^10.4.0",
"tslint": "^6.1.3",
"typescript": ">=3.3.1 <4.7.0"
"typescript": ">=3.3.1 <4.6.0 || 4.7.0-beta"
},
"resolutions": {
"@types/node": "^16.11.4",
"typescript": "4.6.2"
"typescript": "4.7.0-beta"
}
}
2 changes: 1 addition & 1 deletion packages/ast-spec/package.json
Expand Up @@ -29,7 +29,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -b tsconfig.build.json && api-extractor run --local",
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist && rimraf _ts3.4 && rimraf .rollup.cache && rimraf coverage",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
Expand Down
3 changes: 2 additions & 1 deletion packages/ast-spec/src/type/TSQualifiedName/spec.ts
@@ -1,10 +1,11 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { Identifier } from '../../expression/Identifier/spec';
import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec';
import type { EntityName } from '../../unions/EntityName';

export interface TSQualifiedName extends BaseNode {
type: AST_NODE_TYPES.TSQualifiedName;
left: EntityName;
right: Identifier;
right: Identifier | PrivateIdentifier;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NGL - I do hate this a little bit because the only place that this.#foo is valid is in a typeof. It just means that consumers will have to check the type of this even though they'll know it's not possible.

It's probably not worth going to the effort of creating a separate AST node just for private member expressions within a type query.

}
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/ban-types.ts
Expand Up @@ -185,7 +185,8 @@ export default util.createRule<Options, MessageIds>({
customMessage,
},
fix: fixWith
? (fixer): TSESLint.RuleFix => fixer.replaceText(typeNode, fixWith)
? (fixer: TSESLint.RuleFixer): TSESLint.RuleFix =>
fixer.replaceText(typeNode, fixWith)
: null,
});
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ export default createRule<Options, MessageIds>({
node,
messageId: 'preferRecord',
fix: safeFix
? (fixer): TSESLint.RuleFix => {
? (fixer: TSESLint.RuleFixer): TSESLint.RuleFix => {
const key = sourceCode.getText(keyType.typeAnnotation);
const value = sourceCode.getText(valueType.typeAnnotation);
const record = member.readonly
Expand Down
Expand Up @@ -12,7 +12,8 @@ type ParameterCapableTSNode =
| ts.TypeReferenceNode
| ts.ExpressionWithTypeArguments
| ts.JsxOpeningElement
| ts.JsxSelfClosingElement;
| ts.JsxSelfClosingElement
| ts.TypeQueryNode;

type MessageIds = 'unnecessaryTypeParameter';

Expand Down
12 changes: 7 additions & 5 deletions packages/eslint-plugin/src/util/getESLintCoreRule.ts
Expand Up @@ -42,16 +42,18 @@ type RuleId = keyof RuleMap;

export const getESLintCoreRule: <R extends RuleId>(ruleId: R) => RuleMap[R] =
isESLintV8
? <R extends RuleId>(ruleId: R): RuleMap[R] =>
ESLintUtils.nullThrows(
? function <R extends RuleId>(ruleId: R): RuleMap[R] {
return ESLintUtils.nullThrows(
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
require('eslint/use-at-your-own-risk').builtinRules.get(
ruleId,
) as RuleMap[R],
`ESLint's core rule '${ruleId}' not found.`,
)
: <R extends RuleId>(ruleId: R): RuleMap[R] =>
require(`eslint/lib/rules/${ruleId}`) as RuleMap[R];
);
}
: function <R extends RuleId>(ruleId: R): RuleMap[R] {
return require(`eslint/lib/rules/${ruleId}`) as RuleMap[R];
};

export function maybeGetESLintCoreRule<R extends RuleId>(
ruleId: R,
Expand Down
4 changes: 4 additions & 0 deletions packages/scope-manager/src/lib/dom.iterable.ts
Expand Up @@ -18,6 +18,7 @@ export const dom_iterable = {
DOMStringList: TYPE,
DOMTokenList: TYPE,
DataTransferItemList: TYPE,
EventCounts: TYPE,
FileList: TYPE,
FontFaceSet: TYPE,
FormData: TYPE,
Expand All @@ -29,6 +30,9 @@ export const dom_iterable = {
Headers: TYPE,
IDBDatabase: TYPE,
IDBObjectStore: TYPE,
MIDIInputMap: TYPE,
MIDIOutput: TYPE,
MIDIOutputMap: TYPE,
MediaKeyStatusMap: TYPE,
MediaList: TYPE,
MessageEvent: TYPE,
Expand Down
48 changes: 44 additions & 4 deletions packages/scope-manager/src/lib/dom.ts
Expand Up @@ -127,6 +127,9 @@ export const dom = {
LockInfo: TYPE,
LockManagerSnapshot: TYPE,
LockOptions: TYPE,
MIDIConnectionEventInit: TYPE,
MIDIMessageEventInit: TYPE,
MIDIOptions: TYPE,
MediaCapabilitiesDecodingInfo: TYPE,
MediaCapabilitiesEncodingInfo: TYPE,
MediaCapabilitiesInfo: TYPE,
Expand Down Expand Up @@ -157,6 +160,7 @@ export const dom = {
MouseEventInit: TYPE,
MultiCacheQueryOptions: TYPE,
MutationObserverInit: TYPE,
NavigationPreloadState: TYPE,
NotificationAction: TYPE,
NotificationOptions: TYPE,
OfflineAudioCompletionEventInit: TYPE,
Expand Down Expand Up @@ -206,6 +210,10 @@ export const dom = {
RTCDataChannelEventInit: TYPE,
RTCDataChannelInit: TYPE,
RTCDtlsFingerprint: TYPE,
RTCEncodedAudioFrameMetadata: TYPE,
RTCEncodedVideoFrameMetadata: TYPE,
RTCErrorEventInit: TYPE,
RTCErrorInit: TYPE,
RTCIceCandidateInit: TYPE,
RTCIceCandidatePairStats: TYPE,
RTCIceServer: TYPE,
Expand Down Expand Up @@ -280,7 +288,9 @@ export const dom = {
ULongRange: TYPE,
UnderlyingSink: TYPE,
UnderlyingSource: TYPE,
VideoColorSpaceInit: TYPE,
VideoConfiguration: TYPE,
VideoFrameMetadata: TYPE,
WaveShaperOptions: TYPE,
WebGLContextAttributes: TYPE,
WebGLContextEventInit: TYPE,
Expand Down Expand Up @@ -449,6 +459,7 @@ export const dom = {
ElementInternals: TYPE_VALUE,
ErrorEvent: TYPE_VALUE,
Event: TYPE_VALUE,
EventCounts: TYPE_VALUE,
EventListener: TYPE,
EventListenerObject: TYPE,
EventSourceEventMap: TYPE,
Expand Down Expand Up @@ -504,7 +515,7 @@ export const dom = {
HTMLDataElement: TYPE_VALUE,
HTMLDataListElement: TYPE_VALUE,
HTMLDetailsElement: TYPE_VALUE,
HTMLDialogElement: TYPE,
HTMLDialogElement: TYPE_VALUE,
HTMLDirectoryElement: TYPE_VALUE,
HTMLDivElement: TYPE_VALUE,
HTMLDocument: TYPE_VALUE,
Expand Down Expand Up @@ -609,6 +620,17 @@ export const dom = {
Location: TYPE_VALUE,
Lock: TYPE_VALUE,
LockManager: TYPE_VALUE,
MIDIAccessEventMap: TYPE,
MIDIAccess: TYPE_VALUE,
MIDIConnectionEvent: TYPE_VALUE,
MIDIInputEventMap: TYPE,
MIDIInput: TYPE_VALUE,
MIDIInputMap: TYPE_VALUE,
MIDIMessageEvent: TYPE_VALUE,
MIDIOutput: TYPE_VALUE,
MIDIOutputMap: TYPE_VALUE,
MIDIPortEventMap: TYPE,
MIDIPort: TYPE_VALUE,
MathMLElementEventMap: TYPE,
MathMLElement: TYPE_VALUE,
MediaCapabilities: TYPE_VALUE,
Expand Down Expand Up @@ -653,13 +675,15 @@ export const dom = {
MutationObserver: TYPE_VALUE,
MutationRecord: TYPE_VALUE,
NamedNodeMap: TYPE_VALUE,
NavigationPreloadManager: TYPE_VALUE,
Navigator: TYPE_VALUE,
NavigatorAutomationInformation: TYPE,
NavigatorConcurrentHardware: TYPE,
NavigatorContentUtils: TYPE,
NavigatorCookies: TYPE,
NavigatorID: TYPE,
NavigatorLanguage: TYPE,
NavigatorLocks: TYPE,
NavigatorNetworkInformation: TYPE,
NavigatorOnLine: TYPE,
NavigatorPlugins: TYPE,
Expand Down Expand Up @@ -736,7 +760,12 @@ export const dom = {
RTCDataChannelEvent: TYPE_VALUE,
RTCDtlsTransportEventMap: TYPE,
RTCDtlsTransport: TYPE_VALUE,
RTCEncodedAudioFrame: TYPE_VALUE,
RTCEncodedVideoFrame: TYPE_VALUE,
RTCError: TYPE_VALUE,
RTCErrorEvent: TYPE_VALUE,
RTCIceCandidate: TYPE_VALUE,
RTCIceTransportEventMap: TYPE,
RTCIceTransport: TYPE_VALUE,
RTCPeerConnectionEventMap: TYPE,
RTCPeerConnection: TYPE_VALUE,
Expand All @@ -745,6 +774,8 @@ export const dom = {
RTCRtpReceiver: TYPE_VALUE,
RTCRtpSender: TYPE_VALUE,
RTCRtpTransceiver: TYPE_VALUE,
RTCSctpTransportEventMap: TYPE,
RTCSctpTransport: TYPE_VALUE,
RTCSessionDescription: TYPE_VALUE,
RTCStatsReport: TYPE_VALUE,
RTCTrackEvent: TYPE_VALUE,
Expand Down Expand Up @@ -934,14 +965,14 @@ export const dom = {
VTTCue: TYPE_VALUE,
VTTRegion: TYPE_VALUE,
ValidityState: TYPE_VALUE,
VideoColorSpace: TYPE_VALUE,
VideoPlaybackQuality: TYPE_VALUE,
VisualViewportEventMap: TYPE,
VisualViewport: TYPE_VALUE,
WEBGL_color_buffer_float: TYPE,
WEBGL_compressed_texture_astc: TYPE,
WEBGL_compressed_texture_etc: TYPE,
WEBGL_compressed_texture_etc1: TYPE,
WEBGL_compressed_texture_pvrtc: TYPE,
WEBGL_compressed_texture_s3tc: TYPE,
WEBGL_compressed_texture_s3tc_srgb: TYPE,
WEBGL_debug_renderer_info: TYPE,
Expand Down Expand Up @@ -1040,6 +1071,7 @@ export const dom = {
UnderlyingSourceCancelCallback: TYPE,
UnderlyingSourcePullCallback: TYPE,
UnderlyingSourceStartCallback: TYPE,
VideoFrameRequestCallback: TYPE,
VoidFunction: TYPE,
HTMLElementTagNameMap: TYPE,
HTMLElementDeprecatedTagNameMap: TYPE,
Expand All @@ -1055,7 +1087,6 @@ export const dom = {
CSSNumberish: TYPE,
CanvasImageSource: TYPE,
ClipboardItemData: TYPE,
ClipboardItemDataType: TYPE,
ClipboardItems: TYPE,
ConstrainBoolean: TYPE,
ConstrainDOMString: TYPE,
Expand Down Expand Up @@ -1170,6 +1201,9 @@ export const dom = {
KeyUsage: TYPE,
LineAlignSetting: TYPE,
LockMode: TYPE,
MIDIPortConnectionState: TYPE,
MIDIPortDeviceState: TYPE,
MIDIPortType: TYPE,
MediaDecodingType: TYPE,
MediaDeviceKind: TYPE,
MediaEncodingType: TYPE,
Expand All @@ -1181,7 +1215,7 @@ export const dom = {
MediaSessionAction: TYPE,
MediaSessionPlaybackState: TYPE,
MediaStreamTrackState: TYPE,
NavigationType: TYPE,
NavigationTimingType: TYPE,
NotificationDirection: TYPE,
NotificationPermission: TYPE,
OrientationLockType: TYPE,
Expand All @@ -1203,6 +1237,8 @@ export const dom = {
RTCDataChannelState: TYPE,
RTCDegradationPreference: TYPE,
RTCDtlsTransportState: TYPE,
RTCEncodedVideoFrameType: TYPE,
RTCErrorDetailType: TYPE,
RTCIceCandidateType: TYPE,
RTCIceComponent: TYPE,
RTCIceConnectionState: TYPE,
Expand All @@ -1217,6 +1253,7 @@ export const dom = {
RTCPriorityType: TYPE,
RTCRtcpMuxPolicy: TYPE,
RTCRtpTransceiverDirection: TYPE,
RTCSctpTransportState: TYPE,
RTCSdpType: TYPE,
RTCSignalingState: TYPE,
RTCStatsIceCandidatePairState: TYPE,
Expand Down Expand Up @@ -1250,7 +1287,10 @@ export const dom = {
TouchType: TYPE,
TransferFunction: TYPE,
UserVerificationRequirement: TYPE,
VideoColorPrimaries: TYPE,
VideoFacingModeEnum: TYPE,
VideoMatrixCoefficients: TYPE,
VideoTransferCharacteristics: TYPE,
WebGLPowerPreference: TYPE,
WorkerType: TYPE,
XMLHttpRequestResponseType: TYPE,
Expand Down
2 changes: 2 additions & 0 deletions packages/scope-manager/src/lib/es2020.bigint.ts
Expand Up @@ -4,9 +4,11 @@
// npx nx generate-lib @typescript-eslint/scope-manager

import { ImplicitLibVariableOptions } from '../variable';
import { es2020_intl } from './es2020.intl';
import { TYPE, TYPE_VALUE } from './base-config';

export const es2020_bigint = {
...es2020_intl,
BigIntToLocaleStringOptions: TYPE,
BigInt: TYPE_VALUE,
BigIntConstructor: TYPE,
Expand Down
13 changes: 13 additions & 0 deletions packages/scope-manager/src/lib/es2020.date.ts
@@ -0,0 +1,13 @@
// THIS CODE WAS AUTOMATICALLY GENERATED
// DO NOT EDIT THIS CODE BY HAND
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
// npx nx generate-lib @typescript-eslint/scope-manager

import { ImplicitLibVariableOptions } from '../variable';
import { es2020_intl } from './es2020.intl';
import { TYPE } from './base-config';

export const es2020_date = {
...es2020_intl,
Date: TYPE,
} as Record<string, ImplicitLibVariableOptions>;
13 changes: 13 additions & 0 deletions packages/scope-manager/src/lib/es2020.number.ts
@@ -0,0 +1,13 @@
// THIS CODE WAS AUTOMATICALLY GENERATED
// DO NOT EDIT THIS CODE BY HAND
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
// npx nx generate-lib @typescript-eslint/scope-manager

import { ImplicitLibVariableOptions } from '../variable';
import { es2020_intl } from './es2020.intl';
import { TYPE } from './base-config';

export const es2020_number = {
...es2020_intl,
Number: TYPE,
} as Record<string, ImplicitLibVariableOptions>;
4 changes: 4 additions & 0 deletions packages/scope-manager/src/lib/es2020.ts
Expand Up @@ -6,6 +6,8 @@
import { ImplicitLibVariableOptions } from '../variable';
import { es2019 } from './es2019';
import { es2020_bigint } from './es2020.bigint';
import { es2020_date } from './es2020.date';
import { es2020_number } from './es2020.number';
import { es2020_promise } from './es2020.promise';
import { es2020_sharedmemory } from './es2020.sharedmemory';
import { es2020_string } from './es2020.string';
Expand All @@ -15,6 +17,8 @@ import { es2020_intl } from './es2020.intl';
export const es2020 = {
...es2019,
...es2020_bigint,
...es2020_date,
...es2020_number,
...es2020_promise,
...es2020_sharedmemory,
...es2020_string,
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/lib/es2022.object.ts
Expand Up @@ -7,5 +7,5 @@ import { ImplicitLibVariableOptions } from '../variable';
import { TYPE } from './base-config';

export const es2022_object = {
Object: TYPE,
ObjectConstructor: TYPE,
} as Record<string, ImplicitLibVariableOptions>;
2 changes: 2 additions & 0 deletions packages/scope-manager/src/lib/esnext.bigint.ts
Expand Up @@ -4,9 +4,11 @@
// npx nx generate-lib @typescript-eslint/scope-manager

import { ImplicitLibVariableOptions } from '../variable';
import { es2020_intl } from './es2020.intl';
import { TYPE, TYPE_VALUE } from './base-config';

export const esnext_bigint = {
...es2020_intl,
BigIntToLocaleStringOptions: TYPE,
BigInt: TYPE_VALUE,
BigIntConstructor: TYPE,
Expand Down