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): Do not directly call object builtins #344

Merged
merged 2 commits into from
Jan 13, 2021
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
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"ecmaVersion": 2018
},
"rules": {
"prettier/prettier": "error",
"no-prototype-builtins": "off"
"prettier/prettier": "error"
},
"globals": {
"BUILD_COMPAT_REACT_NATIVE": "readonly",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"date-fns": "^1.30.1",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.3.1",
"express": "^4.16.2",
"fs-extra": "^4.0.2",
"husky": "^4.3.6",
Expand Down
14 changes: 7 additions & 7 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ var _parseConfig = function _parseConfig(options, config) {

// validates config value is defined, is the correct type, and some additional value sanity checks
var parseValidateAndLoad = function parseValidateAndLoad(key) {
if (!options.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(options, key)) {
return; // skip bogus config values
}

Expand All @@ -453,7 +453,7 @@ var _parseConfig = function _parseConfig(options, config) {
};

for (var key in config) {
if (config.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(config, key)) {
parseValidateAndLoad(key);
}
}
Expand Down Expand Up @@ -769,7 +769,7 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti
// setOnce the initial user properties
var identify = new Identify();
for (var key in userProperties) {
if (userProperties.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(userProperties, key)) {
identify.setOnce('initial_' + key, userProperties[key]);
identify.set(key, userProperties[key]);
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ AmplitudeClient.prototype.setUserProperties = function setUserProperties(userPro
// convert userProperties into an identify call
var identify = new Identify();
for (var property in sanitized) {
if (sanitized.hasOwnProperty(property)) {
if (Object.prototype.hasOwnProperty.call(sanitized, property)) {
identify.set(property, sanitized[property]);
}
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
}

// if identify input is a proxied object created by the async loading snippet, convert it into an identify object
if (type(identify_obj) === 'object' && identify_obj.hasOwnProperty('_q')) {
if (Object.prototype.hasOwnProperty.call(identify_obj, '_q')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to call this on a non-object-like will fail, so I got to remove a check here :)

identify_obj = _convertProxyObjectToRealObject(new Identify(), identify_obj);
}

Expand Down Expand Up @@ -1196,7 +1196,7 @@ AmplitudeClient.prototype.groupIdentify = function (group_type, group_name, iden
}

// if identify input is a proxied object created by the async loading snippet, convert it into an identify object
if (type(identify_obj) === 'object' && identify_obj.hasOwnProperty('_q')) {
if (Object.prototype.hasOwnProperty.call(identify_obj, '_q')) {
identify_obj = _convertProxyObjectToRealObject(new Identify(), identify_obj);
}

Expand Down Expand Up @@ -1524,7 +1524,7 @@ AmplitudeClient.prototype.logRevenueV2 = function logRevenueV2(revenue_obj) {
}

// if revenue input is a proxied object created by the async loading snippet, convert it into an revenue object
if (type(revenue_obj) === 'object' && revenue_obj.hasOwnProperty('_q')) {
if (Object.prototype.hasOwnProperty.call(revenue_obj, '_q')) {
revenue_obj = _convertProxyObjectToRealObject(new Revenue(), revenue_obj);
}

Expand Down
2 changes: 1 addition & 1 deletion src/amplitude-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
setUpProxy(amplitude);
amplitude.getInstance = function (instance) {
instance = (!instance || instance.length === 0 ? '$default_instance' : instance).toLowerCase();
if (!amplitude._iq.hasOwnProperty(instance)) {
if (!Object.prototype.hasOwnProperty.call(amplitude._iq, instance)) {
amplitude._iq[instance] = { _q: [] };
setUpProxy(amplitude._iq[instance]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (BUILD_COMPAT_SNIPPET) {

// run queued up functions on instances
for (var instance in this._instances) {
if (this._instances.hasOwnProperty(instance)) {
if (Object.prototype.hasOwnProperty.call(this._instances, instance)) {
this._instances[instance].runQueuedFunctions();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Identify.prototype.append = function (property, value) {
*/
Identify.prototype.clearAll = function () {
if (Object.keys(this.userPropertiesOperations).length > 0) {
if (!this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
if (!Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, AMP_OP_CLEAR_ALL)) {
utils.log.error(
'Need to send $clearAll on its own Identify object without any other operations, skipping $clearAll',
);
Expand Down Expand Up @@ -163,7 +163,7 @@ Identify.prototype.unset = function (property) {
*/
Identify.prototype._addOperation = function (operation, property, value) {
// check that the identify doesn't already contain a clearAll
if (this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
if (Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, AMP_OP_CLEAR_ALL)) {
utils.log.error('This identify already contains a $clearAll operation, skipping operation ' + operation);
return;
}
Expand All @@ -174,7 +174,7 @@ Identify.prototype._addOperation = function (operation, property, value) {
return;
}

if (!this.userPropertiesOperations.hasOwnProperty(operation)) {
if (!Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, operation)) {
this.userPropertiesOperations[operation] = {};
}
this.userPropertiesOperations[operation][property] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ newInstance._q = old._q || [];
*/
for (let instance in old._iq) {
// migrate each instance's queue
if (old._iq.hasOwnProperty(instance)) {
if (Object.prototype.hasOwnProperty.call(old._iq, instance)) {
newInstance.getInstance(instance)._q = old._iq[instance]._q || [];
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var logLevels = {
let logLevel = logLevels.WARN;

const setLogLevel = function setLogLevel(logLevelName) {
if (logLevels.hasOwnProperty(logLevelName)) {
if (Object.prototype.hasOwnProperty.call(logLevels, logLevel)) {
logLevel = logLevels[logLevelName];
}
};
Expand Down Expand Up @@ -112,7 +112,7 @@ var validateProperties = function validateProperties(properties) {

var copy = {}; // create a copy with all of the valid properties
for (var property in properties) {
if (!(property in properties)) {
if (!Object.prototype.hasOwnProperty.call(properties, property)) {
continue;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ var validateGroups = function validateGroups(groups) {

var copy = {}; // create a copy with all of the valid properties
for (var group in groups) {
if (!groups.hasOwnProperty(group)) {
if (!Object.prototype.hasOwnProperty.call(groups, group)) {
continue;
}

Expand Down
6 changes: 6 additions & 0 deletions test/browser/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
"prettier/prettier": "error",
"no-prototype-builtins": "off"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2806,10 +2806,10 @@ eslint-config-prettier@^7.0.0:
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz#c1ae4106f74e6c0357f44adb076771d032ac0e97"
integrity sha512-8Y8lGLVPPZdaNA7JXqnvETVC7IiVRgAP6afQu9gOQRn90YY3otMNh+x7Vr2vMePQntF+5erdSUBqSzCmU/AxaQ==

eslint-plugin-prettier@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.0.tgz#61e295349a65688ffac0b7808ef0a8244bdd8d40"
integrity sha512-tMTwO8iUWlSRZIwS9k7/E4vrTsfvsrcM5p1eftyuqWH25nKsz/o6/54I7jwQ/3zobISyC7wMy9ZsFwgTxOcOpQ==
eslint-plugin-prettier@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz#7079cfa2497078905011e6f82e8dd8453d1371b7"
integrity sha512-Rq3jkcFY8RYeQLgk2cCwuc0P7SEFwDravPhsJZOQ5N4YI4DSg50NyqJ/9gdZHzQlHf8MvafSesbNJCcP/FF6pQ==
dependencies:
prettier-linter-helpers "^1.0.0"

Expand Down