Skip to content

Commit

Permalink
[Refactor] fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed Apr 1, 2022
1 parent 5bc571d commit 04da3f0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
"prefer-spread": 0, // until node 6 is required
"function-call-argument-newline": 1, // TODO: enable
"function-paren-newline": 0,
"no-plusplus": 1,
"no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
"no-param-reassign": 1,
"no-unreachable-loop": 1, // TODO: enable
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

[#3261]: https://github.com/yannickcr/eslint-plugin-react/pull/3261
[#3254]: https://github.com/yannickcr/eslint-plugin-react/pull/3254
[#3251]: https://github.com/yannickcr/eslint-plugin-react/pull/3251
[#3244]: https://github.com/yannickcr/eslint-plugin-react/pull/3244
Expand Down
8 changes: 3 additions & 5 deletions lib/rules/jsx-max-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = {
while (jsxUtil.isJSX(node.parent) || isExpression(node.parent)) {
node = node.parent;
if (jsxUtil.isJSX(node)) {
count++;
count += 1;
}
}

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

function findJSXElementOrFragment(variables, name, previousReferences) {
function find(refs, prevRefs) {
let i = refs.length;

while (--i >= 0) {
for (let i = refs.length - 1; i >= 0; i--) {
if (has(refs[i], 'writeExpr')) {
const writeExpr = refs[i].writeExpr;

Expand Down Expand Up @@ -121,7 +119,7 @@ module.exports = {
}

function checkDescendant(baseDepth, children) {
baseDepth++;
baseDepth += 1;
(children || []).forEach((node) => {
if (!hasJSX(node)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = {
});
break;
}
index++;
index += 1;
} while (index < checkNames.length && !allowNamespace);
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function getGroupsOfSortableAttributes(attributes) {
|| (lastAttr.type === 'JSXSpreadAttribute'
&& attributes[i].type !== 'JSXSpreadAttribute')
) {
groupCount++;
groupCount += 1;
sortableAttributeGroups[groupCount - 1] = [];
}
if (attributes[i].type !== 'JSXSpreadAttribute') {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-render-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
let depth = 0;
ancestors.forEach((ancestor) => {
if (/Function(Expression|Declaration)$/.test(ancestor.type)) {
depth++;
depth += 1;
}
if (
/(MethodDefinition|Property|ClassProperty|PropertyDefinition)$/.test(ancestor.type)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ module.exports = {
};
}
// Increment the prop score
errors[propA.index].score++;
errors[propA.index].score += 1;
// Stop here if we already have pushed another node at this position
if (getPropertyName(errors[propA.index].node) !== getPropertyName(propA.node)) {
return;
Expand Down
33 changes: 17 additions & 16 deletions lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ function traverse(ASTnode, visitor) {
estraverse.traverse(ASTnode, opts);
}

function loopNodes(nodes) {
for (let i = nodes.length - 1; i >= 0; i--) {
if (nodes[i].type === 'ReturnStatement') {
return nodes[i];
}
if (nodes[i].type === 'SwitchStatement') {
const j = nodes[i].cases.length - 1;
if (j >= 0) {
return loopNodes(nodes[i].cases[j].consequent);
}
}
}
return false;
}

/**
* Find a return statment in the current node
*
Expand All @@ -42,23 +57,9 @@ function findReturnStatement(node) {
return false;
}

const bodyNodes = (node.value ? node.value.body.body : node.body.body);
const bodyNodes = node.value ? node.value.body.body : node.body.body;

return (function loopNodes(nodes) {
let i = nodes.length - 1;
for (; i >= 0; i--) {
if (nodes[i].type === 'ReturnStatement') {
return nodes[i];
}
if (nodes[i].type === 'SwitchStatement') {
let j = nodes[i].cases.length - 1;
for (; j >= 0; j--) {
return loopNodes(nodes[i].cases[j].consequent);
}
}
}
return false;
}(bodyNodes));
return loopNodes(bodyNodes);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/util/makeNoMethodSetStateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafe
let depth = 0;
ancestors.some((ancestor) => {
if (/Function(Expression|Declaration)$/.test(ancestor.type)) {
depth++;
depth += 1;
}
if (
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition' && ancestor.type !== 'ClassProperty' && ancestor.type !== 'PropertyDefinition')
Expand Down

0 comments on commit 04da3f0

Please sign in to comment.