The no-confusing-arrow rule is enabled, so the following syntax is an error:
const fn = a => a ? 1 : 2;
The arrow-body-style rule is enabled, so the following syntax is an error too:
const fn = a => { return a ? 1 : 2; };
So the only way to write it following the rules is the following one:
const fn = a => { if (a) return 2; return 3; };
Is this correct? Or is there another way to write the same stuff in a different way?
The allowParens option is set to true, so
const fn = a => (a ? 1 : 2);
should not cause a linter error.
https://github.com/airbnb/javascript#arrows--confusing
Simply copy and paste the code seemed as good practice.
const itemHeight = (item) => { return item.height > 256 ? item.largeSize : item.smallSize; };
itemHeight();
The error reports 1:30 error Unexpected block statement surrounding arrow body arrow-body-style
@medifle thanks, we don't lint the readme, so sometimes the examples can go out of sync.
let fun = (question, yes, no) => {
if (confirm(question)) yes();
else no();
};
let asking = fun("Do you agree?", function() { alert("You agreed."); }, function() { alert("You canceled the execution."); });
is this right way or wrong way to explore the arrow ????
@tejalbadgujar if your function doesn’t use this or arguments or super, and isn’t newed, then there’s really no difference. All three of those functions could be arrows or normal ones, just the same.
Got it
On Sun 19 Jul, 2020, 1:14 AM Jordan Harband, notifications@github.com
wrote:
@tejalbadgujar https://github.com/tejalbadgujar if your function
doesn’t use this or arguments or super, and isn’t newed, then there’s
really no difference. All three of those functions could be arrows or
normal ones, just the same.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/airbnb/javascript/issues/856#issuecomment-660532601,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANS6YA5O5BJJQVCLU75UEBTR4H3SBANCNFSM4CB7EIGQ
.
Most helpful comment
The
allowParensoption is set to true, soshould not cause a linter error.