Skip to content

Commit cf6e79e

Browse files
dplewisdavimacedo
authored andcommitted
Fix: Lint no-prototype-builtins (parse-community#5920)
* Fix: Lint no-prototype-builtins Closes: parse-community#5842 Reference: https://eslint.org/docs/rules/no-prototype-builtins * replace Object.hasOwnProperty.call
1 parent 4bffdce commit cf6e79e

22 files changed

+145
-64
lines changed

.eslintrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"prefer-const": "error",
2424
"space-infix-ops": "error",
2525
"no-useless-escape": "off",
26-
"no-prototype-builtins": "off",
2726
"require-atomic-updates": "off"
2827
}
2928
}

spec/ParseQuery.Aggregate.spec.js

+42-14
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ describe('Parse.Query Aggregate testing', () => {
127127
get(Parse.serverURL + '/aggregate/TestObject', options)
128128
.then(resp => {
129129
expect(resp.results.length).toBe(3);
130-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
131-
expect(resp.results[1].hasOwnProperty('objectId')).toBe(true);
132-
expect(resp.results[2].hasOwnProperty('objectId')).toBe(true);
130+
expect(
131+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
132+
).toBe(true);
133+
expect(
134+
Object.prototype.hasOwnProperty.call(resp.results[1], 'objectId')
135+
).toBe(true);
136+
expect(
137+
Object.prototype.hasOwnProperty.call(resp.results[2], 'objectId')
138+
).toBe(true);
133139
expect(resp.results[0].objectId).not.toBe(undefined);
134140
expect(resp.results[1].objectId).not.toBe(undefined);
135141
expect(resp.results[2].objectId).not.toBe(undefined);
@@ -148,9 +154,15 @@ describe('Parse.Query Aggregate testing', () => {
148154
});
149155
const resp = await get(Parse.serverURL + '/aggregate/TestObject', options);
150156
expect(resp.results.length).toBe(3);
151-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
152-
expect(resp.results[1].hasOwnProperty('objectId')).toBe(true);
153-
expect(resp.results[2].hasOwnProperty('objectId')).toBe(true);
157+
expect(
158+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
159+
).toBe(true);
160+
expect(
161+
Object.prototype.hasOwnProperty.call(resp.results[1], 'objectId')
162+
).toBe(true);
163+
expect(
164+
Object.prototype.hasOwnProperty.call(resp.results[2], 'objectId')
165+
).toBe(true);
154166
expect(resp.results[0].objectId).not.toBe(undefined);
155167
expect(resp.results[1].objectId).not.toBe(undefined);
156168
expect(resp.results[2].objectId).not.toBe(undefined);
@@ -371,8 +383,12 @@ describe('Parse.Query Aggregate testing', () => {
371383
expect(results.length).toEqual(4);
372384
for (let i = 0; i < results.length; i++) {
373385
const item = results[i];
374-
expect(item.hasOwnProperty('updatedAt')).toEqual(true);
375-
expect(item.hasOwnProperty('objectId')).toEqual(false);
386+
expect(Object.prototype.hasOwnProperty.call(item, 'updatedAt')).toEqual(
387+
true
388+
);
389+
expect(Object.prototype.hasOwnProperty.call(item, 'objectId')).toEqual(
390+
false
391+
);
376392
}
377393
done();
378394
});
@@ -482,7 +498,9 @@ describe('Parse.Query Aggregate testing', () => {
482498
});
483499
get(Parse.serverURL + '/aggregate/TestObject', options)
484500
.then(resp => {
485-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
501+
expect(
502+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
503+
).toBe(true);
486504
expect(resp.results[0].objectId).toBe(null);
487505
expect(resp.results[0].total).toBe(50);
488506
done();
@@ -498,7 +516,9 @@ describe('Parse.Query Aggregate testing', () => {
498516
});
499517
get(Parse.serverURL + '/aggregate/TestObject', options)
500518
.then(resp => {
501-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
519+
expect(
520+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
521+
).toBe(true);
502522
expect(resp.results[0].objectId).toBe(null);
503523
expect(resp.results[0].total).toBe(4);
504524
done();
@@ -514,7 +534,9 @@ describe('Parse.Query Aggregate testing', () => {
514534
});
515535
get(Parse.serverURL + '/aggregate/TestObject', options)
516536
.then(resp => {
517-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
537+
expect(
538+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
539+
).toBe(true);
518540
expect(resp.results[0].objectId).toBe(null);
519541
expect(resp.results[0].minScore).toBe(10);
520542
done();
@@ -530,7 +552,9 @@ describe('Parse.Query Aggregate testing', () => {
530552
});
531553
get(Parse.serverURL + '/aggregate/TestObject', options)
532554
.then(resp => {
533-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
555+
expect(
556+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
557+
).toBe(true);
534558
expect(resp.results[0].objectId).toBe(null);
535559
expect(resp.results[0].maxScore).toBe(20);
536560
done();
@@ -546,7 +570,9 @@ describe('Parse.Query Aggregate testing', () => {
546570
});
547571
get(Parse.serverURL + '/aggregate/TestObject', options)
548572
.then(resp => {
549-
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
573+
expect(
574+
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
575+
).toBe(true);
550576
expect(resp.results[0].objectId).toBe(null);
551577
expect(resp.results[0].avgScore).toBe(12.5);
552578
done();
@@ -966,7 +992,9 @@ describe('Parse.Query Aggregate testing', () => {
966992
.then(resp => {
967993
expect(resp.results.length).toBe(2);
968994
resp.results.forEach(result => {
969-
expect(result.hasOwnProperty('objectId')).toBe(true);
995+
expect(Object.prototype.hasOwnProperty.call(result, 'objectId')).toBe(
996+
true
997+
);
970998
expect(result.name).toBe(undefined);
971999
expect(result.sender).toBe(undefined);
9721000
expect(result.size).toBe(undefined);

spec/Schema.spec.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -1382,19 +1382,29 @@ describe('SchemaController', () => {
13821382

13831383
it('properly handles volatile _Schemas', done => {
13841384
function validateSchemaStructure(schema) {
1385-
expect(schema.hasOwnProperty('className')).toBe(true);
1386-
expect(schema.hasOwnProperty('fields')).toBe(true);
1387-
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(true);
1385+
expect(Object.prototype.hasOwnProperty.call(schema, 'className')).toBe(
1386+
true
1387+
);
1388+
expect(Object.prototype.hasOwnProperty.call(schema, 'fields')).toBe(true);
1389+
expect(
1390+
Object.prototype.hasOwnProperty.call(schema, 'classLevelPermissions')
1391+
).toBe(true);
13881392
}
13891393
function validateSchemaDataStructure(schemaData) {
13901394
Object.keys(schemaData).forEach(className => {
13911395
const schema = schemaData[className];
13921396
// Hooks has className...
13931397
if (className != '_Hooks') {
1394-
expect(schema.hasOwnProperty('className')).toBe(false);
1398+
expect(
1399+
Object.prototype.hasOwnProperty.call(schema, 'className')
1400+
).toBe(false);
13951401
}
1396-
expect(schema.hasOwnProperty('fields')).toBe(false);
1397-
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(false);
1402+
expect(Object.prototype.hasOwnProperty.call(schema, 'fields')).toBe(
1403+
false
1404+
);
1405+
expect(
1406+
Object.prototype.hasOwnProperty.call(schema, 'classLevelPermissions')
1407+
).toBe(false);
13981408
});
13991409
}
14001410
let schema;

spec/VerifyUserPassword.spec.js

+36-12
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,12 @@ describe('Verify User Password', () => {
469469
const res = response.data;
470470
expect(typeof res).toBe('object');
471471
expect(typeof res['objectId']).toEqual('string');
472-
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
473-
expect(res.hasOwnProperty('password')).toEqual(false);
472+
expect(
473+
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
474+
).toEqual(false);
475+
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
476+
false
477+
);
474478
done();
475479
})
476480
.catch(err => {
@@ -493,8 +497,12 @@ describe('Verify User Password', () => {
493497
const res = response.data;
494498
expect(typeof res).toBe('object');
495499
expect(typeof res['objectId']).toEqual('string');
496-
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
497-
expect(res.hasOwnProperty('password')).toEqual(false);
500+
expect(
501+
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
502+
).toEqual(false);
503+
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
504+
false
505+
);
498506
done();
499507
});
500508
});
@@ -513,8 +521,12 @@ describe('Verify User Password', () => {
513521
const res = response.data;
514522
expect(typeof res).toBe('object');
515523
expect(typeof res['objectId']).toEqual('string');
516-
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
517-
expect(res.hasOwnProperty('password')).toEqual(false);
524+
expect(
525+
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
526+
).toEqual(false);
527+
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
528+
false
529+
);
518530
done();
519531
});
520532
});
@@ -544,8 +556,12 @@ describe('Verify User Password', () => {
544556
expect(typeof res).toBe('string');
545557
const body = JSON.parse(res);
546558
expect(typeof body['objectId']).toEqual('string');
547-
expect(body.hasOwnProperty('sessionToken')).toEqual(false);
548-
expect(body.hasOwnProperty('password')).toEqual(false);
559+
expect(
560+
Object.prototype.hasOwnProperty.call(body, 'sessionToken')
561+
).toEqual(false);
562+
expect(Object.prototype.hasOwnProperty.call(body, 'password')).toEqual(
563+
false
564+
);
549565
done();
550566
});
551567
});
@@ -575,8 +591,12 @@ describe('Verify User Password', () => {
575591
expect(typeof res).toBe('string');
576592
const body = JSON.parse(res);
577593
expect(typeof body['objectId']).toEqual('string');
578-
expect(body.hasOwnProperty('sessionToken')).toEqual(false);
579-
expect(body.hasOwnProperty('password')).toEqual(false);
594+
expect(
595+
Object.prototype.hasOwnProperty.call(body, 'sessionToken')
596+
).toEqual(false);
597+
expect(Object.prototype.hasOwnProperty.call(body, 'password')).toEqual(
598+
false
599+
);
580600
done();
581601
});
582602
});
@@ -603,8 +623,12 @@ describe('Verify User Password', () => {
603623
const res = response.data;
604624
expect(typeof res).toBe('object');
605625
expect(typeof res['objectId']).toEqual('string');
606-
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
607-
expect(res.hasOwnProperty('password')).toEqual(false);
626+
expect(
627+
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
628+
).toEqual(false);
629+
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
630+
false
631+
);
608632
done();
609633
});
610634
});

src/Adapters/Auth/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function loadAuthAdapter(provider, authOptions) {
6767
const providerOptions = authOptions[provider];
6868
if (
6969
providerOptions &&
70-
providerOptions.hasOwnProperty('oauth2') &&
70+
Object.prototype.hasOwnProperty.call(providerOptions, 'oauth2') &&
7171
providerOptions['oauth2'] === true
7272
) {
7373
defaultAdapter = oauth2;

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class MongoStorageAdapter implements StorageAdapter {
279279
delete existingIndexes[name];
280280
} else {
281281
Object.keys(field).forEach(key => {
282-
if (!fields.hasOwnProperty(key)) {
282+
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
283283
throw new Parse.Error(
284284
Parse.Error.INVALID_QUERY,
285285
`Field ${key} does not exist, cannot add index.`
@@ -795,7 +795,7 @@ export class MongoStorageAdapter implements StorageAdapter {
795795
)
796796
.then(results => {
797797
results.forEach(result => {
798-
if (result.hasOwnProperty('_id')) {
798+
if (Object.prototype.hasOwnProperty.call(result, '_id')) {
799799
if (isPointerField && result._id) {
800800
result._id = result._id.split('$')[1];
801801
}
@@ -1024,7 +1024,7 @@ export class MongoStorageAdapter implements StorageAdapter {
10241024
const existingIndexes = schema.indexes;
10251025
for (const key in existingIndexes) {
10261026
const index = existingIndexes[key];
1027-
if (index.hasOwnProperty(fieldName)) {
1027+
if (Object.prototype.hasOwnProperty.call(index, fieldName)) {
10281028
return Promise.resolve();
10291029
}
10301030
}

src/Adapters/Storage/Mongo/MongoTransform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
12821282
}
12831283

12841284
if (
1285-
mongoObject.hasOwnProperty('__type') &&
1285+
Object.prototype.hasOwnProperty.call(mongoObject, '__type') &&
12861286
mongoObject.__type == 'Date' &&
12871287
mongoObject.iso instanceof Date
12881288
) {

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
903903
delete existingIndexes[name];
904904
} else {
905905
Object.keys(field).forEach(key => {
906-
if (!fields.hasOwnProperty(key)) {
906+
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
907907
throw new Parse.Error(
908908
Parse.Error.INVALID_QUERY,
909909
`Field ${key} does not exist, cannot add index.`
@@ -2219,7 +2219,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
22192219
}
22202220
if (stage.$match) {
22212221
const patterns = [];
2222-
const orOrAnd = stage.$match.hasOwnProperty('$or') ? ' OR ' : ' AND ';
2222+
const orOrAnd = Object.prototype.hasOwnProperty.call(
2223+
stage.$match,
2224+
'$or'
2225+
)
2226+
? ' OR '
2227+
: ' AND ';
22232228

22242229
if (stage.$match.$or) {
22252230
const collapse = {};
@@ -2294,7 +2299,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
22942299
)
22952300
.then(results => {
22962301
results.forEach(result => {
2297-
if (!result.hasOwnProperty('objectId')) {
2302+
if (!Object.prototype.hasOwnProperty.call(result, 'objectId')) {
22982303
result.objectId = null;
22992304
}
23002305
if (groupValues) {

src/Controllers/DatabaseController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const validateQuery = (
119119
*/
120120
Object.keys(query).forEach(key => {
121121
const noCollisions = !query.$or.some(subq =>
122-
Object.hasOwnProperty.call(subq, key)
122+
Object.prototype.hasOwnProperty.call(subq, key)
123123
);
124124
let hasNears = false;
125125
if (query[key] != null && typeof query[key] == 'object') {
@@ -1487,7 +1487,7 @@ class DatabaseController {
14871487
[key]: userPointer,
14881488
};
14891489
// if we already have a constraint on the key, use the $and
1490-
if (query.hasOwnProperty(key)) {
1490+
if (Object.prototype.hasOwnProperty.call(query, key)) {
14911491
return { $and: [q, query] };
14921492
}
14931493
// otherwise just add the constaint

0 commit comments

Comments
 (0)