From 392e89676f4092200de7f545cf5d69ceed720892 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Mon, 11 Feb 2019 09:03:16 -0800 Subject: [PATCH] add prettier check in ci (#23382) Summary: enforce code format Pull Request resolved: https://github.com/facebook/react-native/pull/23382 Differential Revision: D14024609 Pulled By: cpojer fbshipit-source-id: 21176cf8f009987e5a281bbead414374632eabee --- .circleci/config.yml | 1 + Libraries/vendor/core/Map.js | 8 +++++--- Libraries/vendor/core/_wrapObjectFreezeAndFriends.js | 10 ++++++---- package.json | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ca90180a2..b9135488f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -358,6 +358,7 @@ jobs: - run: *setup-artifacts - run: *yarn - run: *run-js-tests + - run: yarn run format-check - store_test_results: path: ~/react-native/reports/junit diff --git a/Libraries/vendor/core/Map.js b/Libraries/vendor/core/Map.js index 8643cebb9..009a5258d 100644 --- a/Libraries/vendor/core/Map.js +++ b/Libraries/vendor/core/Map.js @@ -546,8 +546,10 @@ module.exports = (function(global, undefined) { } if (!isES5) { - if (hasOwn.call(o, "propertyIsEnumerable") && - hasOwn.call(o.propertyIsEnumerable, hashProperty)) { + if ( + hasOwn.call(o, 'propertyIsEnumerable') && + hasOwn.call(o.propertyIsEnumerable, hashProperty) + ) { return o.propertyIsEnumerable[hashProperty]; } } @@ -571,7 +573,7 @@ module.exports = (function(global, undefined) { o.propertyIsEnumerable = function() { return propIsEnumerable.apply(this, arguments); }; - return o.propertyIsEnumerable[hashProperty] = ++hashCounter; + return (o.propertyIsEnumerable[hashProperty] = ++hashCounter); } } diff --git a/Libraries/vendor/core/_wrapObjectFreezeAndFriends.js b/Libraries/vendor/core/_wrapObjectFreezeAndFriends.js index c3ab8a085..9bfadc9ad 100644 --- a/Libraries/vendor/core/_wrapObjectFreezeAndFriends.js +++ b/Libraries/vendor/core/_wrapObjectFreezeAndFriends.js @@ -19,13 +19,15 @@ function getTestMap() { // Wrap Object.{freeze,seal,preventExtensions} so each function adds its // argument to a Map first, which gives our ./Map.js polyfill a chance to // tag the object before it becomes non-extensible. -["freeze", "seal", "preventExtensions"].forEach(name => { +['freeze', 'seal', 'preventExtensions'].forEach(name => { const method = Object[name]; - if (typeof method === "function") { - (Object: any)[name] = function (obj) { + if (typeof method === 'function') { + (Object: any)[name] = function(obj) { try { // If .set succeeds, also call .delete to avoid leaking memory. - getTestMap().set(obj, obj).delete(obj); + getTestMap() + .set(obj, obj) + .delete(obj); } finally { // If .set fails, the exception will be silently swallowed // by this return-from-finally statement, and the method will diff --git a/package.json b/package.json index f1d100cb4..20fc02a94 100644 --- a/package.json +++ b/package.json @@ -139,7 +139,8 @@ "flow-check-ios": "flow check", "flow-check-android": "flow check --flowconfig-name .flowconfig.android", "lint": "eslint .", - "prettier": "prettier \"./**/*.js\" --write", + "prettier": "prettier --write \"./**/*.js\" \"./**/*.md\"", + "format-check": "prettier --list-different \"./**/*.js\" \"./**/*.md\"", "docker-setup-android": "docker pull reactnativecommunity/react-native-android", "docker-build-android": "docker build -t reactnativeci/android -f ContainerShip/Dockerfile.android .", "test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash ContainerShip/scripts/run-android-docker-instrumentation-tests.sh",