@typescript-eslint/eslint-plugin 8.52.1-alpha.1 → 8.52.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- export type MessageIds = 'unsafeCall' | 'unsafeCallThis' | 'unsafeNew' | 'unsafeTemplateTag';
1
+ export type MessageIds = 'errorCall' | 'errorCallThis' | 'errorNew' | 'errorTemplateTag' | 'unsafeCall' | 'unsafeCallThis' | 'unsafeNew' | 'unsafeTemplateTag';
2
2
  declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
3
3
  name: string;
4
4
  };
@@ -45,13 +45,17 @@ exports.default = (0, util_1.createRule)({
45
45
  requiresTypeChecking: true,
46
46
  },
47
47
  messages: {
48
- unsafeCall: 'Unsafe call of a(n) {{type}} typed value.',
48
+ errorCall: 'Unsafe call of a type that could not be resolved.',
49
+ errorCallThis: 'Unsafe call of a `this` type that could not be resolved.',
50
+ errorNew: 'Unsafe construction of a type that could not be resolved.',
51
+ errorTemplateTag: 'Unsafe use of a template tag whose type could not be resolved.',
52
+ unsafeCall: 'Unsafe call of {{type}} typed value.',
49
53
  unsafeCallThis: [
50
- 'Unsafe call of a(n) {{type}} typed value. `this` is typed as {{type}}.',
54
+ 'Unsafe call of {{type}} typed value. `this` is typed as {{type}}.',
51
55
  'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.',
52
56
  ].join('\n'),
53
- unsafeNew: 'Unsafe construction of a(n) {{type}} typed value.',
54
- unsafeTemplateTag: 'Unsafe use of a(n) {{type}} typed template tag.',
57
+ unsafeNew: 'Unsafe construction of {{type}} typed value.',
58
+ unsafeTemplateTag: 'Unsafe use of {{type}} typed template tag.',
55
59
  },
56
60
  schema: [],
57
61
  },
@@ -60,7 +64,7 @@ exports.default = (0, util_1.createRule)({
60
64
  const services = (0, util_1.getParserServices)(context);
61
65
  const compilerOptions = services.program.getCompilerOptions();
62
66
  const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'noImplicitThis');
63
- function checkCall(node, reportingNode, messageId) {
67
+ function checkCall(node, reportingNode, unsafeMessageId, errorMessageId) {
64
68
  const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
65
69
  if ((0, util_1.isTypeAnyType)(type)) {
66
70
  if (!isNoImplicitThis) {
@@ -68,15 +72,16 @@ exports.default = (0, util_1.createRule)({
68
72
  const thisExpression = (0, util_1.getThisExpression)(node);
69
73
  if (thisExpression &&
70
74
  (0, util_1.isTypeAnyType)((0, util_1.getConstrainedTypeAtLocation)(services, thisExpression))) {
71
- messageId = 'unsafeCallThis';
75
+ unsafeMessageId = 'unsafeCallThis';
76
+ errorMessageId = 'errorCallThis';
72
77
  }
73
78
  }
74
79
  const isErrorType = tsutils.isIntrinsicErrorType(type);
75
80
  context.report({
76
81
  node: reportingNode,
77
- messageId,
82
+ messageId: isErrorType ? errorMessageId : unsafeMessageId,
78
83
  data: {
79
- type: isErrorType ? '`error` type' : '`any`',
84
+ type: 'an `any`',
80
85
  },
81
86
  });
82
87
  return;
@@ -98,7 +103,7 @@ exports.default = (0, util_1.createRule)({
98
103
  return;
99
104
  }
100
105
  const callSignatures = type.getCallSignatures();
101
- if (messageId === 'unsafeNew') {
106
+ if (unsafeMessageId === 'unsafeNew') {
102
107
  if (callSignatures.some(signature => !tsutils.isIntrinsicVoidType(signature.getReturnType()))) {
103
108
  return;
104
109
  }
@@ -108,9 +113,9 @@ exports.default = (0, util_1.createRule)({
108
113
  }
109
114
  context.report({
110
115
  node: reportingNode,
111
- messageId,
116
+ messageId: unsafeMessageId,
112
117
  data: {
113
- type: '`Function`',
118
+ type: 'a `Function`',
114
119
  },
115
120
  });
116
121
  return;
@@ -118,13 +123,13 @@ exports.default = (0, util_1.createRule)({
118
123
  }
119
124
  return {
120
125
  'CallExpression > *.callee'(node) {
121
- checkCall(node, node, 'unsafeCall');
126
+ checkCall(node, node, 'unsafeCall', 'errorCall');
122
127
  },
123
128
  NewExpression(node) {
124
- checkCall(node.callee, node, 'unsafeNew');
129
+ checkCall(node.callee, node, 'unsafeNew', 'errorNew');
125
130
  },
126
131
  'TaggedTemplateExpression > *.tag'(node) {
127
- checkCall(node, node, 'unsafeTemplateTag');
132
+ checkCall(node, node, 'unsafeTemplateTag', 'errorTemplateTag');
128
133
  },
129
134
  };
130
135
  },
@@ -3,7 +3,7 @@ export type Options = [
3
3
  allowOptionalChaining?: boolean;
4
4
  }
5
5
  ];
6
- export type MessageIds = 'unsafeComputedMemberAccess' | 'unsafeMemberExpression' | 'unsafeThisMemberExpression';
6
+ export type MessageIds = 'errorComputedMemberAccess' | 'errorMemberExpression' | 'errorThisMemberExpression' | 'unsafeComputedMemberAccess' | 'unsafeMemberExpression' | 'unsafeThisMemberExpression';
7
7
  declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
8
8
  name: string;
9
9
  };
@@ -42,10 +42,6 @@ var State;
42
42
  State[State["Safe"] = 2] = "Safe";
43
43
  State[State["Chained"] = 3] = "Chained";
44
44
  })(State || (State = {}));
45
- function createDataType(type) {
46
- const isErrorType = tsutils.isIntrinsicErrorType(type);
47
- return isErrorType ? '`error` typed' : '`any`';
48
- }
49
45
  exports.default = (0, util_1.createRule)({
50
46
  name: 'no-unsafe-member-access',
51
47
  meta: {
@@ -56,8 +52,14 @@ exports.default = (0, util_1.createRule)({
56
52
  requiresTypeChecking: true,
57
53
  },
58
54
  messages: {
59
- unsafeComputedMemberAccess: 'Computed name {{property}} resolves to an {{type}} value.',
60
- unsafeMemberExpression: 'Unsafe member access {{property}} on an {{type}} value.',
55
+ errorComputedMemberAccess: 'The type of computed name {{property}} cannot be resolved.',
56
+ errorMemberExpression: 'Unsafe member access {{property}} on a type that cannot be resolved.',
57
+ errorThisMemberExpression: [
58
+ 'Unsafe member access {{property}}. The type of `this` cannot be resolved.',
59
+ 'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.',
60
+ ].join('\n'),
61
+ unsafeComputedMemberAccess: 'Computed name {{property}} resolves to an `any` value.',
62
+ unsafeMemberExpression: 'Unsafe member access {{property}} on an `any` value.',
61
63
  unsafeThisMemberExpression: [
62
64
  'Unsafe member access {{property}} on an `any` value. `this` is typed as `any`.',
63
65
  'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.',
@@ -116,20 +118,28 @@ exports.default = (0, util_1.createRule)({
116
118
  stateCache.set(node, state);
117
119
  if (state === State.Unsafe) {
118
120
  const propertyName = context.sourceCode.getText(node.property);
119
- let messageId = 'unsafeMemberExpression';
121
+ let messageId;
120
122
  if (!isNoImplicitThis) {
121
123
  // `this.foo` or `this.foo[bar]`
122
124
  const thisExpression = (0, util_1.getThisExpression)(node);
123
- if (thisExpression &&
124
- (0, util_1.isTypeAnyType)((0, util_1.getConstrainedTypeAtLocation)(services, thisExpression))) {
125
- messageId = 'unsafeThisMemberExpression';
125
+ if (thisExpression) {
126
+ const thisType = (0, util_1.getConstrainedTypeAtLocation)(services, thisExpression);
127
+ if ((0, util_1.isTypeAnyType)(thisType)) {
128
+ messageId = tsutils.isIntrinsicErrorType(thisType)
129
+ ? 'errorThisMemberExpression'
130
+ : 'unsafeThisMemberExpression';
131
+ }
126
132
  }
127
133
  }
134
+ if (!messageId) {
135
+ messageId = tsutils.isIntrinsicErrorType(type)
136
+ ? 'errorMemberExpression'
137
+ : 'unsafeMemberExpression';
138
+ }
128
139
  context.report({
129
140
  node: node.property,
130
141
  messageId,
131
142
  data: {
132
- type: createDataType(type),
133
143
  property: node.computed ? `[${propertyName}]` : `.${propertyName}`,
134
144
  },
135
145
  });
@@ -159,9 +169,10 @@ exports.default = (0, util_1.createRule)({
159
169
  const propertyName = context.sourceCode.getText(node);
160
170
  context.report({
161
171
  node,
162
- messageId: 'unsafeComputedMemberAccess',
172
+ messageId: tsutils.isIntrinsicErrorType(type)
173
+ ? 'errorComputedMemberAccess'
174
+ : 'unsafeComputedMemberAccess',
163
175
  data: {
164
- type: createDataType(type),
165
176
  property: `[${propertyName}]`,
166
177
  },
167
178
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.52.1-alpha.1",
3
+ "version": "8.52.1-alpha.10",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -59,10 +59,10 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@eslint-community/regexpp": "^4.12.2",
62
- "@typescript-eslint/scope-manager": "8.52.1-alpha.1",
63
- "@typescript-eslint/type-utils": "8.52.1-alpha.1",
64
- "@typescript-eslint/utils": "8.52.1-alpha.1",
65
- "@typescript-eslint/visitor-keys": "8.52.1-alpha.1",
62
+ "@typescript-eslint/scope-manager": "8.52.1-alpha.10",
63
+ "@typescript-eslint/type-utils": "8.52.1-alpha.10",
64
+ "@typescript-eslint/utils": "8.52.1-alpha.10",
65
+ "@typescript-eslint/visitor-keys": "8.52.1-alpha.10",
66
66
  "ignore": "^7.0.5",
67
67
  "natural-compare": "^1.4.0",
68
68
  "ts-api-utils": "^2.4.0"
@@ -70,8 +70,8 @@
70
70
  "devDependencies": {
71
71
  "@types/mdast": "^4.0.4",
72
72
  "@types/natural-compare": "*",
73
- "@typescript-eslint/rule-schema-to-typescript-types": "8.52.1-alpha.1",
74
- "@typescript-eslint/rule-tester": "8.52.1-alpha.1",
73
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.52.1-alpha.10",
74
+ "@typescript-eslint/rule-tester": "8.52.1-alpha.10",
75
75
  "@vitest/coverage-v8": "^3.2.4",
76
76
  "ajv": "^6.12.6",
77
77
  "eslint": "*",
@@ -90,7 +90,7 @@
90
90
  "vitest": "^3.2.4"
91
91
  },
92
92
  "peerDependencies": {
93
- "@typescript-eslint/parser": "^8.52.1-alpha.1",
93
+ "@typescript-eslint/parser": "^8.52.1-alpha.10",
94
94
  "eslint": "^8.57.0 || ^9.0.0",
95
95
  "typescript": ">=4.8.4 <6.0.0"
96
96
  },