Skip to content

Commit 3465df0

Browse files
committed
Add Ignore case
1 parent f2c6548 commit 3465df0

9 files changed

+57
-7
lines changed

lib/rules/forbid-prop-types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
/**
23
* @fileoverview Forbid certain propTypes
34
*/
@@ -25,6 +26,7 @@ const messages = {
2526
forbiddenPropType: 'Prop type "{{target}}" is forbidden',
2627
};
2728

29+
/** @type { import('eslint').Rule.RuleModule } */
2830
module.exports = {
2931
meta: {
3032
docs: {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const messages = {
1717
bracketLocation: 'The closing bracket must be {{location}}{{details}}',
1818
};
1919

20+
/** @type { import('eslint').Rule.RuleModule } */
2021
module.exports = {
2122
meta: {
2223
docs: {
@@ -195,7 +196,9 @@ module.exports = {
195196
*/
196197
function getTokensLocations(node) {
197198
const sourceCode = context.getSourceCode();
199+
// @ts-ignore
198200
const opening = sourceCode.getFirstToken(node).loc.start;
201+
// @ts-ignore
199202
const closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
200203
const tag = sourceCode.getFirstToken(node.name).loc.start;
201204
let lastProp;

lib/rules/jsx-curly-spacing.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
/**
23
* @fileoverview Enforce or disallow spaces inside of curly braces in JSX attributes.
34
* @author Jamund Ferguson
@@ -34,6 +35,7 @@ const messages = {
3435
spaceNeededBefore: 'A space is required before \'{{token}}\'',
3536
};
3637

38+
/** @type { import('eslint').Rule.RuleModule } */
3739
module.exports = {
3840
meta: {
3941
docs: {

lib/rules/jsx-equals-spacing.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const messages = {
1919
needSpaceAfter: 'A space is required after \'=\'',
2020
};
2121

22+
/** @type { import('eslint').Rule.RuleModule } */
2223
module.exports = {
2324
meta: {
2425
docs: {
@@ -61,7 +62,9 @@ module.exports = {
6162

6263
const sourceCode = context.getSourceCode();
6364
const equalToken = sourceCode.getTokenAfter(attrNode.name);
65+
// @ts-ignore
6466
const spacedBefore = sourceCode.isSpaceBetweenTokens(attrNode.name, equalToken);
67+
// @ts-ignore
6568
const spacedAfter = sourceCode.isSpaceBetweenTokens(equalToken, attrNode.value);
6669

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

lib/rules/jsx-indent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
/**
23
* @fileoverview Validate JSX indentation
34
* @author Yannick Croissant
@@ -45,6 +46,7 @@ const messages = {
4546
wrongIndent: 'Expected indentation of {{needed}} {{type}} {{characters}} but found {{gotten}}.',
4647
};
4748

49+
/** @type { import('eslint').Rule.RuleModule } */
4850
module.exports = {
4951
meta: {
5052
docs: {

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const messages = {
1717
useCallback: 'Use callback in setState when referencing the previous state.',
1818
};
1919

20+
/** @type { import('eslint').Rule.RuleModule } */
2021
module.exports = {
2122
meta: {
2223
docs: {
@@ -64,10 +65,10 @@ module.exports = {
6465
// Appends all the methods that are calling another
6566
// method containing this.state to the methods array
6667
methods.forEach((method) => {
67-
if (node.callee.name === method.methodName) {
68+
if (node.callee.type === "Identifier" && node.callee.name === method.methodName) {
6869
let current = node.parent;
6970
while (current.type !== 'Program') {
70-
if (current.type === 'MethodDefinition') {
71+
if (current.type === 'MethodDefinition' && current.key.type === "PrivateIdentifier") {
7172
methods.push({
7273
methodName: current.key.name,
7374
node: method.node,
@@ -83,7 +84,7 @@ module.exports = {
8384
// to further check if they contains this.state
8485
let current = node.parent;
8586
while (current.type !== 'Program') {
86-
if (isFirstArgumentInSetStateCall(current, node)) {
87+
if (isFirstArgumentInSetStateCall(current, node) && node.callee.type === "Identifier") {
8788
const methodName = node.callee.name;
8889
methods.forEach((method) => {
8990
if (method.methodName === methodName) {
@@ -101,11 +102,13 @@ module.exports = {
101102

102103
MemberExpression(node) {
103104
if (
104-
node.property.name === 'state'
105+
node.property.type === "PrivateIdentifier"
106+
&& node.property.name === 'state'
105107
&& node.object.type === 'ThisExpression'
106108
&& isClassComponent()
107109
) {
108110
let current = node;
111+
// @ts-ignore
109112
while (current.type !== 'Program') {
110113
// Reporting if this.state is directly within this.setState
111114
if (isFirstArgumentInSetStateCall(current, node)) {
@@ -116,30 +119,37 @@ module.exports = {
116119
}
117120

118121
// Storing all functions and methods that contains this.state
122+
// @ts-ignore
119123
if (current.type === 'MethodDefinition') {
120124
methods.push({
125+
// @ts-ignore
121126
methodName: current.key.name,
122127
node,
123128
});
124129
break;
130+
// @ts-ignore
125131
} else if (current.type === 'FunctionExpression' && current.parent.key) {
126132
methods.push({
133+
// @ts-ignore
127134
methodName: current.parent.key.name,
128135
node,
129136
});
130137
break;
131138
}
132139

133140
// Storing all variables containing this.state
141+
// @ts-ignore
134142
if (current.type === 'VariableDeclarator') {
135143
vars.push({
136144
node,
137145
scope: context.getScope(),
146+
// @ts-ignore
138147
variableName: current.id.name,
139148
});
140149
break;
141150
}
142151

152+
// @ts-ignore
143153
current = current.parent;
144154
}
145155
}
@@ -149,12 +159,16 @@ module.exports = {
149159
// Checks if the identifier is a variable within an object
150160
let current = node;
151161
while (current.parent.type === 'BinaryExpression') {
162+
// @ts-ignore
152163
current = current.parent;
153164
}
154165
if (
166+
// @ts-ignore
155167
current.parent.value === current
168+
// @ts-ignore
156169
|| current.parent.object === current
157170
) {
171+
// @ts-ignore
158172
while (current.type !== 'Program') {
159173
if (isFirstArgumentInSetStateCall(current, node)) {
160174
vars
@@ -165,15 +179,16 @@ module.exports = {
165179
});
166180
});
167181
}
182+
// @ts-ignore
168183
current = current.parent;
169184
}
170185
}
171186
},
172187

173188
ObjectPattern(node) {
174-
const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression';
189+
const isDerivedFromThis = (node.parent.type === "ForStatement" || node.parent.type === "VariableDeclarator") && node.parent.init && node.parent.init.type === 'ThisExpression';
175190
node.properties.forEach((property) => {
176-
if (property && property.key && property.key.name === 'state' && isDerivedFromThis) {
191+
if (property.type === "Property" && (property.key.type === "PrivateIdentifier" || property.key.type === "Identifier") && property.key.name === 'state' && isDerivedFromThis) {
177192
vars.push({
178193
node: property.key,
179194
scope: context.getScope(),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const messages = {
1717
dangerWithChildren: 'Only set one of `children` or `props.dangerouslySetInnerHTML`',
1818
};
1919

20+
/** @type { import('eslint').Rule.RuleModule } */
2021
module.exports = {
2122
meta: {
2223
docs: {
@@ -119,6 +120,7 @@ module.exports = {
119120
if (
120121
node.callee
121122
&& node.callee.type === 'MemberExpression'
123+
&& node.callee.property.type === "Identifier"
122124
&& node.callee.property.name === 'createElement'
123125
&& node.arguments.length > 1
124126
) {
@@ -127,6 +129,7 @@ module.exports = {
127129
let props = node.arguments[1];
128130

129131
if (props.type === 'Identifier') {
132+
// @ts-ignore
130133
const variable = variableUtil.variablesInScope(context).find((item) => item.name === props.name);
131134
if (variable && variable.defs.length && variable.defs[0].node.init) {
132135
props = variable.defs[0].node.init;

lib/rules/no-deprecated.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const messages = {
114114
deprecated: '{{oldMethod}} is deprecated since React {{version}}{{newMethod}}{{refs}}',
115115
};
116116

117+
/** @type { import('eslint').Rule.RuleModule } */
117118
module.exports = {
118119
meta: {
119120
docs: {
@@ -225,17 +226,24 @@ module.exports = {
225226
if (!isReactImport) {
226227
return;
227228
}
228-
node.specifiers.filter(((s) => s.imported)).forEach((specifier) => {
229+
node.specifiers.filter(((s) => s.type === "ImportSpecifier" && s.imported)).forEach((specifier) => {
230+
if(specifier.type !== "ImportSpecifier") {
231+
return
232+
}
229233
checkDeprecation(node, `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier);
230234
});
231235
},
232236

233237
VariableDeclarator(node) {
234238
const reactModuleName = getReactModuleName(node);
239+
// @ts-ignore
235240
const isRequire = node.init && node.init.callee && node.init.callee.name === 'require';
236241
const isReactRequire = node.init
242+
// @ts-ignore
237243
&& node.init.arguments
244+
// @ts-ignore
238245
&& node.init.arguments.length
246+
// @ts-ignore
239247
&& typeof MODULES[node.init.arguments[0].value] !== 'undefined';
240248
const isDestructuring = node.id && node.id.type === 'ObjectPattern';
241249

@@ -245,7 +253,16 @@ module.exports = {
245253
) {
246254
return;
247255
}
256+
if(node.id.type !== "ObjectPattern") {
257+
return
258+
}
248259
node.id.properties.filter((p) => p.type !== 'RestElement' && p.key).forEach((property) => {
260+
if(property.type !== "Property"){
261+
return
262+
}
263+
if(property.key.type !== "Identifier" && property.key.type !== "PrivateIdentifier"){
264+
return
265+
}
249266
checkDeprecation(node, `${reactModuleName || pragma}.${property.key.name}`, property);
250267
});
251268
},

lib/rules/no-unused-state.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
/**
23
* @fileoverview Attempts to discover all state fields in a React component and
34
* warn if any of them are never read.
@@ -77,6 +78,7 @@ const messages = {
7778
unusedStateField: 'Unused state field: \'{{name}}\'',
7879
};
7980

81+
/** @type { import('eslint').Rule.RuleModule } */
8082
module.exports = {
8183
meta: {
8284
docs: {
@@ -109,6 +111,7 @@ module.exports = {
109111

110112
let scope = context.getScope();
111113
while (scope) {
114+
// @ts-ignore
112115
const parent = scope.block && scope.block.parent;
113116
if (
114117
parent

0 commit comments

Comments
 (0)