Javascript: Mutually exclusive no-confusing-arrow and arrow-body-style rules

Created on 9 Mar 2017  路  3Comments  路  Source: airbnb/javascript

It seems airbnb-base eslint config makes no-confusing-arrow and arrow-body-style rules impossible to fix when ternary operator is used?

items.map(item => item.name ? item.name.en : null)
error  Arrow function used ambiguously with a conditional expression  no-confusing-arrow

http://eslint.org/docs/rules/no-confusing-arrow

items.map((item) => { return item.name ? item.name.en : null; })
error  Unexpected block statement surrounding arrow body  arrow-body-style

http://eslint.org/docs/rules/arrow-body-style

question

Most helpful comment

items.map(item => (item.name ? item.name.en : null))

All 3 comments

items.map(item => (item.name ? item.name.en : null))

Thanks. In my defence no-confusing-arrow rule doc shows (a) => (1 ? 2 : 3) as incorrect code and (a) => { return 1 ? 2 : 3; } as correct, didn't realise there is an option to reverse that.

PRs to improve the docs are always appreciated :-)

Was this page helpful?
0 / 5 - 0 ratings