Skip to content

Commit ecee17c

Browse files
committed
Remove @ts-expect-error and add comments
1 parent eb44ba7 commit ecee17c

File tree

6 files changed

+25
-28
lines changed

6 files changed

+25
-28
lines changed

lib/rules/jsx-closing-bracket-location.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ module.exports = {
196196
*/
197197
function getTokensLocations(node) {
198198
const sourceCode = context.getSourceCode();
199+
// The types differ between ASTNode and ESTree.Node.
199200
// @ts-expect-error
200201
const opening = sourceCode.getFirstToken(node).loc.start;
202+
// The types differ between ASTNode and ESTree.Node.
201203
// @ts-expect-error
202204
const closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
203205
const tag = sourceCode.getFirstToken(node.name).loc.start;

lib/rules/jsx-equals-spacing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ module.exports = {
6262

6363
const sourceCode = context.getSourceCode();
6464
const equalToken = sourceCode.getTokenAfter(attrNode.name);
65-
// @ts-expect-error
65+
if (equalToken.type !== 'Punctuator') {
66+
return;
67+
}
6668
const spacedBefore = sourceCode.isSpaceBetweenTokens(attrNode.name, equalToken);
67-
// @ts-expect-error
6869
const spacedAfter = sourceCode.isSpaceBetweenTokens(equalToken, attrNode.value);
6970

7071
if (config === 'never') {

lib/rules/jsx-indent-props.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ module.exports = {
141141
* @return {Number} Indent
142142
*/
143143
function getNodeIndent(node) {
144+
// The types differ between ASTNode and ESTree.Node.
144145
// @ts-expect-error
145146
let src = context.getSourceCode().getText(node, node.loc.start.column + extraColumnStart);
146147
const lines = src.split('\n');

lib/rules/no-access-state-in-setstate.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ module.exports = {
107107
&& node.object.type === 'ThisExpression'
108108
&& isClassComponent()
109109
) {
110+
/** @type {import("eslint").Rule.Node} */
110111
let current = node;
111-
// @ts-expect-error
112112
while (current.type !== 'Program') {
113113
// Reporting if this.state is directly within this.setState
114114
if (isFirstArgumentInSetStateCall(current, node)) {
@@ -119,56 +119,51 @@ module.exports = {
119119
}
120120

121121
// Storing all functions and methods that contains this.state
122-
// @ts-expect-error
123-
if (current.type === 'MethodDefinition') {
122+
if (current.type === 'MethodDefinition' && current.key.type === 'Identifier') {
124123
methods.push({
125-
// @ts-expect-error
126124
methodName: current.key.name,
127125
node,
128126
});
129127
break;
130-
// @ts-expect-error
131-
} else if (current.type === 'FunctionExpression' && current.parent.key) {
128+
} else if (
129+
current.type === 'FunctionExpression'
130+
&& (current.parent.type === 'Property' || current.parent.type === 'MethodDefinition')
131+
&& current.parent.key.type === 'Identifier'
132+
&& current.parent.key
133+
) {
132134
methods.push({
133-
// @ts-expect-error
134135
methodName: current.parent.key.name,
135136
node,
136137
});
137138
break;
138139
}
139140

140141
// Storing all variables containing this.state
141-
// @ts-expect-error
142-
if (current.type === 'VariableDeclarator') {
142+
if (current.type === 'VariableDeclarator' && current.id.type === 'Identifier') {
143143
vars.push({
144144
node,
145145
scope: context.getScope(),
146-
// @ts-expect-error
147146
variableName: current.id.name,
148147
});
149148
break;
150149
}
151150

152-
// @ts-expect-error
153151
current = current.parent;
154152
}
155153
}
156154
},
157155

158156
Identifier(node) {
159157
// Checks if the identifier is a variable within an object
158+
/** @type {import("eslint").Rule.Node} */
160159
let current = node;
161160
while (current.parent.type === 'BinaryExpression') {
162-
// @ts-expect-error
163161
current = current.parent;
164162
}
165163
if (
166-
// @ts-expect-error
167-
current.parent.value === current
168-
// @ts-expect-error
169-
|| current.parent.object === current
164+
(current.parent.type === 'Property' && current.parent.value === current)
165+
|| (current.parent.type === 'MemberExpression' && current.parent.object === current)
170166
) {
171-
// @ts-expect-error
172167
while (current.type !== 'Program') {
173168
if (isFirstArgumentInSetStateCall(current, node)) {
174169
vars
@@ -179,7 +174,6 @@ module.exports = {
179174
});
180175
});
181176
}
182-
// @ts-expect-error
183177
current = current.parent;
184178
}
185179
}

lib/rules/no-danger-with-children.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ module.exports = {
129129
let props = node.arguments[1];
130130

131131
if (props.type === 'Identifier') {
132-
// @ts-expect-error
133-
const variable = variableUtil.variablesInScope(context).find((item) => item.name === props.name);
132+
const name = props.name;
133+
const variable = variableUtil.variablesInScope(context).find((item) => item.name === name);
134134
if (variable && variable.defs.length && variable.defs[0].node.init) {
135135
props = variable.defs[0].node.init;
136136
}

lib/rules/no-deprecated.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,13 @@ module.exports = {
236236

237237
VariableDeclarator(node) {
238238
const reactModuleName = getReactModuleName(node);
239-
// @ts-expect-error
240-
const isRequire = node.init && node.init.callee && node.init.callee.name === 'require';
241-
const isReactRequire = node.init
242-
// @ts-expect-error
239+
const isRequire = node.init.type === 'CallExpression'
240+
&& node.init.callee && node.init.callee.type === 'Identifier'
241+
&& node.init.callee.name === 'require';
242+
const isReactRequire = node.init.type === 'CallExpression'
243243
&& node.init.arguments
244-
// @ts-expect-error
245244
&& node.init.arguments.length
246-
// @ts-expect-error
245+
&& node.init.arguments[0].type === 'Literal'
247246
&& typeof MODULES[node.init.arguments[0].value] !== 'undefined';
248247
const isDestructuring = node.id && node.id.type === 'ObjectPattern';
249248

0 commit comments

Comments
 (0)