Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Lint no-prototype-builtins #5920

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"prefer-const": "error",
"space-infix-ops": "error",
"no-useless-escape": "off",
"no-prototype-builtins": "off",
"require-atomic-updates": "off"
}
}
56 changes: 42 additions & 14 deletions spec/ParseQuery.Aggregate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ describe('Parse.Query Aggregate testing', () => {
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results.length).toBe(3);
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(resp.results[1].hasOwnProperty('objectId')).toBe(true);
expect(resp.results[2].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[1], 'objectId')
).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[2], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).not.toBe(undefined);
expect(resp.results[1].objectId).not.toBe(undefined);
expect(resp.results[2].objectId).not.toBe(undefined);
Expand All @@ -148,9 +154,15 @@ describe('Parse.Query Aggregate testing', () => {
});
const resp = await get(Parse.serverURL + '/aggregate/TestObject', options);
expect(resp.results.length).toBe(3);
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(resp.results[1].hasOwnProperty('objectId')).toBe(true);
expect(resp.results[2].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[1], 'objectId')
).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[2], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).not.toBe(undefined);
expect(resp.results[1].objectId).not.toBe(undefined);
expect(resp.results[2].objectId).not.toBe(undefined);
Expand Down Expand Up @@ -371,8 +383,12 @@ describe('Parse.Query Aggregate testing', () => {
expect(results.length).toEqual(4);
for (let i = 0; i < results.length; i++) {
const item = results[i];
expect(item.hasOwnProperty('updatedAt')).toEqual(true);
expect(item.hasOwnProperty('objectId')).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(item, 'updatedAt')).toEqual(
true
);
expect(Object.prototype.hasOwnProperty.call(item, 'objectId')).toEqual(
false
);
}
done();
});
Expand Down Expand Up @@ -482,7 +498,9 @@ describe('Parse.Query Aggregate testing', () => {
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).toBe(null);
expect(resp.results[0].total).toBe(50);
done();
Expand All @@ -498,7 +516,9 @@ describe('Parse.Query Aggregate testing', () => {
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).toBe(null);
expect(resp.results[0].total).toBe(4);
done();
Expand All @@ -514,7 +534,9 @@ describe('Parse.Query Aggregate testing', () => {
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).toBe(null);
expect(resp.results[0].minScore).toBe(10);
done();
Expand All @@ -530,7 +552,9 @@ describe('Parse.Query Aggregate testing', () => {
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).toBe(null);
expect(resp.results[0].maxScore).toBe(20);
done();
Expand All @@ -546,7 +570,9 @@ describe('Parse.Query Aggregate testing', () => {
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(resp.results[0].objectId).toBe(null);
expect(resp.results[0].avgScore).toBe(12.5);
done();
Expand Down Expand Up @@ -966,7 +992,9 @@ describe('Parse.Query Aggregate testing', () => {
.then(resp => {
expect(resp.results.length).toBe(2);
resp.results.forEach(result => {
expect(result.hasOwnProperty('objectId')).toBe(true);
expect(Object.prototype.hasOwnProperty.call(result, 'objectId')).toBe(
true
);
expect(result.name).toBe(undefined);
expect(result.sender).toBe(undefined);
expect(result.size).toBe(undefined);
Expand Down
22 changes: 16 additions & 6 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,19 +1382,29 @@ describe('SchemaController', () => {

it('properly handles volatile _Schemas', done => {
function validateSchemaStructure(schema) {
expect(schema.hasOwnProperty('className')).toBe(true);
expect(schema.hasOwnProperty('fields')).toBe(true);
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(true);
expect(Object.prototype.hasOwnProperty.call(schema, 'className')).toBe(
true
);
expect(Object.prototype.hasOwnProperty.call(schema, 'fields')).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(schema, 'classLevelPermissions')
).toBe(true);
}
function validateSchemaDataStructure(schemaData) {
Object.keys(schemaData).forEach(className => {
const schema = schemaData[className];
// Hooks has className...
if (className != '_Hooks') {
expect(schema.hasOwnProperty('className')).toBe(false);
expect(
Object.prototype.hasOwnProperty.call(schema, 'className')
).toBe(false);
}
expect(schema.hasOwnProperty('fields')).toBe(false);
expect(schema.hasOwnProperty('classLevelPermissions')).toBe(false);
expect(Object.prototype.hasOwnProperty.call(schema, 'fields')).toBe(
false
);
expect(
Object.prototype.hasOwnProperty.call(schema, 'classLevelPermissions')
).toBe(false);
});
}
let schema;
Expand Down
48 changes: 36 additions & 12 deletions spec/VerifyUserPassword.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ describe('Verify User Password', () => {
const res = response.data;
expect(typeof res).toBe('object');
expect(typeof res['objectId']).toEqual('string');
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
expect(res.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
false
);
done();
})
.catch(err => {
Expand All @@ -493,8 +497,12 @@ describe('Verify User Password', () => {
const res = response.data;
expect(typeof res).toBe('object');
expect(typeof res['objectId']).toEqual('string');
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
expect(res.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
false
);
done();
});
});
Expand All @@ -513,8 +521,12 @@ describe('Verify User Password', () => {
const res = response.data;
expect(typeof res).toBe('object');
expect(typeof res['objectId']).toEqual('string');
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
expect(res.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
false
);
done();
});
});
Expand Down Expand Up @@ -544,8 +556,12 @@ describe('Verify User Password', () => {
expect(typeof res).toBe('string');
const body = JSON.parse(res);
expect(typeof body['objectId']).toEqual('string');
expect(body.hasOwnProperty('sessionToken')).toEqual(false);
expect(body.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(body, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(body, 'password')).toEqual(
false
);
done();
});
});
Expand Down Expand Up @@ -575,8 +591,12 @@ describe('Verify User Password', () => {
expect(typeof res).toBe('string');
const body = JSON.parse(res);
expect(typeof body['objectId']).toEqual('string');
expect(body.hasOwnProperty('sessionToken')).toEqual(false);
expect(body.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(body, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(body, 'password')).toEqual(
false
);
done();
});
});
Expand All @@ -603,8 +623,12 @@ describe('Verify User Password', () => {
const res = response.data;
expect(typeof res).toBe('object');
expect(typeof res['objectId']).toEqual('string');
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
expect(res.hasOwnProperty('password')).toEqual(false);
expect(
Object.prototype.hasOwnProperty.call(res, 'sessionToken')
).toEqual(false);
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(
false
);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function loadAuthAdapter(provider, authOptions) {
const providerOptions = authOptions[provider];
if (
providerOptions &&
providerOptions.hasOwnProperty('oauth2') &&
Object.prototype.hasOwnProperty.call(providerOptions, 'oauth2') &&
providerOptions['oauth2'] === true
) {
defaultAdapter = oauth2;
Expand Down
6 changes: 3 additions & 3 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class MongoStorageAdapter implements StorageAdapter {
delete existingIndexes[name];
} else {
Object.keys(field).forEach(key => {
if (!fields.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
`Field ${key} does not exist, cannot add index.`
Expand Down Expand Up @@ -795,7 +795,7 @@ export class MongoStorageAdapter implements StorageAdapter {
)
.then(results => {
results.forEach(result => {
if (result.hasOwnProperty('_id')) {
if (Object.prototype.hasOwnProperty.call(result, '_id')) {
if (isPointerField && result._id) {
result._id = result._id.split('$')[1];
}
Expand Down Expand Up @@ -1024,7 +1024,7 @@ export class MongoStorageAdapter implements StorageAdapter {
const existingIndexes = schema.indexes;
for (const key in existingIndexes) {
const index = existingIndexes[key];
if (index.hasOwnProperty(fieldName)) {
if (Object.prototype.hasOwnProperty.call(index, fieldName)) {
return Promise.resolve();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
}

if (
mongoObject.hasOwnProperty('__type') &&
Object.prototype.hasOwnProperty.call(mongoObject, '__type') &&
mongoObject.__type == 'Date' &&
mongoObject.iso instanceof Date
) {
Expand Down
11 changes: 8 additions & 3 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
delete existingIndexes[name];
} else {
Object.keys(field).forEach(key => {
if (!fields.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
`Field ${key} does not exist, cannot add index.`
Expand Down Expand Up @@ -2219,7 +2219,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
}
if (stage.$match) {
const patterns = [];
const orOrAnd = stage.$match.hasOwnProperty('$or') ? ' OR ' : ' AND ';
const orOrAnd = Object.prototype.hasOwnProperty.call(
stage.$match,
'$or'
)
? ' OR '
: ' AND ';

if (stage.$match.$or) {
const collapse = {};
Expand Down Expand Up @@ -2294,7 +2299,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
)
.then(results => {
results.forEach(result => {
if (!result.hasOwnProperty('objectId')) {
if (!Object.prototype.hasOwnProperty.call(result, 'objectId')) {
result.objectId = null;
}
if (groupValues) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const validateQuery = (
*/
Object.keys(query).forEach(key => {
const noCollisions = !query.$or.some(subq =>
Object.hasOwnProperty.call(subq, key)
Object.prototype.hasOwnProperty.call(subq, key)
);
let hasNears = false;
if (query[key] != null && typeof query[key] == 'object') {
Expand Down Expand Up @@ -1487,7 +1487,7 @@ class DatabaseController {
[key]: userPointer,
};
// if we already have a constraint on the key, use the $and
if (query.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(query, key)) {
return { $and: [q, query] };
}
// otherwise just add the constaint
Expand Down
Loading