Skip to content

Commit 0e06b14

Browse files
committed
lint n nits
1 parent 5a438e0 commit 0e06b14

Some content is hidden

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

43 files changed

+601
-506
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"no-multiple-empty-lines": 1,
2323
"prefer-const": "error",
2424
"space-infix-ops": "error",
25-
"no-useless-escape": "off"
25+
"no-useless-escape": "off",
26+
"no-var": "error"
2627
}
2728
}

integration/server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var express = require('express');
2-
var ParseServer = require('parse-server').ParseServer;
3-
var app = express();
1+
const express = require('express');
2+
const ParseServer = require('parse-server').ParseServer;
3+
const app = express();
44

55
// Specify the connection string for your mongodb database
66
// and the location to your Parse cloud code
7-
var api = new ParseServer({
7+
const api = new ParseServer({
88
databaseURI: 'mongodb://localhost:27017/integration',
99
appId: 'integration',
1010
masterKey: 'notsosecret',

integration/test/ParseObjectTest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ describe('Parse Object', () => {
14761476
beforeEach(() => {
14771477
const StorageController = controller.file;
14781478
Parse.CoreManager.setLocalDatastoreController(StorageController);
1479+
Parse.enableLocalDatastore();
14791480
});
14801481

14811482
it(`${controller.name} can pin (unsaved)`, async () => {

src/Analytics.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function track(
6262
throw new TypeError('A name for the custom event must be provided');
6363
}
6464

65-
for (var key in dimensions) {
65+
for (const key in dimensions) {
6666
if (typeof key !== 'string' || typeof dimensions[key] !== 'string') {
6767
throw new TypeError(
6868
'track() dimensions expects keys and values of type "string".'
@@ -74,10 +74,10 @@ export function track(
7474
.track(name, dimensions);
7575
}
7676

77-
var DefaultController = {
77+
const DefaultController = {
7878
track(name, dimensions) {
79-
var path = 'events/' + name;
80-
var RESTController = CoreManager.getRESTController();
79+
const path = 'events/' + name;
80+
const RESTController = CoreManager.getRESTController();
8181
return RESTController.request('POST', path, { dimensions: dimensions });
8282
}
8383
};

src/Cloud.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function run(
4848
throw new TypeError('Cloud function name must be a string.');
4949
}
5050

51-
var requestOptions = {};
51+
const requestOptions = {};
5252
if (options.useMasterKey) {
5353
requestOptions.useMasterKey = options.useMasterKey;
5454
}
@@ -104,15 +104,15 @@ export function startJob(
104104
* @return {Parse.Object} Status of Job.
105105
*/
106106
export function getJobStatus(jobStatusId: string): Promise {
107-
var query = new ParseQuery('_JobStatus');
107+
const query = new ParseQuery('_JobStatus');
108108
return query.get(jobStatusId, { useMasterKey: true });
109109
}
110110

111111
const DefaultController = {
112112
run(name, data, options) {
113-
var RESTController = CoreManager.getRESTController();
113+
const RESTController = CoreManager.getRESTController();
114114

115-
var payload = encode(data, true);
115+
const payload = encode(data, true);
116116

117117
const request = RESTController.request(
118118
'POST',
@@ -134,7 +134,7 @@ const DefaultController = {
134134
},
135135

136136
getJobsData(options) {
137-
var RESTController = CoreManager.getRESTController();
137+
const RESTController = CoreManager.getRESTController();
138138

139139
return RESTController.request(
140140
'GET',
@@ -145,9 +145,9 @@ const DefaultController = {
145145
},
146146

147147
startJob(name, data, options) {
148-
var RESTController = CoreManager.getRESTController();
148+
const RESTController = CoreManager.getRESTController();
149149

150-
var payload = encode(data, true);
150+
const payload = encode(data, true);
151151

152152
return RESTController.request(
153153
'POST',

src/CoreManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ type Config = {
156156
HooksController?: HooksController,
157157
};
158158

159-
var config: Config & { [key: string]: mixed } = {
159+
const config: Config & { [key: string]: mixed } = {
160160
// Defaults
161161
IS_NODE: (typeof process !== 'undefined' &&
162162
!!process.versions &&

src/FacebookUtils.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import parseDate from './parseDate';
1313
import ParseUser from './ParseUser';
1414

15-
var initialized = false;
16-
var requestedPermissions;
17-
var initOptions;
18-
var provider = {
15+
let initialized = false;
16+
let requestedPermissions;
17+
let initOptions;
18+
const provider = {
1919
authenticate(options) {
2020
if (typeof FB === 'undefined') {
2121
options.error(this, 'Facebook SDK not found.');
@@ -42,19 +42,19 @@ var provider = {
4242

4343
restoreAuthentication(authData) {
4444
if (authData) {
45-
var expiration = parseDate(authData.expiration_date);
46-
var expiresIn = expiration ?
45+
const expiration = parseDate(authData.expiration_date);
46+
const expiresIn = expiration ?
4747
(expiration.getTime() - new Date().getTime()) / 1000 :
4848
0;
4949

50-
var authResponse = {
50+
const authResponse = {
5151
userID: authData.id,
5252
accessToken: authData.access_token,
5353
expiresIn: expiresIn
5454
};
55-
var newOptions = {};
55+
const newOptions = {};
5656
if (initOptions) {
57-
for (var key in initOptions) {
57+
for (const key in initOptions) {
5858
newOptions[key] = initOptions[key];
5959
}
6060
}
@@ -67,7 +67,7 @@ var provider = {
6767
// Most of the time, the users will match -- it's only in cases where
6868
// the FB SDK knows of a different user than the one being restored
6969
// from a Parse User that logged in with username/password.
70-
var existingResponse = FB.getAuthResponse();
70+
const existingResponse = FB.getAuthResponse();
7171
if (existingResponse &&
7272
existingResponse.userID !== authResponse.userID) {
7373
FB.logout();
@@ -93,7 +93,7 @@ var provider = {
9393
* @static
9494
* @hideconstructor
9595
*/
96-
var FacebookUtils = {
96+
const FacebookUtils = {
9797
/**
9898
* Initializes Parse Facebook integration. Call this function after you
9999
* have loaded the Facebook Javascript SDK with the same parameters
@@ -120,12 +120,12 @@ var FacebookUtils = {
120120
}
121121
initOptions = {};
122122
if (options) {
123-
for (var key in options) {
123+
for (const key in options) {
124124
initOptions[key] = options[key];
125125
}
126126
}
127127
if (initOptions.status && typeof console !== 'undefined') {
128-
var warn = console.warn || console.log || function() {}; // eslint-disable-line no-console
128+
const warn = console.warn || console.log || function() {}; // eslint-disable-line no-console
129129
warn.call(console, 'The "status" flag passed into' +
130130
' FB.init, when set to true, can interfere with Parse Facebook' +
131131
' integration, so it has been suppressed. Please call' +
@@ -177,9 +177,9 @@ var FacebookUtils = {
177177
requestedPermissions = permissions;
178178
return ParseUser._logInWith('facebook', options);
179179
} else {
180-
var newOptions = {};
180+
const newOptions = {};
181181
if (options) {
182-
for (var key in options) {
182+
for (const key in options) {
183183
newOptions[key] = options[key];
184184
}
185185
}
@@ -216,9 +216,9 @@ var FacebookUtils = {
216216
requestedPermissions = permissions;
217217
return user._linkWith('facebook', options);
218218
} else {
219-
var newOptions = {};
219+
const newOptions = {};
220220
if (options) {
221-
for (var key in options) {
221+
for (const key in options) {
222222
newOptions[key] = options[key];
223223
}
224224
}

src/InstallationController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import Storage from './Storage';
1313

14-
var iidCache = null;
14+
let iidCache = null;
1515

1616
function hexOctet() {
1717
return Math.floor(
@@ -29,12 +29,12 @@ function generateId() {
2929
);
3030
}
3131

32-
var InstallationController = {
32+
const InstallationController = {
3333
currentInstallationId(): Promise {
3434
if (typeof iidCache === 'string') {
3535
return Promise.resolve(iidCache);
3636
}
37-
var path = Storage.generatePath('installationId');
37+
const path = Storage.generatePath('installationId');
3838
return Storage.getItemAsync(path).then((iid) => {
3939
if (!iid) {
4040
iid = generateId();

src/LocalDatastore.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@ const LocalDatastore = {
4040
},
4141

4242
_clear(): void {
43-
var controller = CoreManager.getLocalDatastoreController();
43+
const controller = CoreManager.getLocalDatastoreController();
4444
controller.clear();
4545
},
4646

4747
_handlePinWithName(name: string, object: ParseObject) {
48-
let pinName = DEFAULT_PIN;
49-
if (name !== DEFAULT_PIN) {
50-
pinName = PIN_PREFIX + name;
51-
}
48+
const pinName = this.getPinName(name);
5249
const objects = this._getChildren(object);
5350
objects[object._getId()] = object._toFullJSON();
54-
for (var objectId in objects) {
51+
for (const objectId in objects) {
5552
this.pinWithName(objectId, objects[objectId]);
5653
}
5754
const pinned = this.fromPinWithName(pinName) || [];
@@ -61,10 +58,7 @@ const LocalDatastore = {
6158
},
6259

6360
_handleUnPinWithName(name: string, object: ParseObject) {
64-
let pinName = DEFAULT_PIN;
65-
if (name !== DEFAULT_PIN) {
66-
pinName = PIN_PREFIX + name;
67-
}
61+
const pinName = this.getPinName(name);
6862
const objects = this._getChildren(object);
6963
const objectIds = Object.keys(objects);
7064
objectIds.push(object._getId());
@@ -112,10 +106,7 @@ const LocalDatastore = {
112106
if (!name) {
113107
return allObjects;
114108
}
115-
let pinName = DEFAULT_PIN;
116-
if (name !== DEFAULT_PIN) {
117-
pinName = PIN_PREFIX + name;
118-
}
109+
const pinName = this.getPinName(name);
119110
const pinned = this.fromPinWithName(pinName);
120111
if (!Array.isArray(pinned)) {
121112
return [];
@@ -124,13 +115,19 @@ const LocalDatastore = {
124115
},
125116

126117
_updateObjectIfPinned(object: ParseObject) {
118+
if (!this.isEnabled) {
119+
return;
120+
}
127121
const pinned = this.fromPinWithName(object.id);
128122
if (pinned) {
129123
this.pinWithName(object.id, object._toFullJSON());
130124
}
131125
},
132126

133127
_destroyObjectIfPinned(object: ParseObject) {
128+
if (!this.isEnabled) {
129+
return;
130+
}
134131
const pin = this.fromPinWithName(object.id);
135132
if (!pin) {
136133
return;
@@ -173,6 +170,20 @@ const LocalDatastore = {
173170
}
174171
}
175172
},
173+
174+
getPinName(pinName: ?string) {
175+
if (!pinName || pinName === DEFAULT_PIN) {
176+
return DEFAULT_PIN;
177+
}
178+
return PIN_PREFIX + pinName;
179+
},
180+
181+
checkIfEnabled() {
182+
if (!this.isEnabled) {
183+
console.log('Parse.enableLocalDatastore() must be called first'); // eslint-disable-line no-console
184+
}
185+
return this.isEnabled;
186+
}
176187
};
177188

178189
function isLocalStorageEnabled() {
@@ -188,6 +199,7 @@ function isLocalStorageEnabled() {
188199
LocalDatastore.DEFAULT_PIN = DEFAULT_PIN;
189200
LocalDatastore.PIN_PREFIX = PIN_PREFIX;
190201
LocalDatastore.isLocalStorageEnabled = isLocalStorageEnabled;
202+
LocalDatastore.isEnabled = false;
191203
module.exports = LocalDatastore;
192204

193205
if (isLocalStorageEnabled()) {

src/LocalDatastoreController.default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const LocalDatastoreController = {
3131
},
3232

3333
clear() {
34-
for (var key in memMap) {
34+
for (const key in memMap) {
3535
if (memMap.hasOwnProperty(key)) {
3636
delete memMap[key];
3737
}

0 commit comments

Comments
 (0)