Skip to content

Commit 25e6afd

Browse files
committed
Remove @ts-nocheck
1 parent ecee17c commit 25e6afd

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

lib/rules/forbid-foreign-prop-types.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/**
32
* @fileoverview Forbid using another component's propTypes
43
* @author Ian Christian Myers
@@ -110,8 +109,9 @@ module.exports = {
110109
&& !ast.isAssignmentLHS(node)
111110
&& !isAllowedAssignment(node)
112111
)) || (
113-
(node.property.type === 'Literal' || node.property.type === 'JSXText')
114-
&& node.property.value === 'propTypes'
112+
// The JSXText type is not present in the estree type definitions
113+
// @ts-expect-error
114+
(node.property.type === 'Literal' || node.property.type === 'JSXText') && node.property.value === 'propTypes'
115115
&& !ast.isAssignmentLHS(node)
116116
&& !isAllowedAssignment(node)
117117
)
@@ -123,7 +123,7 @@ module.exports = {
123123
},
124124

125125
ObjectPattern(node) {
126-
const propTypesNode = node.properties.find((property) => property.type === 'Property' && property.key.name === 'propTypes');
126+
const propTypesNode = node.properties.find((property) => property.type === 'Property' && property.key.type === 'Identifier' && property.key.name === 'propTypes');
127127

128128
if (propTypesNode) {
129129
report(context, messages.forbiddenPropType, 'forbiddenPropType', {

lib/rules/forbid-prop-types.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/**
32
* @fileoverview Forbid certain propTypes
43
*/
@@ -197,7 +196,7 @@ module.exports = {
197196
}
198197
if (node.specifiers.length >= 1) {
199198
const propTypesSpecifier = node.specifiers.find((specifier) => (
200-
specifier.imported && specifier.imported.name === 'PropTypes'
199+
specifier.type === 'ImportSpecifier' && specifier.imported && specifier.imported.name === 'PropTypes'
201200
));
202201
if (propTypesSpecifier) {
203202
propTypesPackageName = propTypesSpecifier.local.name;
@@ -232,13 +231,17 @@ module.exports = {
232231
) {
233232
return;
234233
}
234+
if (node.parent.type !== 'AssignmentExpression') {
235+
return;
236+
}
235237

236238
checkNode(node.parent.right);
237239
},
238240

239241
CallExpression(node) {
240242
if (
241-
node.callee.object
243+
node.callee.type === 'MemberExpression'
244+
&& node.callee.object
242245
&& !isPropTypesPackage(node.callee.object)
243246
&& !propsUtil.isPropTypesDeclaration(node.callee)
244247
) {
@@ -247,7 +250,8 @@ module.exports = {
247250

248251
if (
249252
node.arguments.length > 0
250-
&& (node.callee.name === 'shape' || astUtil.getPropertyName(node.callee) === 'shape')
253+
&& ((node.callee.type === 'Identifier' && node.callee.name === 'shape') || astUtil.getPropertyName(node.callee) === 'shape')
254+
&& node.arguments[0].type === 'ObjectExpression'
251255
) {
252256
checkProperties(node.arguments[0].properties);
253257
}
@@ -272,7 +276,7 @@ module.exports = {
272276

273277
ObjectExpression(node) {
274278
node.properties.forEach((property) => {
275-
if (!property.key) {
279+
if (property.type !== 'Property') {
276280
return;
277281
}
278282

lib/rules/jsx-curly-spacing.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/**
32
* @fileoverview Enforce or disallow spaces inside of curly braces in JSX attributes.
43
* @author Jamund Ferguson
@@ -12,6 +11,7 @@
1211

1312
'use strict';
1413

14+
// @ts-ignore
1515
const has = require('object.hasown/polyfill')();
1616
const docsUrl = require('../util/docsUrl');
1717
const report = require('../util/report');
@@ -373,7 +373,9 @@ module.exports = {
373373
}
374374

375375
const sourceCode = context.getSourceCode();
376+
// @ts-expect-error The types differ between ASTNode and ESTree.Node.
376377
const first = sourceCode.getFirstToken(node);
378+
// @ts-expect-error The types differ between ASTNode and ESTree.Node.
377379
const last = sourceCode.getLastToken(node);
378380
let second = sourceCode.getTokenAfter(first, { includeComments: true });
379381
let penultimate = sourceCode.getTokenBefore(last, { includeComments: true });
@@ -388,15 +390,21 @@ module.exports = {
388390
const trailingComments = sourceCode.getNodeByRangeIndex(penultimate.range[0]).trailingComments;
389391
penultimate = trailingComments ? trailingComments[trailingComments.length - 1] : penultimate;
390392
}
393+
if (first.type !== 'Punctuator' || last.type !== 'Punctuator') {
394+
return;
395+
}
391396

392397
const isObjectLiteral = first.value === second.value;
393398
const spacing = isObjectLiteral ? config.objectLiteralSpaces : config.when;
394399
if (spacing === SPACING.always) {
400+
// @ts-expect-error second has a Comment type.
395401
if (!sourceCode.isSpaceBetweenTokens(first, second)) {
396402
reportRequiredBeginningSpace(node, first);
397-
} else if (!config.allowMultiline && isMultiline(first, second)) {
403+
} else if (!config.allowMultiline && isMultiline(first, second)
404+
) {
398405
reportNoBeginningNewline(node, first, spacing);
399406
}
407+
// @ts-expect-error penultimate has a Comment type.
400408
if (!sourceCode.isSpaceBetweenTokens(penultimate, last)) {
401409
reportRequiredEndingSpace(node, last);
402410
} else if (!config.allowMultiline && isMultiline(penultimate, last)) {
@@ -407,13 +415,16 @@ module.exports = {
407415
if (!config.allowMultiline) {
408416
reportNoBeginningNewline(node, first, spacing);
409417
}
418+
// @ts-expect-error second has a Comment type.
410419
} else if (sourceCode.isSpaceBetweenTokens(first, second)) {
411420
reportNoBeginningSpace(node, first);
412421
}
413422
if (isMultiline(penultimate, last)) {
414-
if (!config.allowMultiline) {
415-
reportNoEndingNewline(node, last, spacing);
423+
if (config.allowMultiline) {
424+
return;
416425
}
426+
reportNoEndingNewline(node, last, spacing);
427+
// @ts-expect-error penultimate has a Comment type.
417428
} else if (sourceCode.isSpaceBetweenTokens(penultimate, last)) {
418429
reportNoEndingSpace(node, last);
419430
}

lib/rules/jsx-indent.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/**
32
* @fileoverview Validate JSX indentation
43
* @author Yannick Croissant
@@ -118,6 +117,7 @@ module.exports = {
118117
}
119118

120119
if (node.type === 'ReturnStatement') {
120+
// @ts-expect-error The types differ between ASTNode and ESTree.Node.
121121
const raw = context.getSourceCode().getText(node);
122122
const lines = raw.split('\n');
123123
if (lines.length > 1) {
@@ -170,6 +170,7 @@ module.exports = {
170170
* @return {Number} Indent
171171
*/
172172
function getNodeIndent(node, byLastLine, excludeCommas) {
173+
// @ts-expect-error The types differ between ASTNode and ESTree.Node.
173174
let src = context.getSourceCode().getText(node, node.loc.start.column + extraColumnStart);
174175
const lines = src.split('\n');
175176
if (byLastLine) {
@@ -217,6 +218,7 @@ module.exports = {
217218
&& node.parent.parent
218219
&& node.parent.parent.type === 'ConditionalExpression'
219220
&& node.parent.parent.alternate === node.parent
221+
// @ts-expect-error The types differ between ASTNode and ESTree.Node.
220222
&& context.getSourceCode().getTokenBefore(node).value !== '('
221223
);
222224
}
@@ -337,24 +339,29 @@ module.exports = {
337339

338340
function handleOpeningElement(node) {
339341
const sourceCode = context.getSourceCode();
342+
/** @type {import("estree").Node | import("eslint").AST.Token | import("estree").Comment} */
340343
let prevToken = sourceCode.getTokenBefore(node);
341344
if (!prevToken) {
342345
return;
343346
}
344347
// Use the parent in a list or an array
345348
if (prevToken.type === 'JSXText' || ((prevToken.type === 'Punctuator') && prevToken.value === ',')) {
346349
prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
350+
// @ts-expect-error The JSX syntax type does not exist within prevToken.
347351
prevToken = prevToken.type === 'Literal' || prevToken.type === 'JSXText' ? prevToken.parent : prevToken;
348352
// Use the first non-punctuator token in a conditional expression
349353
} else if (prevToken.type === 'Punctuator' && prevToken.value === ':') {
350354
do {
351355
prevToken = sourceCode.getTokenBefore(prevToken);
352356
} while (prevToken.type === 'Punctuator' && prevToken.value !== '/');
353357
prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
358+
// @ts-expect-error The JSX syntax type does not exist within prevToken.
354359
while (prevToken.parent && prevToken.parent.type !== 'ConditionalExpression') {
360+
// @ts-expect-error The JSX syntax type does not exist within prevToken.
355361
prevToken = prevToken.parent;
356362
}
357363
}
364+
// @ts-expect-error The JSX syntax type does not exist within prevToken.
358365
prevToken = prevToken.type === 'JSXExpressionContainer' ? prevToken.expression : prevToken;
359366
const parentElementIndent = getNodeIndent(prevToken);
360367
const indent = (

lib/rules/no-unused-state.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/**
32
* @fileoverview Attempts to discover all state fields in a React component and
43
* warn if any of them are never read.
@@ -111,6 +110,7 @@ module.exports = {
111110

112111
let scope = context.getScope();
113112
while (scope) {
113+
// @ts-expect-error The parent property does not exist in the ESTree.Node type.
114114
const parent = scope.block && scope.block.parent;
115115
if (
116116
parent
@@ -386,7 +386,9 @@ module.exports = {
386386

387387
stateRefs.forEach((ref) => {
388388
const identifier = ref.identifier;
389+
// @ts-expect-error The parent property does not exist in the Identifier type.
389390
if (identifier && identifier.parent && identifier.parent.type === 'MemberExpression') {
391+
// @ts-expect-error The parent property does not exist in the Identifier type.
390392
addUsedStateField(identifier.parent.property);
391393
}
392394
});
@@ -432,7 +434,7 @@ module.exports = {
432434
return;
433435
}
434436

435-
if (parent.key.name === 'getInitialState') {
437+
if (parent.type === 'Property' && parent.key.type === 'Identifier' && parent.key.name === 'getInitialState') {
436438
const body = node.body.body;
437439
const lastBodyNode = body[body.length - 1];
438440

@@ -464,6 +466,7 @@ module.exports = {
464466
&& unwrappedRight.type === 'ObjectExpression'
465467
) {
466468
// Find the nearest function expression containing this assignment.
469+
/** @type {import("eslint").Rule.Node} */
467470
let fn = node;
468471
while (fn.type !== 'FunctionExpression' && fn.parent) {
469472
fn = fn.parent;

0 commit comments

Comments
 (0)