Skip to content

Commit 2c3a00b

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Use the prettier config at the root for react-native-codegen (#52746)
Summary: Pull Request resolved: #52746 The config is needed for build, so I renamed it. In this way, the formatting of js code in react-native repo will be consistently controlled by the prettier config in the root. This change will make prettier v3 upgrade easier. Changelog: [Internal] Reviewed By: pieterv Differential Revision: D78700564 fbshipit-source-id: 392ed490bf814870f285c8372ff68b454e228802
1 parent 7970ee9 commit 2c3a00b

11 files changed

Lines changed: 106 additions & 106 deletions

File tree

File renamed without changes.

packages/react-native-codegen/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const prettier = require('prettier');
3232
const {styleText} = require('util');
3333

3434
const prettierConfig = JSON.parse(
35-
fs.readFileSync(path.resolve(__dirname, '..', '.prettierrc'), 'utf8'),
35+
fs.readFileSync(path.resolve(__dirname, '..', 'build.prettierrc'), 'utf8'),
3636
);
3737

3838
const SRC_DIR = 'src';

packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ const HostFunctionTemplate = ({
4747
isVoid
4848
? `\n ${methodCall};`
4949
: isNullable
50-
? `\n auto result = ${methodCall};`
51-
: ''
50+
? `\n auto result = ${methodCall};`
51+
: ''
5252
}
5353
return ${
5454
isVoid
5555
? 'jsi::Value::undefined()'
5656
: isNullable
57-
? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()'
58-
: methodCall
57+
? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()'
58+
: methodCall
5959
};
6060
}`;
6161
};

packages/react-native-codegen/src/generators/modules/GenerateModuleH.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,17 +572,17 @@ function translateEventEmitterToCpp(
572572
${
573573
isVoidTypeAnnotation ? '' : `template <typename ${templateName}> `
574574
}void emit${toPascalCase(eventEmitter.name)}(${
575-
isVoidTypeAnnotation
576-
? ''
577-
: `${isArray ? `std::vector<${templateName}>` : templateName} value`
578-
}) {${
579-
isVoidTypeAnnotation
580-
? ''
581-
: `
575+
isVoidTypeAnnotation
576+
? ''
577+
: `${isArray ? `std::vector<${templateName}>` : templateName} value`
578+
}) {${
579+
isVoidTypeAnnotation
580+
? ''
581+
: `
582582
static_assert(bridging::supportsFromJs<${
583583
isArray ? `std::vector<${templateName}>` : templateName
584584
}, ${jsiType}>, "value cannnot be converted to ${jsiType}");`
585-
}
585+
}
586586
static_cast<AsyncEventEmitter<${
587587
isVoidTypeAnnotation ? '' : 'jsi::Value'
588588
}>&>(*delegate_.eventEmitterMap_["${eventEmitter.name}"]).emit(${

packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ function EventEmitterTemplate(
8484
: ''
8585
}) {
8686
mEventEmitterCallback.invoke("${eventEmitter.name}"${
87-
eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation'
88-
? ', value'
89-
: ''
90-
});
87+
eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation'
88+
? ', value'
89+
: ''
90+
});
9191
}`;
9292
}
9393

@@ -113,8 +113,8 @@ function MethodTemplate(
113113
const methodClosing = abstract
114114
? ';'
115115
: methodBody != null && methodBody.length > 0
116-
? ` { ${methodBody} }`
117-
: ' {}';
116+
? ` { ${methodBody} }`
117+
: ' {}';
118118
return ` ${methodJavaAnnotation}
119119
public ${methodQualifier}${translatedReturnType} ${methodName}(${traversedArgs.join(
120120
', ',

packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ namespace facebook::react {
7474
}),
7575
)
7676
.join('\n' + ' '.repeat(8))}${
77-
eventEmitters.length > 0
78-
? eventEmitters
79-
.map(eventEmitter => {
80-
return `
77+
eventEmitters.length > 0
78+
? eventEmitters
79+
.map(eventEmitter => {
80+
return `
8181
eventEmitterMap_["${eventEmitter.name}"] = std::make_shared<AsyncEventEmitter<id>>();`;
82-
})
83-
.join('')
84-
: ''
85-
}${
86-
eventEmitters.length > 0
87-
? `
82+
})
83+
.join('')
84+
: ''
85+
}${
86+
eventEmitters.length > 0
87+
? `
8888
setEventEmitterCallback([&](const std::string &name, id value) {
8989
static_cast<AsyncEventEmitter<id> &>(*eventEmitterMap_[name]).emit(value);
9090
});`
91-
: ''
92-
}
91+
: ''
92+
}
9393
}
9494
} // namespace facebook::react`;
9595

packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ describe('Flow Module Parser', () => {
116116
nullable && optional
117117
? 'a nullable and optional'
118118
: nullable
119-
? 'a nullable'
120-
: optional
121-
? 'an optional'
122-
: 'a required';
119+
? 'a nullable'
120+
: optional
121+
? 'an optional'
122+
: 'a required';
123123

124124
function annotateArg(paramName: string, paramType: string) {
125125
if (nullable && optional) {
@@ -167,10 +167,10 @@ describe('Flow Module Parser', () => {
167167
(nullable && optional
168168
? 'Nullable and Optional'
169169
: nullable
170-
? 'Nullable'
171-
: optional
172-
? 'Optional'
173-
: 'Required') + ' Parameter',
170+
? 'Nullable'
171+
: optional
172+
? 'Optional'
173+
: 'Required') + ' Parameter',
174174
() => {
175175
it(`should not parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Function'`, () => {
176176
expect(() => parseParamType('arg', 'Function')).toThrow(
@@ -397,10 +397,10 @@ describe('Flow Module Parser', () => {
397397
isPropNullable && isPropOptional
398398
? 'a nullable and optional'
399399
: isPropNullable
400-
? 'a nullable'
401-
: isPropOptional
402-
? 'an optional'
403-
: 'a required';
400+
? 'a nullable'
401+
: isPropOptional
402+
? 'an optional'
403+
: 'a required';
404404

405405
function annotateProp(propName: string, propType: string) {
406406
if (isPropNullable && isPropOptional) {
@@ -465,10 +465,10 @@ describe('Flow Module Parser', () => {
465465
(isPropNullable && isPropOptional
466466
? 'Nullable and Optional'
467467
: isPropNullable
468-
? 'Nullable'
469-
: isPropOptional
470-
? 'Optional'
471-
: 'Required') + ' Property',
468+
? 'Nullable'
469+
: isPropOptional
470+
? 'Optional'
471+
: 'Required') + ' Property',
472472
() => {
473473
describe('Props with Primitive Types', () => {
474474
PRIMITIVES.forEach(([FLOW_TYPE, PARSED_TYPE_NAME]) => {
@@ -932,10 +932,10 @@ describe('Flow Module Parser', () => {
932932
nullable && optional
933933
? 'a nullable and optional'
934934
: nullable
935-
? 'a nullable'
936-
: optional
937-
? 'an optional'
938-
: 'a required';
935+
? 'a nullable'
936+
: optional
937+
? 'an optional'
938+
: 'a required';
939939

940940
function annotateProp(propName: string, propType: string) {
941941
if (nullable && optional) {
@@ -1001,10 +1001,10 @@ describe('Flow Module Parser', () => {
10011001
(nullable && optional
10021002
? 'Nullable and Optional'
10031003
: nullable
1004-
? 'Nullable'
1005-
: optional
1006-
? 'Optional'
1007-
: 'Required') + ' Property',
1004+
? 'Nullable'
1005+
: optional
1006+
? 'Optional'
1007+
: 'Required') + ' Property',
10081008
() => {
10091009
/**
10101010
* TODO: Fill out props in promise

packages/react-native-codegen/src/parsers/flow/parser.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ class FlowParser implements Parser {
187187
typeAnnotation.type === 'EnumStringBody'
188188
? 'StringTypeAnnotation'
189189
: typeAnnotation.type === 'EnumNumberBody'
190-
? 'NumberTypeAnnotation'
191-
: null;
190+
? 'NumberTypeAnnotation'
191+
: null;
192192
if (!enumMembersType) {
193193
throw new Error(
194194
`Unknown enum type annotation type. Got: ${typeAnnotation.type}. Expected: EnumStringBody or EnumNumberBody.`,
@@ -242,14 +242,14 @@ class FlowParser implements Parser {
242242
value: member.init.value,
243243
}
244244
: typeof member.init?.value === 'string'
245-
? {
246-
type: 'StringLiteralTypeAnnotation',
247-
value: member.init.value,
248-
}
249-
: {
250-
type: 'StringLiteralTypeAnnotation',
251-
value: member.id.name,
252-
};
245+
? {
246+
type: 'StringLiteralTypeAnnotation',
247+
value: member.init.value,
248+
}
249+
: {
250+
type: 'StringLiteralTypeAnnotation',
251+
value: member.id.name,
252+
};
253253

254254
return {
255255
name: member.id.name,

packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ function setDefaultValue(
353353
common.default = ((defaultValue === null
354354
? null
355355
: defaultValue
356-
? defaultValue
357-
: 0): number | null);
356+
? defaultValue
357+
: 0): number | null);
358358
break;
359359
case 'BooleanTypeAnnotation':
360360
common.default = defaultValue === null ? null : !!defaultValue;

packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ describe('TypeScript Module Parser', () => {
192192
nullable && optional
193193
? 'a nullable and optional'
194194
: nullable
195-
? 'a nullable'
196-
: optional
197-
? 'an optional'
198-
: 'a required';
195+
? 'a nullable'
196+
: optional
197+
? 'an optional'
198+
: 'a required';
199199

200200
function annotateArg(paramName: string, paramType: string) {
201201
if (nullable && optional) {
@@ -243,10 +243,10 @@ describe('TypeScript Module Parser', () => {
243243
(nullable && optional
244244
? 'Nullable and Optional'
245245
: nullable
246-
? 'Nullable'
247-
: optional
248-
? 'Optional'
249-
: 'Required') + ' Parameter',
246+
? 'Nullable'
247+
: optional
248+
? 'Optional'
249+
: 'Required') + ' Parameter',
250250
() => {
251251
it(`should not parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Function'`, () => {
252252
expect(() => parseParamType('arg', 'Function')).toThrow(
@@ -473,10 +473,10 @@ describe('TypeScript Module Parser', () => {
473473
isPropNullable && isPropOptional
474474
? 'a nullable and optional'
475475
: isPropNullable
476-
? 'a nullable'
477-
: isPropOptional
478-
? 'an optional'
479-
: 'a required';
476+
? 'a nullable'
477+
: isPropOptional
478+
? 'an optional'
479+
: 'a required';
480480

481481
function annotateProp(propName: string, propType: string) {
482482
if (isPropNullable && isPropOptional) {
@@ -541,10 +541,10 @@ describe('TypeScript Module Parser', () => {
541541
(isPropNullable && isPropOptional
542542
? 'Nullable and Optional'
543543
: isPropNullable
544-
? 'Nullable'
545-
: isPropOptional
546-
? 'Optional'
547-
: 'Required') + ' Property',
544+
? 'Nullable'
545+
: isPropOptional
546+
? 'Optional'
547+
: 'Required') + ' Property',
548548
() => {
549549
describe('Props with Primitive Types', () => {
550550
PRIMITIVES.forEach(([FLOW_TYPE, PARSED_TYPE_NAME]) => {
@@ -1007,10 +1007,10 @@ describe('TypeScript Module Parser', () => {
10071007
nullable && optional
10081008
? 'a nullable and optional'
10091009
: nullable
1010-
? 'a nullable'
1011-
: optional
1012-
? 'an optional'
1013-
: 'a required';
1010+
? 'a nullable'
1011+
: optional
1012+
? 'an optional'
1013+
: 'a required';
10141014

10151015
function annotateProp(propName: string, propType: string) {
10161016
if (nullable && optional) {
@@ -1076,10 +1076,10 @@ describe('TypeScript Module Parser', () => {
10761076
(nullable && optional
10771077
? 'Nullable and Optional'
10781078
: nullable
1079-
? 'Nullable'
1080-
: optional
1081-
? 'Optional'
1082-
: 'Required') + ' Property',
1079+
? 'Nullable'
1080+
: optional
1081+
? 'Optional'
1082+
: 'Required') + ' Property',
10831083
() => {
10841084
/**
10851085
* TODO: Fill out props in promise

0 commit comments

Comments
 (0)