fix: do not format callbacks with arguments as React hooks (#5778)
Ref: https://github.com/prettier/prettier/pull/5608#issuecomment-455860396master
parent
106fc36c81
commit
565731668f
|
@ -41,3 +41,40 @@ Examples:
|
|||
```
|
||||
|
||||
-->
|
||||
|
||||
- JavaScript: Do not format functions with arguments as react hooks ([#5778] by [@SimenB])
|
||||
|
||||
The formatting added in Prettier 1.16 would format any function receiving an
|
||||
arrow function and an array literal to match React Hook's documentation.
|
||||
Prettier will now format this the same as before that change if the arrow
|
||||
function receives any arguments.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
|
||||
(allColors, color) => {
|
||||
return allColors.concat(color);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// Output (Prettier stable)
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce((
|
||||
allColors,
|
||||
color
|
||||
) => {
|
||||
return allColors.concat(color);
|
||||
}, []);
|
||||
|
||||
// Output (Prettier master)
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
|
||||
(allColors, color) => {
|
||||
return allColors.concat(color);
|
||||
},
|
||||
[]
|
||||
);
|
||||
```
|
||||
|
||||
[@simenb]: https://github.com/SimenB
|
||||
[#5778]: https://github.com/prettier/prettier/pull/5778
|
||||
|
|
|
@ -3904,6 +3904,7 @@ function printArgumentsList(path, options, print) {
|
|||
if (
|
||||
args.length === 2 &&
|
||||
args[0].type === "ArrowFunctionExpression" &&
|
||||
args[0].params.length === 0 &&
|
||||
args[0].body.type === "BlockStatement" &&
|
||||
args[1].type === "ArrayExpression" &&
|
||||
!args.find(arg => arg.leadingComments || arg.trailingComments)
|
||||
|
|
|
@ -42,6 +42,14 @@ const mapChargeItems = fp.flow(
|
|||
|
||||
expect(new LongLongLongLongLongRange([0, 0], [0, 0])).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0]));
|
||||
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
|
||||
(allColors, color) => {
|
||||
return allColors.concat(color);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
=====================================output=====================================
|
||||
h(
|
||||
f(
|
||||
|
@ -84,6 +92,13 @@ expect(
|
|||
new LongLongLongLongLongRange([0, 0], [0, 0])
|
||||
).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0]));
|
||||
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
|
||||
(allColors, color) => {
|
||||
return allColors.concat(color);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
|
|
|
@ -33,3 +33,11 @@ const mapChargeItems = fp.flow(
|
|||
);
|
||||
|
||||
expect(new LongLongLongLongLongRange([0, 0], [0, 0])).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0]));
|
||||
|
||||
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
|
||||
(allColors, color) => {
|
||||
return allColors.concat(color);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue