Skip to content

Commit 04d65bb

Browse files
committed
[eslint] enable and manually fix no-case-declarations
1 parent 0b49ae7 commit 04d65bb

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"object-curly-newline": 1,
3737
"object-property-newline": 1,
3838
"spaced-comment": 1,
39-
"no-case-declarations": 1,
4039
"no-underscore-dangle": 1,
4140
"no-mixed-operators": 1,
4241
"no-void": 1,

lib/rules/forbid-prop-types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,20 @@ module.exports = {
118118
case 'ObjectExpression':
119119
checkProperties(node.properties);
120120
break;
121-
case 'Identifier':
121+
case 'Identifier': {
122122
const propTypesObject = variableUtil.findVariableByName(context, node.name);
123123
if (propTypesObject && propTypesObject.properties) {
124124
checkProperties(propTypesObject.properties);
125125
}
126126
break;
127-
case 'CallExpression':
127+
}
128+
case 'CallExpression': {
128129
const innerNode = node.arguments && node.arguments[0];
129130
if (propWrapperUtil.isPropWrapperFunction(context, context.getSource(node.callee)) && innerNode) {
130131
checkNode(innerNode);
131132
}
132133
break;
134+
}
133135
default:
134136
break;
135137
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ module.exports = {
142142
return tokens.lastProp.lastLine === tokens.closing.line;
143143
case 'props-aligned':
144144
case 'tag-aligned':
145-
case 'line-aligned':
145+
case 'line-aligned': {
146146
const correctColumn = getCorrectColumn(tokens, expectedLocation);
147147
return correctColumn === tokens.closing.column;
148+
}
148149
default:
149150
return true;
150151
}

lib/rules/jsx-sort-default-props.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,20 @@ module.exports = {
129129
case 'ObjectExpression':
130130
checkSorted(node.properties);
131131
break;
132-
case 'Identifier':
132+
case 'Identifier': {
133133
const propTypesObject = findVariableByName(node.name);
134134
if (propTypesObject && propTypesObject.properties) {
135135
checkSorted(propTypesObject.properties);
136136
}
137137
break;
138-
case 'CallExpression':
138+
}
139+
case 'CallExpression': {
139140
const innerNode = node.arguments && node.arguments[0];
140141
if (propWrapperUtil.isPropWrapperFunction(context, node.callee.name) && innerNode) {
141142
checkNode(innerNode);
142143
}
143144
break;
145+
}
144146
default:
145147
break;
146148
}

lib/rules/sort-prop-types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,20 @@ module.exports = {
247247
case 'ObjectExpression':
248248
checkSorted(node.properties);
249249
break;
250-
case 'Identifier':
250+
case 'Identifier': {
251251
const propTypesObject = variableUtil.findVariableByName(context, node.name);
252252
if (propTypesObject && propTypesObject.properties) {
253253
checkSorted(propTypesObject.properties);
254254
}
255255
break;
256-
case 'CallExpression':
256+
}
257+
case 'CallExpression': {
257258
const innerNode = node.arguments && node.arguments[0];
258259
if (propWrapperUtil.isPropWrapperFunction(context, node.callee.name) && innerNode) {
259260
checkNode(innerNode);
260261
}
261262
break;
263+
}
262264
default:
263265
break;
264266
}

lib/util/propTypes.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
370370
const callName = value.callee.property.name;
371371
const argument = value.arguments[0];
372372
switch (callName) {
373-
case 'shape':
373+
case 'shape': {
374374
if (argument.type !== 'ObjectExpression') {
375375
// Invalid proptype or cannot analyse statically
376376
return {};
@@ -390,8 +390,9 @@ module.exports = function propTypesInstructions(context, components, utils) {
390390
}
391391
});
392392
return shapeTypeDefinition;
393+
}
393394
case 'arrayOf':
394-
case 'objectOf':
395+
case 'objectOf': {
395396
const fullName = [parentName, '*'].join('.');
396397
const child = buildReactDeclarationTypes(argument, fullName);
397398
child.fullName = fullName;
@@ -403,7 +404,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
403404
__ANY_KEY__: child
404405
}
405406
};
406-
case 'oneOfType':
407+
}
408+
case 'oneOfType': {
407409
if (
408410
!argument.elements ||
409411
!argument.elements.length
@@ -435,6 +437,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
435437
return {};
436438
}
437439
return unionTypeDefinition;
440+
}
438441
case 'instanceOf':
439442
return {
440443
type: 'instance',
@@ -482,7 +485,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
482485
declaredPropTypes[key] = types;
483486
});
484487
break;
485-
case 'MemberExpression':
488+
case 'MemberExpression': {
486489
let curDeclaredPropTypes = declaredPropTypes;
487490
// Walk the list of properties, until we reach the assignment
488491
// ie: ClassX.propTypes.a.b.c = ...
@@ -537,7 +540,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
537540
}
538541
}
539542
break;
540-
case 'Identifier':
543+
}
544+
case 'Identifier': {
541545
const variablesInScope = variableUtil.variablesInScope(context);
542546
for (let i = 0, j = variablesInScope.length; i < j; i++) {
543547
if (variablesInScope[i].name !== propTypes.name) {
@@ -549,7 +553,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
549553
}
550554
ignorePropsValidation = true;
551555
break;
552-
case 'CallExpression':
556+
}
557+
case 'CallExpression': {
553558
if (
554559
propWrapperUtil.isPropWrapperFunction(context, sourceCode.getText(propTypes.callee)) &&
555560
propTypes.arguments && propTypes.arguments[0]
@@ -558,6 +563,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
558563
return;
559564
}
560565
break;
566+
}
561567
case 'IntersectionTypeAnnotation':
562568
ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes);
563569
break;

lib/util/usedPropTypes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
364364
let ignoreUnusedPropTypesValidation = component && component.ignoreUnusedPropTypesValidation || false;
365365

366366
switch (type) {
367-
case 'direct':
367+
case 'direct': {
368368
// Ignore Object methods
369369
if (name in Object.prototype) {
370370
break;
@@ -385,7 +385,8 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
385385
node: reportedNode
386386
});
387387
break;
388-
case 'destructuring':
388+
}
389+
case 'destructuring': {
389390
for (let k = 0, l = (properties || []).length; k < l; k++) {
390391
if (hasSpreadOperator(properties[k]) || properties[k].computed) {
391392
ignoreUnusedPropTypesValidation = true;
@@ -409,6 +410,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
409410
}
410411
}
411412
break;
413+
}
412414
default:
413415
break;
414416
}

0 commit comments

Comments
 (0)