Skip to content

Commit a175ccf

Browse files
maze-runnariamareebjamal
authored andcommitted
refactor: fix hasOwnProperty and format code (#3749)
1 parent 68606f9 commit a175ccf

File tree

9 files changed

+39
-38
lines changed

9 files changed

+39
-38
lines changed

app/adapters/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import FastbootAdapter from 'ember-data-storefront/mixins/fastboot-adapter';
1313
* @return {*}
1414
*/
1515
export const fixFilterQuery = query => {
16-
if (query.hasOwnProperty('filter')) {
16+
if (Object.prototype.hasOwnProperty.call(query, 'filter')) {
1717
query.filter = JSON.stringify(query.filter);
1818
}
1919

app/components/forms/reset-password-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default Component.extend(FormMixin, {
8585
this.router.transitionTo('login');
8686
})
8787
.catch(reason => {
88-
if (reason && reason.hasOwnProperty('errors') && reason.errors[0].status === 404) {
88+
if (reason && Object.prototype.hasOwnProperty.call(reason, 'errors') && reason.errors[0].status === 404) {
8989
this.set('errorMessage', this.l10n.t('No account is registered with this email address.'));
9090
} else {
9191
this.set('errorMessage', this.l10n.t('An unexpected error occurred.'));

app/controllers/oauth/callback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default Controller.extend({
2323
})
2424
.catch(reason => {
2525
if (!(this.isDestroyed || this.isDestroying)) {
26-
if (reason && reason.hasOwnProperty('status_code') && reason.status_code === 401) {
26+
if (reason && Object.prototype.hasOwnProperty.call(reason, 'status_code') && reason.status_code === 401) {
2727
this.set('errorMessage', this.l10n.t('Your credentials were incorrect.'));
2828
} else {
2929
this.set('errorMessage', this.l10n.t('An unexpected error occurred.'));

app/controllers/public/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default Controller.extend({
9191
})
9292
.catch(reason => {
9393
if (!(this.isDestroyed || this.isDestroying)) {
94-
if (reason && reason.hasOwnProperty('status_code') && reason.status_code === 401) {
94+
if (reason && Object.prototype.hasOwnProperty.call(reason, 'status_code') && reason.status_code === 401) {
9595
this.set('errorMessage', this.l10n.t('Your credentials were incorrect.'));
9696
} else {
9797
this.set('errorMessage', this.l10n.t('An unexpected error occurred.'));

app/controllers/register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default Controller.extend({
2525
}
2626
})
2727
.catch(reason => {
28-
if (reason && reason.hasOwnProperty('errors') && reason.errors[0].status === 409) {
28+
if (reason && Object.prototype.hasOwnProperty.call(reason, 'errors') && reason.errors[0].status === 409) {
2929
this.set('errorMessage', this.l10n.t('User already exists.'));
3030
} else {
3131
this.set('errorMessage', this.l10n.t('An unexpected error occurred.'));
@@ -57,7 +57,7 @@ export default Controller.extend({
5757
})
5858
.catch(reason => {
5959
if (!(this.isDestroyed || this.isDestroying)) {
60-
if (reason && reason.hasOwnProperty('status_code') && reason.status_code === 401) {
60+
if (reason && Object.prototype.hasOwnProperty.call(reason, 'errors') && reason.status_code === 401) {
6161
this.set('errorMessage', this.l10n.t('Your credentials were incorrect.'));
6262
} else {
6363
this.set('errorMessage', this.l10n.t('An unexpected error occurred.'));

app/services/device.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default Service.extend({
3939
deviceType: computed('currentWidth', function() {
4040
let deviceType = 'computer';
4141
forOwn(breakpoints, (value, key) => {
42-
if (this.currentWidth >= value.min && (!value.hasOwnProperty('max') || this.currentWidth <= value.max)) {
42+
if (this.currentWidth >= value.min && (!Object.prototype.hasOwnProperty.call(value, 'max') || this.currentWidth <= value.max)) {
4343
deviceType = key;
4444
}
4545
});

app/services/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default Service.extend({
180180
xhr.open('get', url);
181181
let headers = fetchOptions.headers || {};
182182
for (let k in headers) {
183-
if (k !== 'Content-Type' && headers.hasOwnProperty(k)) {
183+
if (k !== 'Content-Type' && Object.prototype.hasOwnProperty.call(headers, k)) {
184184
xhr.setRequestHeader(k, fetchOptions.headers[k]);
185185
}
186186
}

config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ module.exports = function(environment) {
172172
'media-src' : '\'none\''
173173
};
174174
}
175+
175176
if (environment === 'development') {
176177
// ENV.APP.LOG_RESOLVER = true;
177178
// ENV.APP.LOG_ACTIVE_GENERATION = true;

scripts/replace-config.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
require('dotenv').config()
1+
require('dotenv').config();
22

33
const fs = require('fs');
4-
const promisify = require('util').promisify
5-
const { merge } = require('lodash')
6-
const safeEval = require('safe-eval')
4+
const promisify = require('util').promisify;
5+
const { merge } = require('lodash');
6+
const safeEval = require('safe-eval');
77

8-
const env = require('../config/environment')
9-
const appName = 'open-event-frontend'
8+
const env = require('../config/environment');
9+
const appName = 'open-event-frontend';
1010

11-
const environment = env('production')
11+
const environment = env('production');
1212

1313
async function replaceFastbootConfig() {
14-
const packagePath = './dist/package.json'
15-
const packageInfo = require('.' + packagePath)
14+
const packagePath = './dist/package.json';
15+
const packageInfo = require('.' + packagePath);
1616

17-
const old = packageInfo.fastboot.config[appName]
17+
const old = packageInfo.fastboot.config[appName];
1818
packageInfo.fastboot.config[appName] = merge(old, environment);
19-
await promisify(fs.writeFile)(packagePath, JSON.stringify(packageInfo))
19+
await promisify(fs.writeFile)(packagePath, JSON.stringify(packageInfo));
2020

2121
console.log('Transformed package.json with new environment')
2222
}
2323

2424
function findObject(js, objectStart) {
2525
let braceCount = 1;
2626

27-
const start = js.indexOf("{", objectStart);
27+
const start = js.indexOf('{', objectStart);
2828

2929
if (start < 0) {
3030
return null;
@@ -38,15 +38,15 @@ function findObject(js, objectStart) {
3838
const c = js[index];
3939

4040
if (!parseBlocker && !parseBlockerBuffer) {
41-
if (c == "{") {
41+
if (c === '{') {
4242
braceCount += 1;
4343
} else if (c == "}") {
4444
braceCount -= 1;
4545
} else if (c === '"' || c === "'" || c === "`") {
4646
parseBlocker = c;
47-
} else if (js[index - 1] == "/") {
48-
if (c == "/") parseBlocker = "\n";
49-
else if (c == "*") parseBlockerBuffer = "*/";
47+
} else if (js[index - 1] === '/') {
48+
if (c === '/') { parseBlocker = "\n"; }
49+
else if (c === "*") { parseBlockerBuffer = "*/"; }
5050
}
5151

5252
if (braceCount === 0) {
@@ -55,7 +55,7 @@ function findObject(js, objectStart) {
5555
} else {
5656
if (c === parseBlocker) {
5757
parseBlocker = null;
58-
} else if (c == '/' && js[index - 1] == '*') {
58+
} else if (c === '/' && js[index - 1] == '*') {
5959
parseBlockerBuffer = null;
6060
}
6161
}
@@ -72,43 +72,43 @@ function findObject(js, objectStart) {
7272
}
7373

7474
function replace(str, start, end, replacement) {
75-
return str.substring(0, start) + replacement + str.substring(end + 1, str.length)
75+
return str.substring(0, start) + replacement + str.substring(end + 1, str.length);
7676
}
7777

7878
async function replaceWebConfig() {
79-
const pattern = new RegExp(`^${appName}.*\.js$`)
80-
const basePath = './dist/assets/'
81-
const appJs = (await promisify(fs.readdir)(basePath)).filter(name => name.match(pattern))
79+
const pattern = new RegExp(`^${appName}.*\.js$`);
80+
const basePath = './dist/assets/';
81+
const appJs = (await promisify(fs.readdir)(basePath)).filter(name => name.match(pattern));
8282

83-
const envDefinition = 'define("open-event-frontend/config/environment"'
83+
const envDefinition = 'define("open-event-frontend/config/environment"';
8484

8585
for (const js of appJs) {
8686
const jsPath = basePath + js;
8787
const code = (await promisify(fs.readFile)(jsPath)).toString()
88-
let defineIndex = code.indexOf(envDefinition)
88+
let defineIndex = code.indexOf(envDefinition);
8989

9090
if (defineIndex < 0) {
91-
defineIndex = code.indexOf(envDefinition.replace(/"/g, "'"))
91+
defineIndex = code.indexOf(envDefinition.replace(/"/g, "'"));
9292
if (defineIndex < 0)
9393
continue;
9494
}
9595

96-
const defaultIndex = code.indexOf('default', defineIndex + 1)
96+
const defaultIndex = code.indexOf('default', defineIndex + 1);
9797

98-
if (defaultIndex < 0)
98+
if (defaultIndex < 0) {
9999
continue;
100-
100+
}
101101
// File with environment definition found
102102

103103
console.log('Transforming ' + js)
104-
105-
const object = findObject(code, defaultIndex)
104+
105+
const object = findObject(code, defaultIndex);
106106

107107
console.log('Environment Object Found', object)
108108

109109
const webEnvJson = code.substring(object.start, object.end + 1)
110110
const old = safeEval('(' + webEnvJson + ')')
111-
111+
112112
const newEnv = JSON.stringify(merge(old, environment))
113113
const newCode = replace(code, object.start, object.end, newEnv)
114114

0 commit comments

Comments
 (0)