Skip to content

Commit 14fc693

Browse files
authored
fix(lint): Do not directly call object builtins (#344)
* change direct builtin call * two other places where the wrong one was used
1 parent d933f5d commit 14fc693

10 files changed

+28
-23
lines changed

.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"ecmaVersion": 2018
88
},
99
"rules": {
10-
"prettier/prettier": "error",
11-
"no-prototype-builtins": "off"
10+
"prettier/prettier": "error"
1211
},
1312
"globals": {
1413
"BUILD_COMPAT_REACT_NATIVE": "readonly",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"date-fns": "^1.30.1",
3636
"eslint": "^7.15.0",
3737
"eslint-config-prettier": "^7.0.0",
38-
"eslint-plugin-prettier": "^3.3.0",
38+
"eslint-plugin-prettier": "^3.3.1",
3939
"express": "^4.16.2",
4040
"fs-extra": "^4.0.2",
4141
"husky": "^4.3.6",

src/amplitude-client.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ var _parseConfig = function _parseConfig(options, config) {
431431

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

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

455455
for (var key in config) {
456-
if (config.hasOwnProperty(key)) {
456+
if (Object.prototype.hasOwnProperty.call(config, key)) {
457457
parseValidateAndLoad(key);
458458
}
459459
}
@@ -769,7 +769,7 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti
769769
// setOnce the initial user properties
770770
var identify = new Identify();
771771
for (var key in userProperties) {
772-
if (userProperties.hasOwnProperty(key)) {
772+
if (Object.prototype.hasOwnProperty.call(userProperties, key)) {
773773
identify.setOnce('initial_' + key, userProperties[key]);
774774
identify.set(key, userProperties[key]);
775775
}
@@ -1076,7 +1076,7 @@ AmplitudeClient.prototype.setUserProperties = function setUserProperties(userPro
10761076
// convert userProperties into an identify call
10771077
var identify = new Identify();
10781078
for (var property in sanitized) {
1079-
if (sanitized.hasOwnProperty(property)) {
1079+
if (Object.prototype.hasOwnProperty.call(sanitized, property)) {
10801080
identify.set(property, sanitized[property]);
10811081
}
10821082
}
@@ -1140,7 +1140,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
11401140
}
11411141

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

@@ -1196,7 +1196,7 @@ AmplitudeClient.prototype.groupIdentify = function (group_type, group_name, iden
11961196
}
11971197

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

@@ -1524,7 +1524,7 @@ AmplitudeClient.prototype.logRevenueV2 = function logRevenueV2(revenue_obj) {
15241524
}
15251525

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

src/amplitude-snippet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
setUpProxy(amplitude);
8383
amplitude.getInstance = function (instance) {
8484
instance = (!instance || instance.length === 0 ? '$default_instance' : instance).toLowerCase();
85-
if (!amplitude._iq.hasOwnProperty(instance)) {
85+
if (!Object.prototype.hasOwnProperty.call(amplitude._iq, instance)) {
8686
amplitude._iq[instance] = { _q: [] };
8787
setUpProxy(amplitude._iq[instance]);
8888
}

src/amplitude.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if (BUILD_COMPAT_SNIPPET) {
5555

5656
// run queued up functions on instances
5757
for (var instance in this._instances) {
58-
if (this._instances.hasOwnProperty(instance)) {
58+
if (Object.prototype.hasOwnProperty.call(this._instances, instance)) {
5959
this._instances[instance].runQueuedFunctions();
6060
}
6161
}

src/identify.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Identify.prototype.append = function (property, value) {
7878
*/
7979
Identify.prototype.clearAll = function () {
8080
if (Object.keys(this.userPropertiesOperations).length > 0) {
81-
if (!this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
81+
if (!Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, AMP_OP_CLEAR_ALL)) {
8282
utils.log.error(
8383
'Need to send $clearAll on its own Identify object without any other operations, skipping $clearAll',
8484
);
@@ -163,7 +163,7 @@ Identify.prototype.unset = function (property) {
163163
*/
164164
Identify.prototype._addOperation = function (operation, property, value) {
165165
// check that the identify doesn't already contain a clearAll
166-
if (this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
166+
if (Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, AMP_OP_CLEAR_ALL)) {
167167
utils.log.error('This identify already contains a $clearAll operation, skipping operation ' + operation);
168168
return;
169169
}
@@ -174,7 +174,7 @@ Identify.prototype._addOperation = function (operation, property, value) {
174174
return;
175175
}
176176

177-
if (!this.userPropertiesOperations.hasOwnProperty(operation)) {
177+
if (!Object.prototype.hasOwnProperty.call(this.userPropertiesOperations, operation)) {
178178
this.userPropertiesOperations[operation] = {};
179179
}
180180
this.userPropertiesOperations[operation][property] = value;

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ newInstance._q = old._q || [];
1111
*/
1212
for (let instance in old._iq) {
1313
// migrate each instance's queue
14-
if (old._iq.hasOwnProperty(instance)) {
14+
if (Object.prototype.hasOwnProperty.call(old._iq, instance)) {
1515
newInstance.getInstance(instance)._q = old._iq[instance]._q || [];
1616
}
1717
}

src/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var logLevels = {
1111
let logLevel = logLevels.WARN;
1212

1313
const setLogLevel = function setLogLevel(logLevelName) {
14-
if (logLevels.hasOwnProperty(logLevelName)) {
14+
if (Object.prototype.hasOwnProperty.call(logLevels, logLevel)) {
1515
logLevel = logLevels[logLevelName];
1616
}
1717
};
@@ -112,7 +112,7 @@ var validateProperties = function validateProperties(properties) {
112112

113113
var copy = {}; // create a copy with all of the valid properties
114114
for (var property in properties) {
115-
if (!(property in properties)) {
115+
if (!Object.prototype.hasOwnProperty.call(properties, property)) {
116116
continue;
117117
}
118118

@@ -177,7 +177,7 @@ var validateGroups = function validateGroups(groups) {
177177

178178
var copy = {}; // create a copy with all of the valid properties
179179
for (var group in groups) {
180-
if (!groups.hasOwnProperty(group)) {
180+
if (!Object.prototype.hasOwnProperty.call(groups, group)) {
181181
continue;
182182
}
183183

test/browser/.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
"prettier/prettier": "error",
4+
"no-prototype-builtins": "off"
5+
}
6+
}

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2799,10 +2799,10 @@ eslint-config-prettier@^7.0.0:
27992799
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz#c1ae4106f74e6c0357f44adb076771d032ac0e97"
28002800
integrity sha512-8Y8lGLVPPZdaNA7JXqnvETVC7IiVRgAP6afQu9gOQRn90YY3otMNh+x7Vr2vMePQntF+5erdSUBqSzCmU/AxaQ==
28012801

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

0 commit comments

Comments
 (0)