Skip to content

Commit

Permalink
RN: Follow-up Format w/ Prettier v2.x
Browse files Browse the repository at this point in the history
Summary:
When I upgraded React Native to Prettier v2.x, I removed `format` from a few files to reduce the number of changes.

This is a follow-up to bring back `format` and fix any remaining issues.

Changelog:
[Internal]

Reviewed By: zertosh

Differential Revision: D32287259

fbshipit-source-id: 37ea6d2c973b1db5d37c46d73675bdf436fb9a9d
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 9, 2021
1 parent cf763cd commit 10f9ab4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 68 deletions.
16 changes: 7 additions & 9 deletions Libraries/BatchedBridge/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @noformat
* @format
*/

'use strict';
Expand Down Expand Up @@ -72,19 +72,17 @@ class MessageQueue {
}

// $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.callFunctionReturnFlushedQueue = this.callFunctionReturnFlushedQueue.bind(
this,
);
this.callFunctionReturnFlushedQueue =
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.callFunctionReturnFlushedQueue.bind(this);
// $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.flushedQueue = this.flushedQueue.bind(this);

// $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.invokeCallbackAndReturnFlushedQueue = this.invokeCallbackAndReturnFlushedQueue.bind(
this,
);
this.invokeCallbackAndReturnFlushedQueue =
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.invokeCallbackAndReturnFlushedQueue.bind(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @noformat
* @format
*/

const React = require('react');
Expand Down Expand Up @@ -100,7 +100,8 @@ const ProgressBarAndroid = (

const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid);

/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
module.exports = (ProgressBarAndroidToExport: typeof ProgressBarAndroidNativeComponent);
module.exports =
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
(ProgressBarAndroidToExport: typeof ProgressBarAndroidNativeComponent);
17 changes: 8 additions & 9 deletions Libraries/Utilities/ReactNativeTestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow
* @noformat
* @format
*/

/* eslint-env jest */
Expand All @@ -26,13 +26,14 @@ export type ReactTestInstance = $PropertyType<ReactTestRendererType, 'root'>;
export type Predicate = (node: ReactTestInstance) => boolean;

type $ReturnType<Fn> = $Call<<Ret, A>((...A) => Ret) => Ret, Fn>;
/* $FlowFixMe[prop-missing] (>=0.125.1 site=react_native_fb) This comment
* suppresses an error found when Flow v0.125.1 was deployed. To see the error,
* delete this comment and run Flow. */
/* $FlowFixMe[value-as-type] (>=0.125.1 site=react_native_fb) This comment
* suppresses an error found when Flow v0.125.1 was deployed. To see the error,
* delete this comment and run Flow. */
export type ReactTestRendererJSON = $ReturnType<ReactTestRenderer.create.toJSON>;
export type ReactTestRendererJSON =
/* $FlowFixMe[prop-missing] (>=0.125.1 site=react_native_fb) This comment
* suppresses an error found when Flow v0.125.1 was deployed. To see the error,
* delete this comment and run Flow. */
$ReturnType<ReactTestRenderer.create.toJSON>;

const {
Switch,
Expand Down Expand Up @@ -199,10 +200,8 @@ function tap(instance: ReactTestInstance) {
} else if (
touchable?.props?.onStartShouldSetResponder?.testOnly_pressabilityConfig
) {
const {
onPress,
disabled,
} = touchable.props.onStartShouldSetResponder.testOnly_pressabilityConfig();
const {onPress, disabled} =
touchable.props.onStartShouldSetResponder.testOnly_pressabilityConfig();
if (!disabled) {
onPress({nativeEvent: {}});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/polyfills/Object.es8.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noformat
* @format
* @polyfill
* @nolint
*/

(function() {
(function () {
'use strict';

const hasOwnProperty = Object.prototype.hasOwnProperty;
Expand All @@ -19,7 +19,7 @@
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
*/
if (typeof Object.entries !== 'function') {
Object.entries = function(object) {
Object.entries = function (object) {
// `null` and `undefined` values are not allowed.
if (object == null) {
throw new TypeError('Object.entries called on non-object');
Expand All @@ -40,7 +40,7 @@
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
*/
if (typeof Object.values !== 'function') {
Object.values = function(object) {
Object.values = function (object) {
// `null` and `undefined` values are not allowed.
if (object == null) {
throw new TypeError('Object.values called on non-object');
Expand Down
32 changes: 16 additions & 16 deletions packages/polyfills/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @polyfill
* @nolint
* @noformat
* @format
*/

/* eslint-disable no-shadow, eqeqeq, curly, no-unused-vars, no-void, no-control-regex */
Expand All @@ -15,7 +15,7 @@
* This pipes all of our console logging functions to native logging so that
* JavaScript errors in required modules show up in Xcode via NSLog.
*/
const inspect = (function() {
const inspect = (function () {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -55,7 +55,7 @@ const inspect = (function() {
function arrayToHash(array) {
var hash = {};

array.forEach(function(val, idx) {
array.forEach(function (val, idx) {
hash[val] = true;
});

Expand Down Expand Up @@ -153,7 +153,7 @@ const inspect = (function() {
if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else {
output = keys.map(function(key) {
output = keys.map(function (key) {
return formatProperty(
ctx,
value,
Expand Down Expand Up @@ -210,7 +210,7 @@ const inspect = (function() {
output.push('');
}
}
keys.forEach(function(key) {
keys.forEach(function (key) {
if (!key.match(/^\d+$/)) {
output.push(
formatProperty(ctx, value, recurseTimes, visibleKeys, key, true),
Expand Down Expand Up @@ -248,7 +248,7 @@ const inspect = (function() {
if (array) {
str = str
.split('\n')
.map(function(line) {
.map(function (line) {
return ' ' + line;
})
.join('\n')
Expand All @@ -258,7 +258,7 @@ const inspect = (function() {
'\n' +
str
.split('\n')
.map(function(line) {
.map(function (line) {
return ' ' + line;
})
.join('\n');
Expand Down Expand Up @@ -290,7 +290,7 @@ const inspect = (function() {

function reduceToSingleString(output, base, braces) {
var numLinesEst = 0;
var length = output.reduce(function(prev, cur) {
var length = output.reduce(function (prev, cur) {
numLinesEst++;
if (cur.indexOf('\n') >= 0) numLinesEst++;
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
Expand Down Expand Up @@ -396,13 +396,13 @@ INSPECTOR_LEVELS[LOG_LEVELS.error] = 'error';
const INSPECTOR_FRAMES_TO_SKIP = __DEV__ ? 2 : 1;

function getNativeLogFunction(level) {
return function() {
return function () {
let str;
if (arguments.length === 1 && typeof arguments[0] === 'string') {
str = arguments[0];
} else {
str = Array.prototype.map
.call(arguments, function(arg) {
.call(arguments, function (arg) {
return inspect(arg, {depth: 10});
})
.join(', ');
Expand Down Expand Up @@ -443,7 +443,7 @@ function getNativeLogFunction(level) {
}

function repeat(element, n) {
return Array.apply(null, Array(n)).map(function() {
return Array.apply(null, Array(n)).map(function () {
return element;
});
}
Expand Down Expand Up @@ -472,7 +472,7 @@ function consoleTablePolyfill(rows) {

// Convert each cell to a string. Also
// figure out max cell width for each column
columns.forEach(function(k, i) {
columns.forEach(function (k, i) {
columnWidths[i] = k.length;
for (var j = 0; j < rows.length; j++) {
var cellStr = (rows[j][k] || '?').toString();
Expand All @@ -485,15 +485,15 @@ function consoleTablePolyfill(rows) {
// Join all elements in the row into a single string with | separators
// (appends extra spaces to each cell to make separators | aligned)
function joinRow(row, space) {
var cells = row.map(function(cell, i) {
var cells = row.map(function (cell, i) {
var extraSpaces = repeat(' ', columnWidths[i] - cell.length).join('');
return cell + extraSpaces;
});
space = space || ' ';
return cells.join(space + '|' + space);
}

var separators = columnWidths.map(function(columnWidth) {
var separators = columnWidths.map(function (columnWidth) {
return repeat('-', columnWidth).join('');
});
var separatorRow = joinRow(separators, '-');
Expand Down Expand Up @@ -579,7 +579,7 @@ if (global.nativeLoggingHook) {
Object.keys(console).forEach(methodName => {
const reactNativeMethod = console[methodName];
if (originalConsole[methodName]) {
console[methodName] = function() {
console[methodName] = function () {
originalConsole[methodName](...arguments);
reactNativeMethod.apply(console, arguments);
};
Expand All @@ -591,7 +591,7 @@ if (global.nativeLoggingHook) {
// supported by it.
['clear', 'dir', 'dirxml', 'profile', 'profileEnd'].forEach(methodName => {
if (typeof originalConsole[methodName] === 'function') {
console[methodName] = function() {
console[methodName] = function () {
originalConsole[methodName](...arguments);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @noformat
* @format
*/

'use strict';
Expand Down Expand Up @@ -100,10 +100,8 @@ function translateFunctionParamToJavaType(
imports: Set<string>,
): string {
const {optional, typeAnnotation: nullableTypeAnnotation} = param;
const [
typeAnnotation,
nullable,
] = unwrapNullable<NativeModuleParamTypeAnnotation>(nullableTypeAnnotation);
const [typeAnnotation, nullable] =
unwrapNullable<NativeModuleParamTypeAnnotation>(nullableTypeAnnotation);
const isRequired = !optional && !nullable;

function wrapIntoNullableIfNeeded(generatedType: string) {
Expand Down Expand Up @@ -169,12 +167,10 @@ function translateFunctionReturnTypeToJavaType(
resolveAlias: AliasResolver,
imports: Set<string>,
): string {
const [
returnTypeAnnotation,
nullable,
] = unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullableReturnTypeAnnotation,
);
const [returnTypeAnnotation, nullable] =
unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullableReturnTypeAnnotation,
);

function wrapIntoNullableIfNeeded(generatedType: string) {
if (nullable) {
Expand Down Expand Up @@ -234,12 +230,10 @@ function getFalsyReturnStatementFromReturnType(
createErrorMessage: (typeName: string) => string,
resolveAlias: AliasResolver,
): string {
const [
returnTypeAnnotation,
nullable,
] = unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullableReturnTypeAnnotation,
);
const [returnTypeAnnotation, nullable] =
unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullableReturnTypeAnnotation,
);

let realTypeAnnotation = returnTypeAnnotation;
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
Expand Down Expand Up @@ -288,9 +282,8 @@ function buildGetConstantsMethod(
method: NativeModulePropertyShape,
imports: Set<string>,
): string {
const [
methodTypeAnnotation,
] = unwrapNullable<NativeModuleFunctionTypeAnnotation>(method.typeAnnotation);
const [methodTypeAnnotation] =
unwrapNullable<NativeModuleFunctionTypeAnnotation>(method.typeAnnotation);
if (
methodTypeAnnotation.returnTypeAnnotation.type === 'ObjectTypeAnnotation'
) {
Expand Down Expand Up @@ -405,11 +398,10 @@ module.exports = {
return buildGetConstantsMethod(method, imports);
}

const [
methodTypeAnnotation,
] = unwrapNullable<NativeModuleFunctionTypeAnnotation>(
method.typeAnnotation,
);
const [methodTypeAnnotation] =
unwrapNullable<NativeModuleFunctionTypeAnnotation>(
method.typeAnnotation,
);

// Handle return type
const translatedReturnType = translateFunctionReturnTypeToJavaType(
Expand Down

0 comments on commit 10f9ab4

Please sign in to comment.