diff --git a/packages/react-native-codegen/.prettierrc b/packages/react-native-codegen/build.prettierrc similarity index 100% rename from packages/react-native-codegen/.prettierrc rename to packages/react-native-codegen/build.prettierrc diff --git a/packages/react-native-codegen/scripts/build.js b/packages/react-native-codegen/scripts/build.js index 862ccdd7598..16a70ff7036 100644 --- a/packages/react-native-codegen/scripts/build.js +++ b/packages/react-native-codegen/scripts/build.js @@ -32,7 +32,7 @@ const prettier = require('prettier'); const {styleText} = require('util'); const prettierConfig = JSON.parse( - fs.readFileSync(path.resolve(__dirname, '..', '.prettierrc'), 'utf8'), + fs.readFileSync(path.resolve(__dirname, '..', 'build.prettierrc'), 'utf8'), ); const SRC_DIR = 'src'; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js index 3c4e9b4fe9f..e26b789740b 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js @@ -47,15 +47,15 @@ const HostFunctionTemplate = ({ isVoid ? `\n ${methodCall};` : isNullable - ? `\n auto result = ${methodCall};` - : '' + ? `\n auto result = ${methodCall};` + : '' } return ${ isVoid ? 'jsi::Value::undefined()' : isNullable - ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' - : methodCall + ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' + : methodCall }; }`; }; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index 9537f4f044b..2e666347e51 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -572,17 +572,17 @@ function translateEventEmitterToCpp( ${ isVoidTypeAnnotation ? '' : `template ` }void emit${toPascalCase(eventEmitter.name)}(${ - isVoidTypeAnnotation - ? '' - : `${isArray ? `std::vector<${templateName}>` : templateName} value` - }) {${ - isVoidTypeAnnotation - ? '' - : ` + isVoidTypeAnnotation + ? '' + : `${isArray ? `std::vector<${templateName}>` : templateName} value` + }) {${ + isVoidTypeAnnotation + ? '' + : ` static_assert(bridging::supportsFromJs<${ isArray ? `std::vector<${templateName}>` : templateName }, ${jsiType}>, "value cannnot be converted to ${jsiType}");` - } + } static_cast&>(*delegate_.eventEmitterMap_["${eventEmitter.name}"]).emit(${ diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 8ff63e8c994..e634125797c 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -84,10 +84,10 @@ function EventEmitterTemplate( : '' }) { mEventEmitterCallback.invoke("${eventEmitter.name}"${ - eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation' - ? ', value' - : '' - }); + eventEmitter.typeAnnotation.typeAnnotation.type !== 'VoidTypeAnnotation' + ? ', value' + : '' + }); }`; } @@ -113,8 +113,8 @@ function MethodTemplate( const methodClosing = abstract ? ';' : methodBody != null && methodBody.length > 0 - ? ` { ${methodBody} }` - : ' {}'; + ? ` { ${methodBody} }` + : ' {}'; return ` ${methodJavaAnnotation} public ${methodQualifier}${translatedReturnType} ${methodName}(${traversedArgs.join( ', ', diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js index 10e3c2eeec9..d4b80dcb054 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js @@ -74,22 +74,22 @@ namespace facebook::react { }), ) .join('\n' + ' '.repeat(8))}${ - eventEmitters.length > 0 - ? eventEmitters - .map(eventEmitter => { - return ` + eventEmitters.length > 0 + ? eventEmitters + .map(eventEmitter => { + return ` eventEmitterMap_["${eventEmitter.name}"] = std::make_shared>();`; - }) - .join('') - : '' -}${ - eventEmitters.length > 0 - ? ` + }) + .join('') + : '' + }${ + eventEmitters.length > 0 + ? ` setEventEmitterCallback([&](const std::string &name, id value) { static_cast &>(*eventEmitterMap_[name]).emit(value); });` - : '' -} + : '' + } } } // namespace facebook::react`; diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js index 66b5dfc975d..edfb10de5b0 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js @@ -116,10 +116,10 @@ describe('Flow Module Parser', () => { nullable && optional ? 'a nullable and optional' : nullable - ? 'a nullable' - : optional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : optional + ? 'an optional' + : 'a required'; function annotateArg(paramName: string, paramType: string) { if (nullable && optional) { @@ -167,10 +167,10 @@ describe('Flow Module Parser', () => { (nullable && optional ? 'Nullable and Optional' : nullable - ? 'Nullable' - : optional - ? 'Optional' - : 'Required') + ' Parameter', + ? 'Nullable' + : optional + ? 'Optional' + : 'Required') + ' Parameter', () => { it(`should not parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Function'`, () => { expect(() => parseParamType('arg', 'Function')).toThrow( @@ -397,10 +397,10 @@ describe('Flow Module Parser', () => { isPropNullable && isPropOptional ? 'a nullable and optional' : isPropNullable - ? 'a nullable' - : isPropOptional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : isPropOptional + ? 'an optional' + : 'a required'; function annotateProp(propName: string, propType: string) { if (isPropNullable && isPropOptional) { @@ -465,10 +465,10 @@ describe('Flow Module Parser', () => { (isPropNullable && isPropOptional ? 'Nullable and Optional' : isPropNullable - ? 'Nullable' - : isPropOptional - ? 'Optional' - : 'Required') + ' Property', + ? 'Nullable' + : isPropOptional + ? 'Optional' + : 'Required') + ' Property', () => { describe('Props with Primitive Types', () => { PRIMITIVES.forEach(([FLOW_TYPE, PARSED_TYPE_NAME]) => { @@ -932,10 +932,10 @@ describe('Flow Module Parser', () => { nullable && optional ? 'a nullable and optional' : nullable - ? 'a nullable' - : optional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : optional + ? 'an optional' + : 'a required'; function annotateProp(propName: string, propType: string) { if (nullable && optional) { @@ -1001,10 +1001,10 @@ describe('Flow Module Parser', () => { (nullable && optional ? 'Nullable and Optional' : nullable - ? 'Nullable' - : optional - ? 'Optional' - : 'Required') + ' Property', + ? 'Nullable' + : optional + ? 'Optional' + : 'Required') + ' Property', () => { /** * TODO: Fill out props in promise diff --git a/packages/react-native-codegen/src/parsers/flow/parser.js b/packages/react-native-codegen/src/parsers/flow/parser.js index 4369892edab..c8224d4e44e 100644 --- a/packages/react-native-codegen/src/parsers/flow/parser.js +++ b/packages/react-native-codegen/src/parsers/flow/parser.js @@ -187,8 +187,8 @@ class FlowParser implements Parser { typeAnnotation.type === 'EnumStringBody' ? 'StringTypeAnnotation' : typeAnnotation.type === 'EnumNumberBody' - ? 'NumberTypeAnnotation' - : null; + ? 'NumberTypeAnnotation' + : null; if (!enumMembersType) { throw new Error( `Unknown enum type annotation type. Got: ${typeAnnotation.type}. Expected: EnumStringBody or EnumNumberBody.`, @@ -242,14 +242,14 @@ class FlowParser implements Parser { value: member.init.value, } : typeof member.init?.value === 'string' - ? { - type: 'StringLiteralTypeAnnotation', - value: member.init.value, - } - : { - type: 'StringLiteralTypeAnnotation', - value: member.id.name, - }; + ? { + type: 'StringLiteralTypeAnnotation', + value: member.init.value, + } + : { + type: 'StringLiteralTypeAnnotation', + value: member.id.name, + }; return { name: member.id.name, diff --git a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js index e74f03572cc..f178527433c 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js @@ -353,8 +353,8 @@ function setDefaultValue( common.default = ((defaultValue === null ? null : defaultValue - ? defaultValue - : 0): number | null); + ? defaultValue + : 0): number | null); break; case 'BooleanTypeAnnotation': common.default = defaultValue === null ? null : !!defaultValue; diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js index e1f260be8c3..6f0eeeb6b55 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js @@ -192,10 +192,10 @@ describe('TypeScript Module Parser', () => { nullable && optional ? 'a nullable and optional' : nullable - ? 'a nullable' - : optional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : optional + ? 'an optional' + : 'a required'; function annotateArg(paramName: string, paramType: string) { if (nullable && optional) { @@ -243,10 +243,10 @@ describe('TypeScript Module Parser', () => { (nullable && optional ? 'Nullable and Optional' : nullable - ? 'Nullable' - : optional - ? 'Optional' - : 'Required') + ' Parameter', + ? 'Nullable' + : optional + ? 'Optional' + : 'Required') + ' Parameter', () => { it(`should not parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Function'`, () => { expect(() => parseParamType('arg', 'Function')).toThrow( @@ -473,10 +473,10 @@ describe('TypeScript Module Parser', () => { isPropNullable && isPropOptional ? 'a nullable and optional' : isPropNullable - ? 'a nullable' - : isPropOptional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : isPropOptional + ? 'an optional' + : 'a required'; function annotateProp(propName: string, propType: string) { if (isPropNullable && isPropOptional) { @@ -541,10 +541,10 @@ describe('TypeScript Module Parser', () => { (isPropNullable && isPropOptional ? 'Nullable and Optional' : isPropNullable - ? 'Nullable' - : isPropOptional - ? 'Optional' - : 'Required') + ' Property', + ? 'Nullable' + : isPropOptional + ? 'Optional' + : 'Required') + ' Property', () => { describe('Props with Primitive Types', () => { PRIMITIVES.forEach(([FLOW_TYPE, PARSED_TYPE_NAME]) => { @@ -1007,10 +1007,10 @@ describe('TypeScript Module Parser', () => { nullable && optional ? 'a nullable and optional' : nullable - ? 'a nullable' - : optional - ? 'an optional' - : 'a required'; + ? 'a nullable' + : optional + ? 'an optional' + : 'a required'; function annotateProp(propName: string, propType: string) { if (nullable && optional) { @@ -1076,10 +1076,10 @@ describe('TypeScript Module Parser', () => { (nullable && optional ? 'Nullable and Optional' : nullable - ? 'Nullable' - : optional - ? 'Optional' - : 'Required') + ' Property', + ? 'Nullable' + : optional + ? 'Optional' + : 'Required') + ' Property', () => { /** * TODO: Fill out props in promise diff --git a/packages/react-native-codegen/src/parsers/typescript/parser.js b/packages/react-native-codegen/src/parsers/typescript/parser.js index ca01a904c66..82ac353a5f1 100644 --- a/packages/react-native-codegen/src/parsers/typescript/parser.js +++ b/packages/react-native-codegen/src/parsers/typescript/parser.js @@ -233,8 +233,8 @@ class TypeScriptParser implements Parser { enumMembersType === 'StringTypeAnnotation' ? 'StringLiteral' : enumMembersType === 'NumberTypeAnnotation' - ? 'NumericLiteral' - : null; + ? 'NumericLiteral' + : null; typeAnnotation.members.forEach(member => { const isNegative = @@ -263,19 +263,19 @@ class TypeScriptParser implements Parser { value: -1 * member.initializer?.argument?.value, } : typeof member.initializer?.value === 'number' - ? { - type: 'NumberLiteralTypeAnnotation', - value: member.initializer?.value, - } - : typeof member.initializer?.value === 'string' - ? { - type: 'StringLiteralTypeAnnotation', - value: member.initializer?.value, - } - : { - type: 'StringLiteralTypeAnnotation', - value: member.id.name, - }; + ? { + type: 'NumberLiteralTypeAnnotation', + value: member.initializer?.value, + } + : typeof member.initializer?.value === 'string' + ? { + type: 'StringLiteralTypeAnnotation', + value: member.initializer?.value, + } + : { + type: 'StringLiteralTypeAnnotation', + value: member.id.name, + }; return { name: member.id.name,