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

Code Cleanup: Enforce Linting Rules & Update UNSAFE_ React Lifecycle Events #559

Merged
merged 33 commits into from Jun 4, 2020
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
75b0091
add linting for no-param-reassign and fix resulting linting errors
IAmThePan Apr 29, 2020
8d37082
add linting for prefer-object-spread and fix resulting linting errors
IAmThePan Apr 29, 2020
3049bd1
add linting for no-restricted-syntax and fix 1/2 of resulting errors
IAmThePan May 1, 2020
fe03ad7
add linting for no-prototype-builtins and fix resulting linting errors
IAmThePan May 4, 2020
f11bc18
add linting for class-methods-use-this and fix most resulting errors.…
IAmThePan May 5, 2020
5f3471e
finish linting for class-methods-use-this
IAmThePan May 6, 2020
d4d84dc
add linting for no-mixed-operators and fix resulting linting errors
IAmThePan May 6, 2020
17f90ed
add linting for import/prefer-default-export and fix resulting lintin…
IAmThePan May 8, 2020
a77cd1b
add linting for react/no-access-state-in-setstate and fix resulting l…
IAmThePan May 8, 2020
c31dbaf
add linting for react/jsx-props-no-spreading and fix resulting lintin…
IAmThePan May 11, 2020
3d50aff
finish linting errors for no-restricted-syntax. 1 remains: couldn't r…
IAmThePan May 12, 2020
227d012
Merge branch 'develop' into feature/update-linter
IAmThePan May 12, 2020
0988a29
Fix linting errors resulting from the merge with develop
IAmThePan May 12, 2020
b55be21
Refactor UNSAFE_componentWillMount into either constructor or compone…
IAmThePan May 14, 2020
241747c
Refactor UNSAFE_componentWillReceiveProps to componentDidUpdate or ge…
IAmThePan May 18, 2020
eb413fb
re-enable lint exception for no-prototype-builtins and revert calls b…
IAmThePan May 20, 2020
ac0ec93
add single line exception for no-restricted-syntax linting rule
IAmThePan May 20, 2020
fd954eb
add linting for react/destructuring-assignment and fix errors. ToDo: …
IAmThePan May 21, 2020
e815546
Fix minor bugs
IAmThePan May 22, 2020
ae8ffcc
Fix General Settings last updated text
IAmThePan May 22, 2020
4c56460
rework linting rule no-param-reassign to have more exceptions and par…
IAmThePan May 23, 2020
c5ef663
Remove file and line linting exceptions.
IAmThePan May 26, 2020
3ca2402
re-add linting rule react/sort-comp and fix resulting errors
IAmThePan May 26, 2020
4533fd7
remove added linting exception consistent-return and fix resulting er…
IAmThePan May 26, 2020
590aa60
remove added linting expression no-use-before-define and fix resultin…
IAmThePan May 26, 2020
ecb62e8
Fix linting error
IAmThePan May 26, 2020
f634c1d
fix minor bugs
IAmThePan May 26, 2020
ea51432
Code cleanup: fix PromoModal imports
IAmThePan May 26, 2020
75a88cb
Merge with develop. Fix resulting linting errors
IAmThePan May 26, 2020
68493d2
remove unnecessary hasOwnProperty calls after refactored for...in loops
IAmThePan May 28, 2020
6297062
Fix missing strings bug
IAmThePan May 28, 2020
9b4d16c
Fix last remaining string bug
IAmThePan May 28, 2020
2cb47a1
Merge branch 'develop' into feature/cleanup
IAmThePan Jun 4, 2020
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

remove unnecessary hasOwnProperty calls after refactored for...in loops

  • Loading branch information
IAmThePan committed May 28, 2020
commit 68493d2cf81ffc574bbb5c98cb056f16821ec005
@@ -163,10 +163,8 @@ const Click2PlayContentScript = (function(win, doc) {
const messageKeys = Object.keys(message);
for (let i = 0; i < messageKeys.length; i++) {
const app_id = messageKeys[i];
if (message.hasOwnProperty(app_id)) {
applyC2P(app_id, message[app_id].data, message[app_id].html);
delete message[app_id];
}
applyC2P(app_id, message[app_id].data, message[app_id].html);
delete message[app_id];
}
}
}
@@ -53,13 +53,11 @@ export default class FixedMenu extends React.Component {
const categories = Object.keys(this.antiTrackingData);
for (let i = 0; i < categories.length; i++) {
const category = categories[i];
if (this.antiTrackingData.hasOwnProperty(category)) {
const apps = Object.keys(this.antiTrackingData[category]);
for (let j = 0; j < apps.length; j++) {
const app = apps[j];
if (this.antiTrackingData[category][app] === 'unsafe') {
total++;
}
const apps = Object.keys(this.antiTrackingData[category]);
for (let j = 0; j < apps.length; j++) {
const app = apps[j];
if (this.antiTrackingData[category][app] === 'unsafe') {
total++;
}
}
}
@@ -196,7 +196,7 @@ const StatsView = (props) => {
<I18nWithLink cssClasses="modal-title-text" value="panel_stats_pitch_modal_text" />
</div>
<div className="modal-buttons-container">
<div className="modal-filled-button" onClick={subscribe}>{t('Get_Ghostery_Plus_bang')}</div>
<div className="modal-filled-button" onClick={subscribe}>{t('get_ghostery_plus_bang')}</div>
</div>
{ !loggedIn && (
<div className="modal-text-container">
@@ -43,7 +43,7 @@ const Subscribe = ({ match }) => {
<span className="pitch-learn-more">{t('subscribe_pitch_learn_more')}</span>
</PanelToTabLink>
<div>
<span className="pitch-become-subscriber" onClick={_handleBecomeClick}>{t('Get_Ghostery_Plus_bang')}</span>
<span className="pitch-become-subscriber" onClick={_handleBecomeClick}>{t('get_ghostery_plus_bang')}</span>
</div>
{(loggedIn === 'false') && (
<NavLink to="/login" className="pitch-already-subscriber">
@@ -165,12 +165,10 @@ function setGhosteryDefaultBlocking() {
const app_ids = Object.keys(bugDb.db.apps);
for (let i = 0; i < app_ids.length; i++) {
const app_id = app_ids[i];
if (bugDb.db.apps.hasOwnProperty(app_id)) {
const category = bugDb.db.apps[app_id].cat;
if (categoriesBlock.indexOf(category) >= 0 &&
!selected_app_ids.hasOwnProperty(app_id)) {
selected_app_ids[app_id] = 1;
}
const category = bugDb.db.apps[app_id].cat;
if (categoriesBlock.indexOf(category) >= 0 &&
!selected_app_ids.hasOwnProperty(app_id)) {
selected_app_ids[app_id] = 1;
}
}
panelData.set({ selected_app_ids });
@@ -84,61 +84,57 @@ class BugDb extends Updatable {
const appIds = Object.keys(db.apps);
for (let i = 0; i < appIds.length; i++) {
appId = appIds[i];
if (db.apps.hasOwnProperty(appId)) {
category = db.apps[appId].cat;
if (t(`category_${category}`) === `category_${category}`) {
category = 'uncategorized';
}
blocked = selectedApps.hasOwnProperty(appId);
category = db.apps[appId].cat;
if (t(`category_${category}`) === `category_${category}`) {
category = 'uncategorized';
}
blocked = selectedApps.hasOwnProperty(appId);

// Because we have two trackers in the DB with the same name
if ((categories[category] && categories[category].trackers[db.apps[appId].name])) {
continue; // eslint-disable-line no-continue
}
// Because we have two trackers in the DB with the same name
if ((categories[category] && categories[category].trackers[db.apps[appId].name])) {
continue; // eslint-disable-line no-continue
}

if (categories.hasOwnProperty(category)) {
categories[category].num_total++;
if (blocked) {
categories[category].num_blocked++;
}
} else {
categories[category] = {
id: category,
name: t(`category_${category}`),
description: t(`category_${category}_desc`),
img_name: (category === 'advertising') ? 'adv' : // Because AdBlock blocks images with 'advertising' in the name.
(category === 'social_media') ? 'smed' : category, // Because AdBlock blocks images with 'social' in the name.
num_total: 1,
num_blocked: (blocked) ? 1 : 0,
trackers: []
};
if (categories.hasOwnProperty(category)) {
categories[category].num_total++;
if (blocked) {
categories[category].num_blocked++;
}
categories[category].trackers.push({
id: appId,
name: db.apps[appId].name,
description: '',
blocked,
shouldShow: true,
catId: category,
});
} else {
categories[category] = {
id: category,
name: t(`category_${category}`),
description: t(`category_${category}_desc`),
img_name: (category === 'advertising') ? 'adv' : // Because AdBlock blocks images with 'advertising' in the name.
(category === 'social_media') ? 'smed' : category, // Because AdBlock blocks images with 'social' in the name.
num_total: 1,
num_blocked: (blocked) ? 1 : 0,
trackers: []
};
}
categories[category].trackers.push({
id: appId,
name: db.apps[appId].name,
description: '',
blocked,
shouldShow: true,
catId: category,
});
}

const categoryNames = Object.keys(categories);
for (let i = 0; i < categoryNames.length; i++) {
categoryName = categoryNames[i];
if (categories.hasOwnProperty(categoryName)) {
const cat = categories[categoryName];
if (cat.trackers) {
cat.trackers.sort((a, b) => {
const a1 = a.name.toLowerCase();
const b1 = b.name.toLowerCase();
return (a1 > b1 ? 1 : (a1 < b1 ? -1 : 0));
});
}

categoryArray.push(cat);
const cat = categories[categoryName];
if (cat.trackers) {
cat.trackers.sort((a, b) => {
const a1 = a.name.toLowerCase();
const b1 = b.name.toLowerCase();
return (a1 > b1 ? 1 : (a1 < b1 ? -1 : 0));
});
}

categoryArray.push(cat);
}

// Sort categories by tracker numbers
@@ -182,9 +178,7 @@ class BugDb extends Updatable {
const regexesKeys = Object.keys(regexes);
for (let i = 0; i < regexesKeys.length; i++) {
const id = regexesKeys[i];
if (regexes.hasOwnProperty(id)) {
db.patterns.regex[id] = new RegExp(regexes[id], 'i');
}
db.patterns.regex[id] = new RegExp(regexes[id], 'i');
}

log('setting bugdb noneSelected/allSelected...');
@@ -206,50 +206,46 @@ class FoundBugs {
const ids = Object.keys(bugs);
for (let i = 0; i < ids.length; i++) {
id = ids[i];
if (bugs.hasOwnProperty(id)) {
appid = db.bugs[id].aid;
cid = db.apps[appid].cat;

if (cats_obj.hasOwnProperty(cid)) {
if (!cats_obj[cid].appIds.includes(appid)) {
cats_obj[cid].appIds.push(appid);
cats_obj[cid].trackers.push({
id: appid,
name: db.apps[appid].name,
blocked: bugs[id].blocked
});
if (bugs[id].blocked) {
cats_obj[cid].blocked++;
} else {
cats_obj[cid].allowed++;
}
cats_obj[cid].total++;
appid = db.bugs[id].aid;
cid = db.apps[appid].cat;

if (cats_obj.hasOwnProperty(cid)) {
if (!cats_obj[cid].appIds.includes(appid)) {
cats_obj[cid].appIds.push(appid);
cats_obj[cid].trackers.push({
id: appid,
name: db.apps[appid].name,
blocked: bugs[id].blocked
});
if (bugs[id].blocked) {
cats_obj[cid].blocked++;
} else {
cats_obj[cid].allowed++;
}
} else {
cats_obj[cid] = {
id: cid,
name: cid,
appIds: [appid],
trackers: [{
id: appid,
name: db.apps[appid].name,
blocked: bugs[id].blocked
}],
blocked: (bugs[id].blocked ? 1 : 0),
allowed: (bugs[id].blocked ? 0 : 1),
total: 1
};
cats_obj[cid].total++;
}
} else {
cats_obj[cid] = {
id: cid,
name: cid,
appIds: [appid],
trackers: [{
id: appid,
name: db.apps[appid].name,
blocked: bugs[id].blocked
}],
blocked: (bugs[id].blocked ? 1 : 0),
allowed: (bugs[id].blocked ? 0 : 1),
total: 1
};
}
}

// convert categories hash to array
const cids = Object.keys(cats_obj);
for (let i = 0; i < cids.length; i++) {
cid = cids[i];
if (cats_obj.hasOwnProperty(cid)) {
cats_arr.push(cats_obj[cid]);
}
cats_arr.push(cats_obj[cid]);
}

if (sorted) {
@@ -68,9 +68,7 @@ const leet_convert = function(string) {
const characterKeys = Object.keys(characterMap);
for (let i = 0; i < characterKeys.length; i++) {
const letter = characterKeys[i];
if (characterMap.hasOwnProperty(letter)) {
output = output.replace(new RegExp(letter, 'g'), characterMap[letter]);
}
output = output.replace(new RegExp(letter, 'g'), characterMap[letter]);
}

return output;
ProTip! Use n and p to navigate between commits in a pull request.