RN: Follow-up Format w/ Prettier v2.x

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
This commit is contained in:
Tim Yung 2021-11-09 13:12:59 -08:00 коммит произвёл Facebook GitHub Bot
Родитель cf763cdf81
Коммит 10f9ab4d69
6 изменённых файлов: 58 добавлений и 68 удалений

Просмотреть файл

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow strict * @flow strict
* @noformat * @format
*/ */
'use strict'; 'use strict';
@ -72,19 +72,17 @@ class MessageQueue {
} }
// $FlowFixMe[cannot-write] // $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters this.callFunctionReturnFlushedQueue =
this.callFunctionReturnFlushedQueue = this.callFunctionReturnFlushedQueue.bind( // $FlowFixMe[method-unbinding] added when improving typing for this parameters
this, this.callFunctionReturnFlushedQueue.bind(this);
);
// $FlowFixMe[cannot-write] // $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters // $FlowFixMe[method-unbinding] added when improving typing for this parameters
this.flushedQueue = this.flushedQueue.bind(this); this.flushedQueue = this.flushedQueue.bind(this);
// $FlowFixMe[cannot-write] // $FlowFixMe[cannot-write]
// $FlowFixMe[method-unbinding] added when improving typing for this parameters this.invokeCallbackAndReturnFlushedQueue =
this.invokeCallbackAndReturnFlushedQueue = this.invokeCallbackAndReturnFlushedQueue.bind( // $FlowFixMe[method-unbinding] added when improving typing for this parameters
this, this.invokeCallbackAndReturnFlushedQueue.bind(this);
);
} }
/** /**

Просмотреть файл

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow strict-local * @flow strict-local
* @noformat * @format
*/ */
const React = require('react'); const React = require('react');
@ -100,7 +100,8 @@ const ProgressBarAndroid = (
const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid); const ProgressBarAndroidToExport = React.forwardRef(ProgressBarAndroid);
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an module.exports =
* error found when Flow v0.89 was deployed. To see the error, delete this /* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
* comment and run Flow. */ * error found when Flow v0.89 was deployed. To see the error, delete this
module.exports = (ProgressBarAndroidToExport: typeof ProgressBarAndroidNativeComponent); * comment and run Flow. */
(ProgressBarAndroidToExport: typeof ProgressBarAndroidNativeComponent);

Просмотреть файл

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow * @flow
* @noformat * @format
*/ */
/* eslint-env jest */ /* eslint-env jest */
@ -26,13 +26,14 @@ export type ReactTestInstance = $PropertyType<ReactTestRendererType, 'root'>;
export type Predicate = (node: ReactTestInstance) => boolean; export type Predicate = (node: ReactTestInstance) => boolean;
type $ReturnType<Fn> = $Call<<Ret, A>((...A) => Ret) => Ret, Fn>; 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 /* $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, * suppresses an error found when Flow v0.125.1 was deployed. To see the error,
* delete this comment and run Flow. */ * 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 { const {
Switch, Switch,
@ -199,10 +200,8 @@ function tap(instance: ReactTestInstance) {
} else if ( } else if (
touchable?.props?.onStartShouldSetResponder?.testOnly_pressabilityConfig touchable?.props?.onStartShouldSetResponder?.testOnly_pressabilityConfig
) { ) {
const { const {onPress, disabled} =
onPress, touchable.props.onStartShouldSetResponder.testOnly_pressabilityConfig();
disabled,
} = touchable.props.onStartShouldSetResponder.testOnly_pressabilityConfig();
if (!disabled) { if (!disabled) {
onPress({nativeEvent: {}}); onPress({nativeEvent: {}});
} }

Просмотреть файл

@ -4,12 +4,12 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @noformat * @format
* @polyfill * @polyfill
* @nolint * @nolint
*/ */
(function() { (function () {
'use strict'; 'use strict';
const hasOwnProperty = Object.prototype.hasOwnProperty; const hasOwnProperty = Object.prototype.hasOwnProperty;
@ -19,7 +19,7 @@
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
*/ */
if (typeof Object.entries !== 'function') { if (typeof Object.entries !== 'function') {
Object.entries = function(object) { Object.entries = function (object) {
// `null` and `undefined` values are not allowed. // `null` and `undefined` values are not allowed.
if (object == null) { if (object == null) {
throw new TypeError('Object.entries called on non-object'); throw new TypeError('Object.entries called on non-object');
@ -40,7 +40,7 @@
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
*/ */
if (typeof Object.values !== 'function') { if (typeof Object.values !== 'function') {
Object.values = function(object) { Object.values = function (object) {
// `null` and `undefined` values are not allowed. // `null` and `undefined` values are not allowed.
if (object == null) { if (object == null) {
throw new TypeError('Object.values called on non-object'); throw new TypeError('Object.values called on non-object');

Просмотреть файл

@ -6,7 +6,7 @@
* *
* @polyfill * @polyfill
* @nolint * @nolint
* @noformat * @format
*/ */
/* eslint-disable no-shadow, eqeqeq, curly, no-unused-vars, no-void, no-control-regex */ /* eslint-disable no-shadow, eqeqeq, curly, no-unused-vars, no-void, no-control-regex */
@ -15,7 +15,7 @@
* This pipes all of our console logging functions to native logging so that * This pipes all of our console logging functions to native logging so that
* JavaScript errors in required modules show up in Xcode via NSLog. * JavaScript errors in required modules show up in Xcode via NSLog.
*/ */
const inspect = (function() { const inspect = (function () {
// Copyright Joyent, Inc. and other Node contributors. // Copyright Joyent, Inc. and other Node contributors.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
@ -55,7 +55,7 @@ const inspect = (function() {
function arrayToHash(array) { function arrayToHash(array) {
var hash = {}; var hash = {};
array.forEach(function(val, idx) { array.forEach(function (val, idx) {
hash[val] = true; hash[val] = true;
}); });
@ -153,7 +153,7 @@ const inspect = (function() {
if (array) { if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else { } else {
output = keys.map(function(key) { output = keys.map(function (key) {
return formatProperty( return formatProperty(
ctx, ctx,
value, value,
@ -210,7 +210,7 @@ const inspect = (function() {
output.push(''); output.push('');
} }
} }
keys.forEach(function(key) { keys.forEach(function (key) {
if (!key.match(/^\d+$/)) { if (!key.match(/^\d+$/)) {
output.push( output.push(
formatProperty(ctx, value, recurseTimes, visibleKeys, key, true), formatProperty(ctx, value, recurseTimes, visibleKeys, key, true),
@ -248,7 +248,7 @@ const inspect = (function() {
if (array) { if (array) {
str = str str = str
.split('\n') .split('\n')
.map(function(line) { .map(function (line) {
return ' ' + line; return ' ' + line;
}) })
.join('\n') .join('\n')
@ -258,7 +258,7 @@ const inspect = (function() {
'\n' + '\n' +
str str
.split('\n') .split('\n')
.map(function(line) { .map(function (line) {
return ' ' + line; return ' ' + line;
}) })
.join('\n'); .join('\n');
@ -290,7 +290,7 @@ const inspect = (function() {
function reduceToSingleString(output, base, braces) { function reduceToSingleString(output, base, braces) {
var numLinesEst = 0; var numLinesEst = 0;
var length = output.reduce(function(prev, cur) { var length = output.reduce(function (prev, cur) {
numLinesEst++; numLinesEst++;
if (cur.indexOf('\n') >= 0) numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++;
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
@ -396,13 +396,13 @@ INSPECTOR_LEVELS[LOG_LEVELS.error] = 'error';
const INSPECTOR_FRAMES_TO_SKIP = __DEV__ ? 2 : 1; const INSPECTOR_FRAMES_TO_SKIP = __DEV__ ? 2 : 1;
function getNativeLogFunction(level) { function getNativeLogFunction(level) {
return function() { return function () {
let str; let str;
if (arguments.length === 1 && typeof arguments[0] === 'string') { if (arguments.length === 1 && typeof arguments[0] === 'string') {
str = arguments[0]; str = arguments[0];
} else { } else {
str = Array.prototype.map str = Array.prototype.map
.call(arguments, function(arg) { .call(arguments, function (arg) {
return inspect(arg, {depth: 10}); return inspect(arg, {depth: 10});
}) })
.join(', '); .join(', ');
@ -443,7 +443,7 @@ function getNativeLogFunction(level) {
} }
function repeat(element, n) { function repeat(element, n) {
return Array.apply(null, Array(n)).map(function() { return Array.apply(null, Array(n)).map(function () {
return element; return element;
}); });
} }
@ -472,7 +472,7 @@ function consoleTablePolyfill(rows) {
// Convert each cell to a string. Also // Convert each cell to a string. Also
// figure out max cell width for each column // figure out max cell width for each column
columns.forEach(function(k, i) { columns.forEach(function (k, i) {
columnWidths[i] = k.length; columnWidths[i] = k.length;
for (var j = 0; j < rows.length; j++) { for (var j = 0; j < rows.length; j++) {
var cellStr = (rows[j][k] || '?').toString(); var cellStr = (rows[j][k] || '?').toString();
@ -485,7 +485,7 @@ function consoleTablePolyfill(rows) {
// Join all elements in the row into a single string with | separators // Join all elements in the row into a single string with | separators
// (appends extra spaces to each cell to make separators | aligned) // (appends extra spaces to each cell to make separators | aligned)
function joinRow(row, space) { 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(''); var extraSpaces = repeat(' ', columnWidths[i] - cell.length).join('');
return cell + extraSpaces; return cell + extraSpaces;
}); });
@ -493,7 +493,7 @@ function consoleTablePolyfill(rows) {
return cells.join(space + '|' + space); return cells.join(space + '|' + space);
} }
var separators = columnWidths.map(function(columnWidth) { var separators = columnWidths.map(function (columnWidth) {
return repeat('-', columnWidth).join(''); return repeat('-', columnWidth).join('');
}); });
var separatorRow = joinRow(separators, '-'); var separatorRow = joinRow(separators, '-');
@ -579,7 +579,7 @@ if (global.nativeLoggingHook) {
Object.keys(console).forEach(methodName => { Object.keys(console).forEach(methodName => {
const reactNativeMethod = console[methodName]; const reactNativeMethod = console[methodName];
if (originalConsole[methodName]) { if (originalConsole[methodName]) {
console[methodName] = function() { console[methodName] = function () {
originalConsole[methodName](...arguments); originalConsole[methodName](...arguments);
reactNativeMethod.apply(console, arguments); reactNativeMethod.apply(console, arguments);
}; };
@ -591,7 +591,7 @@ if (global.nativeLoggingHook) {
// supported by it. // supported by it.
['clear', 'dir', 'dirxml', 'profile', 'profileEnd'].forEach(methodName => { ['clear', 'dir', 'dirxml', 'profile', 'profileEnd'].forEach(methodName => {
if (typeof originalConsole[methodName] === 'function') { if (typeof originalConsole[methodName] === 'function') {
console[methodName] = function() { console[methodName] = function () {
originalConsole[methodName](...arguments); originalConsole[methodName](...arguments);
}; };
} }

Просмотреть файл

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow strict * @flow strict
* @noformat * @format
*/ */
'use strict'; 'use strict';
@ -100,10 +100,8 @@ function translateFunctionParamToJavaType(
imports: Set<string>, imports: Set<string>,
): string { ): string {
const {optional, typeAnnotation: nullableTypeAnnotation} = param; const {optional, typeAnnotation: nullableTypeAnnotation} = param;
const [ const [typeAnnotation, nullable] =
typeAnnotation, unwrapNullable<NativeModuleParamTypeAnnotation>(nullableTypeAnnotation);
nullable,
] = unwrapNullable<NativeModuleParamTypeAnnotation>(nullableTypeAnnotation);
const isRequired = !optional && !nullable; const isRequired = !optional && !nullable;
function wrapIntoNullableIfNeeded(generatedType: string) { function wrapIntoNullableIfNeeded(generatedType: string) {
@ -169,12 +167,10 @@ function translateFunctionReturnTypeToJavaType(
resolveAlias: AliasResolver, resolveAlias: AliasResolver,
imports: Set<string>, imports: Set<string>,
): string { ): string {
const [ const [returnTypeAnnotation, nullable] =
returnTypeAnnotation, unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullable, nullableReturnTypeAnnotation,
] = unwrapNullable<NativeModuleReturnTypeAnnotation>( );
nullableReturnTypeAnnotation,
);
function wrapIntoNullableIfNeeded(generatedType: string) { function wrapIntoNullableIfNeeded(generatedType: string) {
if (nullable) { if (nullable) {
@ -234,12 +230,10 @@ function getFalsyReturnStatementFromReturnType(
createErrorMessage: (typeName: string) => string, createErrorMessage: (typeName: string) => string,
resolveAlias: AliasResolver, resolveAlias: AliasResolver,
): string { ): string {
const [ const [returnTypeAnnotation, nullable] =
returnTypeAnnotation, unwrapNullable<NativeModuleReturnTypeAnnotation>(
nullable, nullableReturnTypeAnnotation,
] = unwrapNullable<NativeModuleReturnTypeAnnotation>( );
nullableReturnTypeAnnotation,
);
let realTypeAnnotation = returnTypeAnnotation; let realTypeAnnotation = returnTypeAnnotation;
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') { if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
@ -288,9 +282,8 @@ function buildGetConstantsMethod(
method: NativeModulePropertyShape, method: NativeModulePropertyShape,
imports: Set<string>, imports: Set<string>,
): string { ): string {
const [ const [methodTypeAnnotation] =
methodTypeAnnotation, unwrapNullable<NativeModuleFunctionTypeAnnotation>(method.typeAnnotation);
] = unwrapNullable<NativeModuleFunctionTypeAnnotation>(method.typeAnnotation);
if ( if (
methodTypeAnnotation.returnTypeAnnotation.type === 'ObjectTypeAnnotation' methodTypeAnnotation.returnTypeAnnotation.type === 'ObjectTypeAnnotation'
) { ) {
@ -405,11 +398,10 @@ module.exports = {
return buildGetConstantsMethod(method, imports); return buildGetConstantsMethod(method, imports);
} }
const [ const [methodTypeAnnotation] =
methodTypeAnnotation, unwrapNullable<NativeModuleFunctionTypeAnnotation>(
] = unwrapNullable<NativeModuleFunctionTypeAnnotation>( method.typeAnnotation,
method.typeAnnotation, );
);
// Handle return type // Handle return type
const translatedReturnType = translateFunctionReturnTypeToJavaType( const translatedReturnType = translateFunctionReturnTypeToJavaType(