Skip to content

Commit 56e669f

Browse files
committed
[eslint] enable and autofix operator-linebreak
1 parent 52207e4 commit 56e669f

22 files changed

+135
-144
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
"ignoreTemplateLiterals": true,
2222
"ignoreComments": true,
2323
}],
24+
"operator-linebreak": [2, "after"],
2425

2526
"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
2627

2728
"import/order": 1,
2829
"no-useless-escape": 1,
29-
"operator-linebreak": 1,
3030
"function-paren-newline": 0,
3131
"no-plusplus": 1,
3232
"no-param-reassign": 1,

lib/rules/button-has-type.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const pragmaUtil = require('../util/pragma');
1616

1717
function isCreateElement(node, context) {
1818
const pragma = pragmaUtil.getFromContext(context);
19-
return node.callee
20-
&& node.callee.type === 'MemberExpression'
21-
&& node.callee.property.name === 'createElement'
22-
&& node.callee.object
23-
&& node.callee.object.name === pragma
24-
&& node.arguments.length > 0;
19+
return node.callee &&
20+
node.callee.type === 'MemberExpression' &&
21+
node.callee.property.name === 'createElement' &&
22+
node.callee.object &&
23+
node.callee.object.name === pragma &&
24+
node.arguments.length > 0;
2525
}
2626

2727
// ------------------------------------------------------------------------------

lib/rules/forbid-elements.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ module.exports = {
7373
}
7474

7575
function isValidCreateElement(node) {
76-
return node.callee
77-
&& node.callee.type === 'MemberExpression'
78-
&& node.callee.object.name === 'React'
79-
&& node.callee.property.name === 'createElement'
80-
&& node.arguments.length > 0;
76+
return node.callee &&
77+
node.callee.type === 'MemberExpression' &&
78+
node.callee.object.name === 'React' &&
79+
node.callee.property.name === 'createElement' &&
80+
node.arguments.length > 0;
8181
}
8282

8383
function reportIfForbidden(element, node) {

lib/rules/jsx-curly-brace-presence.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ module.exports = {
213213
}
214214

215215
if (
216-
parent.children
217-
&& parent.children.length === 1
218-
&& containsWhitespaceExpression(parent.children[0])
216+
parent.children &&
217+
parent.children.length === 1 &&
218+
containsWhitespaceExpression(parent.children[0])
219219
) {
220220
return false;
221221
}
@@ -225,9 +225,9 @@ module.exports = {
225225

226226
function shouldCheckForMissingCurly(parent, config) {
227227
if (
228-
parent.children
229-
&& parent.children.length === 1
230-
&& containsWhitespaceExpression(parent.children[0])
228+
parent.children &&
229+
parent.children.length === 1 &&
230+
containsWhitespaceExpression(parent.children[0])
231231
) {
232232
return false;
233233
}

lib/rules/jsx-fragments.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module.exports = {
4848
if (!versionUtil.testReactVersion(context, '16.2.0')) {
4949
context.report({
5050
node,
51-
message: 'Fragments are only supported starting from React v16.2. '
52-
+ 'Please disable the `react/jsx-fragments` rule in ESLint settings or upgrade your version of React.'
51+
message: 'Fragments are only supported starting from React v16.2. ' +
52+
'Please disable the `react/jsx-fragments` rule in ESLint settings or upgrade your version of React.'
5353
});
5454
return true;
5555
}
@@ -62,8 +62,8 @@ module.exports = {
6262
let source = sourceCode.getText();
6363
source = replaceNode(source, jsxFragment.closingFragment, closeFragLong);
6464
source = replaceNode(source, jsxFragment.openingFragment, openFragLong);
65-
const lengthDiff = openFragLong.length - sourceCode.getText(jsxFragment.openingFragment).length
66-
+ closeFragLong.length - sourceCode.getText(jsxFragment.closingFragment).length;
65+
const lengthDiff = openFragLong.length - sourceCode.getText(jsxFragment.openingFragment).length +
66+
closeFragLong.length - sourceCode.getText(jsxFragment.closingFragment).length;
6767
const range = jsxFragment.range;
6868
return fixer.replaceTextRange(range, source.slice(range[0], range[1] + lengthDiff));
6969
};
@@ -76,12 +76,12 @@ module.exports = {
7676
if (jsxElement.closingElement) {
7777
source = replaceNode(source, jsxElement.closingElement, closeFragShort);
7878
source = replaceNode(source, jsxElement.openingElement, openFragShort);
79-
lengthDiff = sourceCode.getText(jsxElement.openingElement).length - openFragShort.length
80-
+ sourceCode.getText(jsxElement.closingElement).length - closeFragShort.length;
79+
lengthDiff = sourceCode.getText(jsxElement.openingElement).length - openFragShort.length +
80+
sourceCode.getText(jsxElement.closingElement).length - closeFragShort.length;
8181
} else {
8282
source = replaceNode(source, jsxElement.openingElement, `${openFragShort}${closeFragShort}`);
83-
lengthDiff = sourceCode.getText(jsxElement.openingElement).length - openFragShort.length
84-
- closeFragShort.length;
83+
lengthDiff = sourceCode.getText(jsxElement.openingElement).length - openFragShort.length -
84+
closeFragShort.length;
8585
}
8686

8787
const range = jsxElement.range;
@@ -102,22 +102,22 @@ module.exports = {
102102

103103
// const Fragment = React.Fragment;
104104
if (
105-
variableInit.type === 'MemberExpression'
106-
&& variableInit.object.type === 'Identifier'
107-
&& variableInit.object.name === reactPragma
108-
&& variableInit.property.type === 'Identifier'
109-
&& variableInit.property.name === fragmentPragma
105+
variableInit.type === 'MemberExpression' &&
106+
variableInit.object.type === 'Identifier' &&
107+
variableInit.object.name === reactPragma &&
108+
variableInit.property.type === 'Identifier' &&
109+
variableInit.property.name === fragmentPragma
110110
) {
111111
return true;
112112
}
113113

114114
// const { Fragment } = require('react');
115115
if (
116-
variableInit.callee
117-
&& variableInit.callee.name === 'require'
118-
&& variableInit.arguments
119-
&& variableInit.arguments[0]
120-
&& variableInit.arguments[0].value === 'react'
116+
variableInit.callee &&
117+
variableInit.callee.name === 'require' &&
118+
variableInit.arguments &&
119+
variableInit.arguments[0] &&
120+
variableInit.arguments[0].value === 'react'
121121
) {
122122
return true;
123123
}

lib/rules/jsx-max-depth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ module.exports = {
8888
if (has(refs[i], 'writeExpr')) {
8989
const writeExpr = refs[i].writeExpr;
9090

91-
return jsxUtil.isJSX(writeExpr)
92-
&& writeExpr
93-
|| (writeExpr && writeExpr.type === 'Identifier')
94-
&& findJSXElementOrFragment(variables, writeExpr.name);
91+
return jsxUtil.isJSX(writeExpr) &&
92+
writeExpr ||
93+
(writeExpr && writeExpr.type === 'Identifier') &&
94+
findJSXElementOrFragment(variables, writeExpr.name);
9595
}
9696
}
9797

lib/rules/no-array-index-key.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ module.exports = {
4545
const ERROR_MESSAGE = 'Do not use Array index in keys';
4646

4747
function isArrayIndex(node) {
48-
return node.type === 'Identifier'
49-
&& indexParamNames.indexOf(node.name) !== -1;
48+
return node.type === 'Identifier' &&
49+
indexParamNames.indexOf(node.name) !== -1;
5050
}
5151

5252
function isUsingReactChildren(node) {
5353
const callee = node.callee;
5454
if (
55-
!callee
56-
|| !callee.property
57-
|| !callee.object
55+
!callee ||
56+
!callee.property ||
57+
!callee.object
5858
) {
5959
return null;
6060
}
@@ -87,9 +87,9 @@ module.exports = {
8787
return null;
8888
}
8989

90-
const callbackArg = isUsingReactChildren(node)
91-
? node.arguments[1]
92-
: node.arguments[0];
90+
const callbackArg = isUsingReactChildren(node) ?
91+
node.arguments[1] :
92+
node.arguments[0];
9393

9494
if (!callbackArg) {
9595
return null;
@@ -156,10 +156,10 @@ module.exports = {
156156
return {
157157
CallExpression(node) {
158158
if (
159-
node.callee
160-
&& node.callee.type === 'MemberExpression'
161-
&& ['createElement', 'cloneElement'].indexOf(node.callee.property.name) !== -1
162-
&& node.arguments.length > 1
159+
node.callee &&
160+
node.callee.type === 'MemberExpression' &&
161+
['createElement', 'cloneElement'].indexOf(node.callee.property.name) !== -1 &&
162+
node.arguments.length > 1
163163
) {
164164
// React.createElement
165165
if (!indexParamNames.length) {

lib/rules/no-children-prop.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ const docsUrl = require('../util/docsUrl');
1818
* object literal, False if not.
1919
*/
2020
function isCreateElementWithProps(node) {
21-
return node.callee
22-
&& node.callee.type === 'MemberExpression'
23-
&& node.callee.property.name === 'createElement'
24-
&& node.arguments.length > 1
25-
&& node.arguments[1].type === 'ObjectExpression';
21+
return node.callee &&
22+
node.callee.type === 'MemberExpression' &&
23+
node.callee.property.name === 'createElement' &&
24+
node.arguments.length > 1 &&
25+
node.arguments[1].type === 'ObjectExpression';
2626
}
2727

2828
// ------------------------------------------------------------------------------

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ module.exports = {
9595
}
9696

9797
if (
98-
node.openingElement.attributes
99-
&& hasChildren
100-
&& findJsxProp(node, 'dangerouslySetInnerHTML')
98+
node.openingElement.attributes &&
99+
hasChildren &&
100+
findJsxProp(node, 'dangerouslySetInnerHTML')
101101
) {
102102
context.report(node, 'Only set one of `children` or `props.dangerouslySetInnerHTML`');
103103
}
104104
},
105105
CallExpression(node) {
106106
if (
107-
node.callee
108-
&& node.callee.type === 'MemberExpression'
109-
&& node.callee.property.name === 'createElement'
110-
&& node.arguments.length > 1
107+
node.callee &&
108+
node.callee.type === 'MemberExpression' &&
109+
node.callee.property.name === 'createElement' &&
110+
node.arguments.length > 1
111111
) {
112112
let hasChildren = false;
113113

lib/rules/no-deprecated.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ module.exports = {
200200
VariableDeclarator(node) {
201201
const reactModuleName = getReactModuleName(node);
202202
const isRequire = node.init && node.init.callee && node.init.callee.name === 'require';
203-
const isReactRequire = node.init
204-
&& node.init.arguments
205-
&& node.init.arguments.length
206-
&& typeof MODULES[node.init.arguments[0].value] !== 'undefined';
203+
const isReactRequire = node.init &&
204+
node.init.arguments &&
205+
node.init.arguments.length &&
206+
typeof MODULES[node.init.arguments[0].value] !== 'undefined';
207207
const isDestructuring = node.id && node.id.type === 'ObjectPattern';
208208

209209
if (

0 commit comments

Comments
 (0)