Add parenthesis for no-confusing-arrow rule (#1182)
I'm unclear whether anyone was ever confused by this but the eslint page is kind of compelling ```js // The intent is not clear var x = a => 1 ? 2 : 3; // Did the author mean this var x = function (a) { return 1 ? 2 : 3 }; // Or this var x = a <= 1 ? 2 : 3; ``` Adding a parenthesis makes it valid with `{"allowParens": true}` rule. Note that if this option is not enabled, the code would not pass lint in the first place.master
parent
e0eb438e7b
commit
2e63684ff5
|
@ -449,6 +449,7 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
case "ExportDefaultDeclaration":
|
||||
case "AwaitExpression":
|
||||
case "JSXSpreadAttribute":
|
||||
case "ArrowFunctionExpression":
|
||||
return true;
|
||||
|
||||
case "NewExpression":
|
||||
|
|
|
@ -70,7 +70,7 @@ function someFunction(url) {
|
|||
}
|
||||
|
||||
const mapChargeItems = fp.flow(
|
||||
l => l < 10 ? l : 1,
|
||||
l => (l < 10 ? l : 1),
|
||||
l => Immutable.Range(l).toMap()
|
||||
);
|
||||
|
||||
|
|
|
@ -89,3 +89,14 @@ const testConsole = new TestConsole(
|
|||
);
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`no-confusing-arrow.js 1`] = `
|
||||
"// no-confusing-arrow
|
||||
var x = a => 1 ? 2 : 3;
|
||||
var x = a <= 1 ? 2 : 3;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// no-confusing-arrow
|
||||
var x = a => (1 ? 2 : 3);
|
||||
var x = a <= 1 ? 2 : 3;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// no-confusing-arrow
|
||||
var x = a => 1 ? 2 : 3;
|
||||
var x = a <= 1 ? 2 : 3;
|
|
@ -49,7 +49,7 @@ function unannotated(x) {
|
|||
}
|
||||
|
||||
// test deduping of inferred types
|
||||
const nullToUndefined = val => val === null ? undefined : val;
|
||||
const nullToUndefined = val => (val === null ? undefined : val);
|
||||
|
||||
function f0(x: ?Object) {
|
||||
return nullToUndefined(x);
|
||||
|
|
|
@ -73,7 +73,7 @@ true
|
|||
}),
|
||||
require(\\"postcss-url\\")({
|
||||
url: url =>
|
||||
url.startsWith(\\"/\\") || /^[a-z]+:/.test(url) ? url : \`/static/\${url}\`
|
||||
(url.startsWith(\\"/\\") || /^[a-z]+:/.test(url) ? url : \`/static/\${url}\`)
|
||||
})
|
||||
]
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue