Skip to content

Commit 04da3f0

Browse files
chiawendtljharb
authored andcommitted
[Refactor] fix linter errors
1 parent 5bc571d commit 04da3f0

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
"prefer-spread": 0, // until node 6 is required
3333
"function-call-argument-newline": 1, // TODO: enable
3434
"function-paren-newline": 0,
35-
"no-plusplus": 1,
35+
"no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
3636
"no-param-reassign": 1,
37-
"no-unreachable-loop": 1, // TODO: enable
3837
"no-restricted-syntax": [2, {
3938
"selector": "ObjectPattern",
4039
"message": "Object destructuring is not compatible with Node v4"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1515

1616
### Changed
1717
* [readme] remove global usage and eslint version from readme ([#3254][] @aladdin-add)
18+
* [Refactor] fix linter errors ([#3261][] @golopot)
1819

20+
[#3261]: https://github.com/yannickcr/eslint-plugin-react/pull/3261
1921
[#3254]: https://github.com/yannickcr/eslint-plugin-react/pull/3254
2022
[#3251]: https://github.com/yannickcr/eslint-plugin-react/pull/3251
2123
[#3244]: https://github.com/yannickcr/eslint-plugin-react/pull/3244

lib/rules/jsx-max-depth.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
while (jsxUtil.isJSX(node.parent) || isExpression(node.parent)) {
7171
node = node.parent;
7272
if (jsxUtil.isJSX(node)) {
73-
count++;
73+
count += 1;
7474
}
7575
}
7676

@@ -89,9 +89,7 @@ module.exports = {
8989

9090
function findJSXElementOrFragment(variables, name, previousReferences) {
9191
function find(refs, prevRefs) {
92-
let i = refs.length;
93-
94-
while (--i >= 0) {
92+
for (let i = refs.length - 1; i >= 0; i--) {
9593
if (has(refs[i], 'writeExpr')) {
9694
const writeExpr = refs[i].writeExpr;
9795

@@ -121,7 +119,7 @@ module.exports = {
121119
}
122120

123121
function checkDescendant(baseDepth, children) {
124-
baseDepth++;
122+
baseDepth += 1;
125123
(children || []).forEach((node) => {
126124
if (!hasJSX(node)) {
127125
return;

lib/rules/jsx-pascal-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = {
155155
});
156156
break;
157157
}
158-
index++;
158+
index += 1;
159159
} while (index < checkNames.length && !allowNamespace);
160160
},
161161
};

lib/rules/jsx-sort-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function getGroupsOfSortableAttributes(attributes) {
133133
|| (lastAttr.type === 'JSXSpreadAttribute'
134134
&& attributes[i].type !== 'JSXSpreadAttribute')
135135
) {
136-
groupCount++;
136+
groupCount += 1;
137137
sortableAttributeGroups[groupCount - 1] = [];
138138
}
139139
if (attributes[i].type !== 'JSXSpreadAttribute') {

lib/rules/require-render-return.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = {
6161
let depth = 0;
6262
ancestors.forEach((ancestor) => {
6363
if (/Function(Expression|Declaration)$/.test(ancestor.type)) {
64-
depth++;
64+
depth += 1;
6565
}
6666
if (
6767
/(MethodDefinition|Property|ClassProperty|PropertyDefinition)$/.test(ancestor.type)

lib/rules/sort-comp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ module.exports = {
266266
};
267267
}
268268
// Increment the prop score
269-
errors[propA.index].score++;
269+
errors[propA.index].score += 1;
270270
// Stop here if we already have pushed another node at this position
271271
if (getPropertyName(errors[propA.index].node) !== getPropertyName(propA.node)) {
272272
return;

lib/util/ast.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ function traverse(ASTnode, visitor) {
2828
estraverse.traverse(ASTnode, opts);
2929
}
3030

31+
function loopNodes(nodes) {
32+
for (let i = nodes.length - 1; i >= 0; i--) {
33+
if (nodes[i].type === 'ReturnStatement') {
34+
return nodes[i];
35+
}
36+
if (nodes[i].type === 'SwitchStatement') {
37+
const j = nodes[i].cases.length - 1;
38+
if (j >= 0) {
39+
return loopNodes(nodes[i].cases[j].consequent);
40+
}
41+
}
42+
}
43+
return false;
44+
}
45+
3146
/**
3247
* Find a return statment in the current node
3348
*
@@ -42,23 +57,9 @@ function findReturnStatement(node) {
4257
return false;
4358
}
4459

45-
const bodyNodes = (node.value ? node.value.body.body : node.body.body);
60+
const bodyNodes = node.value ? node.value.body.body : node.body.body;
4661

47-
return (function loopNodes(nodes) {
48-
let i = nodes.length - 1;
49-
for (; i >= 0; i--) {
50-
if (nodes[i].type === 'ReturnStatement') {
51-
return nodes[i];
52-
}
53-
if (nodes[i].type === 'SwitchStatement') {
54-
let j = nodes[i].cases.length - 1;
55-
for (; j >= 0; j--) {
56-
return loopNodes(nodes[i].cases[j].consequent);
57-
}
58-
}
59-
}
60-
return false;
61-
}(bodyNodes));
62+
return loopNodes(bodyNodes);
6263
}
6364

6465
/**

lib/util/makeNoMethodSetStateRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafe
9595
let depth = 0;
9696
ancestors.some((ancestor) => {
9797
if (/Function(Expression|Declaration)$/.test(ancestor.type)) {
98-
depth++;
98+
depth += 1;
9999
}
100100
if (
101101
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition' && ancestor.type !== 'ClassProperty' && ancestor.type !== 'PropertyDefinition')

0 commit comments

Comments
 (0)