Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 31a5918

Browse files
Merge pull request #53 from RealOrangeOne/master
Add linter
2 parents 71fe648 + 33f0b0c commit 31a5918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+691
-742
lines changed

.eslintrc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
{
22
"extends": "airbnb",
3-
plugins: [
3+
"plugins": [
44
"react",
55
"react-native"
66
],
7+
"env": {
8+
"mocha": true
9+
},
10+
"parser": "babel-eslint",
711
"rules": {
8-
"comma-dangle": 0
12+
"no-unused-vars": [2, {"vars": "all", "args": "none"}],
13+
"comma-dangle": 0,
14+
"func-names": 0,
15+
"prefer-arrow-callback": 0,
16+
"global-require": 0,
17+
"react/prefer-es6-class": 0,
18+
"no-underscore-dangle": 0,
19+
"prefer-rest-params": 0,
20+
"guard-for-in": 0,
21+
"no-restricted-syntax": 0,
22+
"prefer-template": 0,
23+
"no-console": 0,
24+
"max-len": [
25+
2,
26+
120,
27+
2,
28+
{
29+
"ignoreComments": true
30+
}
31+
]
932
}
1033
}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ The API should be as close to the API of `react-native` as possible. If there ar
1212
## Incrementing the version number
1313
In simple: __Don't__. Leave that for us to manage when deploying!
1414

15-
## Tests (Ignore for now!)
15+
## Tests
1616
When adding a new mock, make sure it's got some in-depth tests, and that the linter passes. PRs with failing tests or tests that arent in-depth enough won't be merged. This keeps the mock as stable as possible.

mock.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var ReactNativeMock = require('./build/react-native');
1+
const ReactNativeMock = require('./build/react-native');
22

33
// the cache key that real react native would get
4-
var key = require.resolve('react-native');
4+
const key = require.resolve('react-native');
55

66
// make sure the cache is filled with our lib
77
require.cache[key] = {
@@ -10,4 +10,3 @@ require.cache[key] = {
1010
loaded: true,
1111
exports: ReactNativeMock,
1212
};
13-

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"main": "build/react-native.js",
66
"scripts": {
77
"prepublish": "npm run build",
8-
"test": "mocha --require babel-core/register test/**/*.js",
9-
"test:watch": "npm run test -- --watch",
8+
"test": "npm run lint && npm run mocha",
9+
"mocha": "mocha --require babel-core/register test/**/*.js",
10+
"mocha:watch": "npm run test -- --watch",
1011
"build": "babel src --out-dir build",
11-
"lint": "eslint 'src/' 'test/'"
12+
"lint": "eslint 'src/' 'test/' 'mock.js'"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -30,6 +31,7 @@
3031
"babel": "=6.5.2",
3132
"babel-cli": "=6.9.0",
3233
"babel-core": "=6.9.0",
34+
"babel-eslint": "=6.0.4",
3335
"babel-preset-airbnb": "=2.0.0",
3436
"babel-preset-react-native": "=1.8.0",
3537
"chai": "=3.5.0",

src/NativeModules/AppState.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import DeviceEventEmitter from '../plugins/DeviceEventEmitter';
22

3-
let app_state = 'active';
3+
let _appState = 'active';
44

55
DeviceEventEmitter.on('appStateDidChange', data => {
6-
app_state = data.app_state;
6+
_appState = data._appState;
77
});
88

99
const AppState = {
1010
getCurrentAppState(callback, error) {
11-
Promise.resolve({ app_state }).then(callback);
11+
Promise.resolve({ _appState }).then(callback);
1212
},
1313

1414
__setAppState(appState) {
15-
DeviceEventEmitter.emit('appStateDidChange', { app_state: appState });
15+
DeviceEventEmitter.emit('appStateDidChange', { _appState: appState });
1616
},
1717
};
1818

src/NativeModules/DatePickerAndroid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO(lmr): figure out a good way to have separate responses like "dismissed" vs "set".
22
const DatePickerAndroid = {
33
open(options) {
4-
return Promise.resolve().then({ action: "dismissedAction" });
4+
return Promise.resolve().then({ action: 'dismissedAction' });
55
},
66
};
77

src/NativeModules/ImagePickerIOS.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let _canRecordVideos = true;
2-
let _canUseCamera = true;
1+
const _canRecordVideos = true;
2+
const _canUseCamera = true;
33

44
const ImagePickerIOS = {
55
canRecordVideos(callback) {

src/api/ActionSheetIOS.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
import ActionSheetManager from '../NativeModules/ActionSheetManager';
3-
import invariant from'invariant';
2+
import invariant from 'invariant';
43
import processColor from '../plugins/processColor';
54

65
const ActionSheetIOS = {
@@ -14,7 +13,7 @@ const ActionSheetIOS = {
1413
'Must provide a valid callback'
1514
);
1615
ActionSheetManager.showActionSheetWithOptions(
17-
{...options, tintColor: processColor(options.tintColor)},
16+
{ ...options, tintColor: processColor(options.tintColor) },
1817
callback
1918
);
2019
},
@@ -37,7 +36,7 @@ const ActionSheetIOS = {
3736
'Must provide a valid successCallback'
3837
);
3938
ActionSheetManager.showShareActionSheetWithOptions(
40-
{...options, tintColor: processColor(options.tintColor)},
39+
{ ...options, tintColor: processColor(options.tintColor) },
4140
failureCallback,
4241
successCallback
4342
);

src/api/AlertIOS.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class AlertIOS {
3636
*/
3737
static alert(title, message, callbackOrButtons, type) {
3838
if (typeof type !== 'undefined') {
39-
console.warn('AlertIOS.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.');
40-
this.prompt(title, message, callbackOrButtons, type);
41-
return;
39+
console.warn(
40+
'AlertIOS.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.'
41+
);
42+
this.prompt(title, message, callbackOrButtons, type);
43+
return;
4244
}
4345
this.prompt(title, message, callbackOrButtons, 'default');
4446
}
@@ -85,32 +87,24 @@ class AlertIOS {
8587
*/
8688
static prompt(title, message, callbackOrButtons, type, defaultValue) {
8789
if (typeof type === 'function') {
88-
console.warn(
89-
'You passed a callback function as the "type" argument to AlertIOS.prompt(). React Native is ' +
90-
'assuming you want to use the deprecated AlertIOS.prompt(title, defaultValue, buttons, callback) ' +
91-
'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue) ' +
92-
'and the old syntax will be removed in a future version.');
93-
94-
var callback = type;
95-
var defaultValue = message;
90+
const callback = type;
9691
AlertManager.alertWithArgs({
9792
title: title || undefined,
9893
type: 'plain-text',
99-
defaultValue,
94+
message,
10095
}, (id, value) => {
10196
callback(value);
10297
});
10398
return;
10499
}
105100

106-
var callbacks = [];
107-
var buttons = [];
108-
var cancelButtonKey;
109-
var destructiveButtonKey;
101+
let callbacks = [];
102+
const buttons = [];
103+
let cancelButtonKey;
104+
let destructiveButtonKey;
110105
if (typeof callbackOrButtons === 'function') {
111106
callbacks = [callbackOrButtons];
112-
}
113-
else if (callbackOrButtons instanceof Array) {
107+
} else if (callbackOrButtons instanceof Array) {
114108
callbackOrButtons.forEach((btn, index) => {
115109
callbacks[index] = btn.onPress;
116110
if (btn.style === 'cancel') {
@@ -119,7 +113,7 @@ class AlertIOS {
119113
destructiveButtonKey = String(index);
120114
}
121115
if (btn.text || index < (callbackOrButtons || []).length - 1) {
122-
var btnDef = {};
116+
const btnDef = {};
123117
btnDef[index] = btn.text || '';
124118
buttons.push(btnDef);
125119
}
@@ -135,9 +129,12 @@ class AlertIOS {
135129
defaultValue,
136130
cancelButtonKey,
137131
destructiveButtonKey,
138-
}, (id, value) => {
139-
var cb = callbacks[id];
140-
cb && cb(value);
132+
},
133+
(id, value) => {
134+
const cb = callbacks[id];
135+
if (cb) {
136+
cb(value);
137+
}
141138
}
142139
);
143140
}

0 commit comments

Comments
 (0)