Skip to content

Commit dc2037c

Browse files
pietervfacebook-github-bot
authored andcommitted
Switch xplat prettier config to hermes plugin (#37915)
Summary: Pull Request resolved: #37915 Enable the `prettier-plugin-hermes-parser` in xplat. This plugin enables the use of `hermes-parser` which is significantly faster than the current flow parser prettier bundles (improves formatting time by ~50%) and also brings support for the latest Prettier 3.0.0 printing logic for JS. This upgrade is required in order to enable upcoming Flow features that add new syntax. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D46748891 fbshipit-source-id: 3775ef9afa7c04e565fa4fcf8ca5b410f49d35a1
1 parent 54a5ff9 commit dc2037c

File tree

14 files changed

+103
-67
lines changed

14 files changed

+103
-67
lines changed

.prettierrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@
55
"requirePragma": true,
66
"singleQuote": true,
77
"trailingComma": "all",
8-
"endOfLine": "lf"
8+
"endOfLine": "lf",
9+
"overrides": [
10+
{
11+
"files": [
12+
"*.js"
13+
],
14+
"options": {
15+
"parser": "hermes"
16+
}
17+
}
18+
]
919
}

jest/preprocessor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ module.exports = {
8989
);
9090
},
9191

92-
getCacheKey: (createCacheKeyFunction([
92+
// $FlowFixMe[signature-verification-failure]
93+
getCacheKey: createCacheKeyFunction([
9394
__filename,
9495
require.resolve('metro-react-native-babel-transformer'),
9596
require.resolve('@babel/core/package.json'),
96-
]) /*: any */),
97+
]),
9798
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"mkdirp": "^0.5.1",
9191
"mock-fs": "^5.1.4",
9292
"prettier": "2.8.8",
93+
"prettier-plugin-hermes-parser": "0.12.1",
9394
"react": "18.2.0",
9495
"react-test-renderer": "18.2.0",
9596
"shelljs": "^0.8.5",

packages/react-native/Libraries/Animated/nodes/AnimatedValueXY.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ import invariant from 'invariant';
1919
export type AnimatedValueXYConfig = $ReadOnly<{
2020
useNativeDriver: boolean,
2121
}>;
22-
type ValueXYListenerCallback = (value: {
23-
x: number,
24-
y: number,
25-
...
26-
}) => mixed;
22+
type ValueXYListenerCallback = (value: {x: number, y: number, ...}) => mixed;
2723

2824
let _uniqueId = 1;
2925

@@ -135,11 +131,7 @@ export default class AnimatedValueXY extends AnimatedWithChildren {
135131
* See https://reactnative.dev/docs/animatedvaluexy#resetanimation
136132
*/
137133
resetAnimation(
138-
callback?: (value: {
139-
x: number,
140-
y: number,
141-
...
142-
}) => void,
134+
callback?: (value: {x: number, y: number, ...}) => void,
143135
): void {
144136
this.x.resetAnimation();
145137
this.y.resetAnimation();
@@ -153,13 +145,7 @@ export default class AnimatedValueXY extends AnimatedWithChildren {
153145
*
154146
* See https://reactnative.dev/docs/animatedvaluexy#stopanimation
155147
*/
156-
stopAnimation(
157-
callback?: (value: {
158-
x: number,
159-
y: number,
160-
...
161-
}) => void,
162-
): void {
148+
stopAnimation(callback?: (value: {x: number, y: number, ...}) => void): void {
163149
this.x.stopAnimation();
164150
this.y.stopAnimation();
165151
callback && callback(this.__getValue());

packages/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,18 @@ const ScrollViewStickyHeaderWithForwardedRef: React.AbstractComponent<
246246
clearTimeout(_timer.current);
247247
}
248248
};
249-
}, [nextHeaderLayoutY, measured, layoutHeight, layoutY, scrollViewHeight, scrollAnimatedValue, inverted, offset, animatedValueListener, isFabric]);
249+
}, [
250+
nextHeaderLayoutY,
251+
measured,
252+
layoutHeight,
253+
layoutY,
254+
scrollViewHeight,
255+
scrollAnimatedValue,
256+
inverted,
257+
offset,
258+
animatedValueListener,
259+
isFabric,
260+
]);
250261

251262
const _onLayout = (event: LayoutEvent) => {
252263
setLayoutY(event.nativeEvent.layout.y);

packages/react-native/Libraries/Core/setUpRegeneratorRuntime.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ let hasNativeGenerator;
2222
try {
2323
// If this function was lowered by regenerator-transform, it will try to
2424
// access `global.regeneratorRuntime` which doesn't exist yet and will throw.
25-
hasNativeGenerator = hasNativeConstructor(function* () {},
26-
'GeneratorFunction');
25+
hasNativeGenerator = hasNativeConstructor(
26+
function* () {},
27+
'GeneratorFunction',
28+
);
2729
} catch {
2830
// In this case, we know generators are not provided natively.
2931
hasNativeGenerator = false;

packages/react-native/Libraries/Interaction/JSEventLoopWatchdog.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ const infoLog = require('../Utilities/infoLog');
1414

1515
type Handler = {
1616
onIterate?: () => void,
17-
onStall: (params: {
18-
lastInterval: number,
19-
busyTime: number,
20-
...
21-
}) => ?string,
17+
onStall: (params: {lastInterval: number, busyTime: number, ...}) => ?string,
2218
...
2319
};
2420

packages/react-native/Libraries/LogBox/UI/LogBoxInspectorHeader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const backgroundForLevel = (level: LogLevel) =>
8888
default: 'transparent',
8989
pressed: LogBoxStyle.getFatalDarkColor(),
9090
},
91-
}[level]);
91+
})[level];
9292

9393
function LogBoxInspectorHeaderButton(
9494
props: $ReadOnly<{|

packages/react-native/cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ async function main() {
5656
if (latest !== currentVersion) {
5757
const msg = `
5858
${chalk.bold.yellow('WARNING:')} You should run ${chalk.white.bold(
59-
'npx react-native@latest',
60-
)} to ensure you're always using the most current version of the CLI. NPX has cached version (${chalk.bold.yellow(
61-
currentVersion,
62-
)}) != current release (${chalk.bold.green(latest)})
59+
'npx react-native@latest',
60+
)} to ensure you're always using the most current version of the CLI. NPX has cached version (${chalk.bold.yellow(
61+
currentVersion,
62+
)}) != current release (${chalk.bold.green(latest)})
6363
`;
6464
console.warn(msg);
6565
}

packages/rn-tester/js/examples/Experimental/W3CPointerEventPlatformTests/PointerEventAttributesHoverablePointers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ function PointerEventAttributesHoverablePointersTestCase(
6767
testNamePrefix + ' ' + expectedPointerType + ' ' + expectedEventType;
6868

6969
detected_pointertypes[event.nativeEvent.pointerType] = true;
70-
harness.test(({assert_equals}) => {
71-
assert_equals(
72-
eventType,
73-
expectedEventType,
74-
'Event.type should be ' + expectedEventType,
75-
);
76-
}, pointerTestName + "'s type should be " + expectedEventType);
70+
harness.test(
71+
({assert_equals}) => {
72+
assert_equals(
73+
eventType,
74+
expectedEventType,
75+
'Event.type should be ' + expectedEventType,
76+
);
77+
},
78+
pointerTestName + "'s type should be " + expectedEventType,
79+
);
7780

7881
// Test button and buttons
7982
if (eventType === 'pointerdown') {

0 commit comments

Comments
 (0)