From cafd6f8f9ae1dedb7107a55bf50f00d11ee574da Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 15 Sep 2019 23:18:57 +0200 Subject: [PATCH] update implementation and add prettier for code formatting --- .eslintrc | 2 +- .prettierrc | 6 ++++++ RNAdMobBanner.js | 14 +++++++------- RNAdMobInterstitial.js | 10 ++++------ RNAdMobRewarded.js | 9 ++++----- RNPublisherBanner.js | 19 +++++++++++-------- package.json | 4 +++- utils.js | 7 ++----- 8 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index 2b216f4e7..cad5fcf52 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,7 @@ "es6": true, "node": true }, - "extends": ["eslint:recommended", "plugin:react/recommended"], + "extends": ["plugin:prettier/recommended", "plugin:react/recommended"], "parser": "babel-eslint", "parserOptions": { "ecmaVersion": 6 diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..304ccc793 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "es5", + "proseWrap": "always", + "arrowParens": "always" +} diff --git a/RNAdMobBanner.js b/RNAdMobBanner.js index ce3de7f1d..7dc09e10d 100644 --- a/RNAdMobBanner.js +++ b/RNAdMobBanner.js @@ -1,16 +1,14 @@ +import { arrayOf, func, string } from 'prop-types'; import React, { Component } from 'react'; import { + findNodeHandle, requireNativeComponent, UIManager, - findNodeHandle, ViewPropTypes, } from 'react-native'; -import { string, func, arrayOf } from 'prop-types'; - import { createErrorFromErrorData } from './utils'; class AdMobBanner extends Component { - constructor() { super(); this.handleSizeChange = this.handleSizeChange.bind(this); @@ -28,7 +26,7 @@ class AdMobBanner extends Component { UIManager.dispatchViewManagerCommand( findNodeHandle(this._bannerView), UIManager.getViewManagerConfig('RNGADBannerView').Commands.loadBanner, - null, + null ); } @@ -42,7 +40,9 @@ class AdMobBanner extends Component { handleAdFailedToLoad(event) { if (this.props.onAdFailedToLoad) { - this.props.onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error)); + this.props.onAdFailedToLoad( + createErrorFromErrorData(event.nativeEvent.error) + ); } } @@ -53,7 +53,7 @@ class AdMobBanner extends Component { style={[this.props.style, this.state.style]} onSizeChange={this.handleSizeChange} onAdFailedToLoad={this.handleAdFailedToLoad} - ref={el => (this._bannerView = el)} + ref={(el) => (this._bannerView = el)} /> ); } diff --git a/RNAdMobInterstitial.js b/RNAdMobInterstitial.js index ae929381d..f103c137b 100644 --- a/RNAdMobInterstitial.js +++ b/RNAdMobInterstitial.js @@ -1,8 +1,4 @@ -import { - NativeModules, - NativeEventEmitter, -} from 'react-native'; - +import { NativeEventEmitter, NativeModules } from 'react-native'; import { createErrorFromErrorData } from './utils'; const RNAdMobInterstitial = NativeModules.RNAdMobInterstitial; @@ -24,7 +20,9 @@ const addEventListener = (event, handler) => { if (mappedEvent) { let listener; if (event === 'adFailedToLoad') { - listener = eventEmitter.addListener(mappedEvent, error => handler(createErrorFromErrorData(error))); + listener = eventEmitter.addListener(mappedEvent, (error) => + handler(createErrorFromErrorData(error)) + ); } else { listener = eventEmitter.addListener(mappedEvent, handler); } diff --git a/RNAdMobRewarded.js b/RNAdMobRewarded.js index 20e2ff7f1..81f807440 100644 --- a/RNAdMobRewarded.js +++ b/RNAdMobRewarded.js @@ -1,7 +1,4 @@ -import { - NativeModules, - NativeEventEmitter, -} from 'react-native'; +import { NativeModules, NativeEventEmitter } from 'react-native'; import { createErrorFromErrorData } from './utils'; @@ -27,7 +24,9 @@ const addEventListener = (event, handler) => { if (mappedEvent) { let listener; if (event === 'adFailedToLoad') { - listener = eventEmitter.addListener(mappedEvent, error => handler(createErrorFromErrorData(error))); + listener = eventEmitter.addListener(mappedEvent, (error) => + handler(createErrorFromErrorData(error)) + ); } else { listener = eventEmitter.addListener(mappedEvent, handler); } diff --git a/RNPublisherBanner.js b/RNPublisherBanner.js index ba6999d9d..64aa12014 100644 --- a/RNPublisherBanner.js +++ b/RNPublisherBanner.js @@ -1,16 +1,14 @@ +import { arrayOf, func, string } from 'prop-types'; import React, { Component } from 'react'; import { + findNodeHandle, requireNativeComponent, UIManager, - findNodeHandle, ViewPropTypes, } from 'react-native'; -import { string, func, arrayOf } from 'prop-types'; - import { createErrorFromErrorData } from './utils'; class PublisherBanner extends Component { - constructor() { super(); this.handleSizeChange = this.handleSizeChange.bind(this); @@ -29,7 +27,7 @@ class PublisherBanner extends Component { UIManager.dispatchViewManagerCommand( findNodeHandle(this._bannerView), UIManager.getViewManagerConfig('RNDFPBannerView').Commands.loadBanner, - null, + null ); } @@ -50,7 +48,9 @@ class PublisherBanner extends Component { handleAdFailedToLoad(event) { if (this.props.onAdFailedToLoad) { - this.props.onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error)); + this.props.onAdFailedToLoad( + createErrorFromErrorData(event.nativeEvent.error) + ); } } @@ -62,7 +62,7 @@ class PublisherBanner extends Component { onSizeChange={this.handleSizeChange} onAdFailedToLoad={this.handleAdFailedToLoad} onAppEvent={this.handleAppEvent} - ref={el => (this._bannerView = el)} + ref={(el) => (this._bannerView = el)} /> ); } @@ -116,6 +116,9 @@ PublisherBanner.propTypes = { onAppEvent: func, }; -const RNDFPBannerView = requireNativeComponent('RNDFPBannerView', PublisherBanner); +const RNDFPBannerView = requireNativeComponent( + 'RNDFPBannerView', + PublisherBanner +); export default PublisherBanner; diff --git a/package.json b/package.json index 155f5a04b..3ca6fc2ee 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "devDependencies": { "babel-eslint": "^7.2.3", "eslint": "^4.19.1", - "eslint-plugin-react": "^7.14.3" + "eslint-config-prettier": "^6.3.0", + "eslint-plugin-react": "^7.14.3", + "prettier": "^1.18.2" } } diff --git a/utils.js b/utils.js index da5388175..66608d9b5 100644 --- a/utils.js +++ b/utils.js @@ -1,9 +1,6 @@ export const createErrorFromErrorData = (errorData) => { - const { - message, - ...extraErrorInfo - } = errorData || {}; + const { message, ...extraErrorInfo } = errorData || {}; const error = new Error(message); error.framesToPop = 1; return Object.assign(error, extraErrorInfo); -} +};