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 9c76175
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
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
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
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
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
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
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
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
22 changes: 8 additions & 14 deletions lib/util/ast.js
Expand Up @@ -44,21 +44,15 @@ function findReturnStatement(node) {

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);
}
}
for (let i = bodyNodes.length - 1; i >= 0; i--) {
if (bodyNodes[i].type === 'ReturnStatement') {
return bodyNodes[i];
}
return false;
}(bodyNodes));
if (bodyNodes[i].type === 'SwitchStatement' && bodyNodes[i].cases.length > 0) {
return loopNodes(bodyNodes[i].cases[j].consequent);
}
}
return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/util/makeNoMethodSetStateRule.js
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 9c76175

Please sign in to comment.