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

Next

add linting for no-param-reassign and fix resulting linting errors

  • Loading branch information
IAmThePan committed Apr 29, 2020
commit 75b00917cde978161b75cc58c5fa205173404577
@@ -56,7 +56,14 @@ module.exports = {
'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 2 }],
'no-mixed-operators': [0],
'no-nested-ternary': [0],
'no-param-reassign': [0], // TODO: enable this check
'no-param-reassign': ['error', {
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'trackerEl', // for trackers.forEach()
'categoryEl' // for categories.forEach()
]
}],
'no-plusplus': [0],
'no-prototype-builtins': [0], // TODO: enable this check
'no-restricted-syntax': [0], // TODO: enable this check
@@ -40,7 +40,8 @@ const { sendMessage, sendMessageInPromise } = msg;
* but another one, down the chain of redirects - is. It is loaded
* by app/blocked_redirect.html when we navigate browser to it.
*/
(function BlockedRedirectContentScript(window, document) {
(function BlockedRedirectContentScript(window, doc) {
const document = doc;
/**
* Calculate window height.
* @memberof BlockedRedirectContentScript
@@ -59,11 +59,12 @@ const Click2PlayContentScript = (function(win, doc) {
* @memberof Click2PlayContentScript
* @package
*
* @param {Object} c2pFrame iframe DOM element
* @param {Object} c2pFrameEl iframe DOM element
* @param {Object} c2pAppDef replacement data
* @param {string} html a fragment of html to be used in replacement.
*/
const buildC2P = function(c2pFrame, c2pAppDef, html) {
const buildC2P = function(c2pFrameEl, c2pAppDef, html) {
const c2pFrame = c2pFrameEl;
c2pFrame.addEventListener('load', () => {
const idoc = c2pFrame.contentDocument;

@@ -27,7 +27,8 @@ const { sendMessage } = msg;
* Use to call init to initialize functionality
* @var {Object} initialized to an object with init method as its property
*/
const PageInfo = (function(window, document) {
const PageInfo = (function(window, doc) {
const document = doc;
let state = document.readyState;
/**
* Calculate page domain and latency. Send pageInfo to background.js.
@@ -218,30 +218,30 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
const app_ids = [];

if (isSiteTrackers) {
updated_blocking_categories.forEach((category) => {
if (categoryId && category.id !== categoryId) {
updated_blocking_categories.forEach((categoryEl) => {
if (categoryId && categoryEl.id !== categoryId) {
return;
}

const updated_settings_category = updated_settings_categories.find(item => item.id === category.id);
category.num_blocked = 0;
const updated_settings_category = updated_settings_categories.find(item => item.id === categoryEl.id);
categoryEl.num_blocked = 0;
// TODO: change the logic here
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = block;
const key = tracker.id;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = block;
const key = trackerEl.id;

if (block) {
if (!app_ids.includes(key)) {
app_ids.push(key);
}

tracker.ss_allowed = false;
tracker.ss_blocked = false;
trackerEl.ss_allowed = false;
trackerEl.ss_blocked = false;
}

if (block || tracker.ss_blocked) {
category.num_blocked += 1;
if (block || trackerEl.ss_blocked) {
categoryEl.num_blocked += 1;
updated_app_ids[key] = 1;
} else {
delete updated_app_ids[key];
@@ -258,19 +258,19 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
});
});
} else {
updated_settings_categories.forEach((category) => {
if (categoryId && category.id !== categoryId) {
updated_settings_categories.forEach((categoryEl) => {
if (categoryId && categoryEl.id !== categoryId) {
return;
}

category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = block;
const key = tracker.id;
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = block;
const key = trackerEl.id;

if (block) {
category.num_blocked += 1;
categoryEl.num_blocked += 1;
updated_app_ids[key] = 1;
} else {
delete updated_app_ids[key];
@@ -279,13 +279,13 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
});
});

updated_blocking_categories.forEach((category) => {
category.trackers.forEach((tracker) => {
if (tracker.shouldShow && !tracker.ss_allowed && !tracker.ss_blocked) {
tracker.blocked = block;
updated_blocking_categories.forEach((categoryEl) => {
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow && !trackerEl.ss_allowed && !trackerEl.ss_blocked) {
trackerEl.blocked = block;
}
});
category.num_blocked = category.trackers.filter(tracker => tracker.blocked || tracker.ss_blocked).length;
categoryEl.num_blocked = categoryEl.trackers.filter(trackerEl => trackerEl.blocked || trackerEl.ss_blocked).length;
});
}

@@ -326,24 +326,24 @@ export function resetSettings({ state }) {
const blockingCategories = JSON.parse(JSON.stringify(blocking.categories)) || [];
const settingsCategories = JSON.parse(JSON.stringify(settings.categories)) || [];

blockingCategories.forEach((category) => {
category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = false;
tracker.ss_blocked = false;
tracker.ss_allowed = false;
blockingCategories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = false;
trackerEl.ss_blocked = false;
trackerEl.ss_allowed = false;
}
});
});

settingsCategories.forEach((category) => {
category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = false;
tracker.ss_blocked = false;
tracker.ss_allowed = false;
settingsCategories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = false;
trackerEl.ss_blocked = false;
trackerEl.ss_allowed = false;
}
});
});
@@ -72,10 +72,9 @@ export function updateGhosteryPaused(data) {
});
if (data.time) {
setTimeout(() => {
data.ghosteryPaused = !data.ghosteryPaused;
dispatch({
type: UPDATE_GHOSTERY_PAUSED,
data
data: { ...data, ghosteryPaused: !data.ghosteryPaused }
});
}, data.time);
}
@@ -95,21 +95,21 @@ class Blocking extends React.Component {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone
const updatedUnknownCategory = JSON.parse(JSON.stringify(this.props.unknownCategory)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
let show = true;

// filter by donut wheel categories
if (filterName !== 'all' && filterName !== category.id) {
if (filterName !== 'all' && filterName !== categoryEl.id) {
show = false;
}

category.trackers.forEach((tracker) => {
tracker.shouldShow = show;
categoryEl.trackers.forEach((trackerEl) => {
trackerEl.shouldShow = show;
count++;
});

category.num_shown = (show) ? count : 0;
categoryEl.num_shown = (show) ? count : 0;
});

updatedUnknownCategory.hide = !(filterName === 'all' || filterName === 'unknown');
@@ -124,18 +124,18 @@ class Blocking extends React.Component {
setBlockedShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
const isSbBlocked = this.props.smartBlockActive && tracker.warningSmartBlock;
if ((tracker.blocked && !tracker.ss_allowed) || isSbBlocked || tracker.ss_blocked) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
const isSbBlocked = this.props.smartBlockActive && trackerEl.warningSmartBlock;
if ((trackerEl.blocked && !trackerEl.ss_allowed) || isSbBlocked || trackerEl.ss_blocked) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});
category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -148,18 +148,18 @@ class Blocking extends React.Component {
setWarningShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningCompatibility || tracker.warningInsecure || tracker.warningSlow) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningCompatibility || trackerEl.warningInsecure || trackerEl.warningSlow) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -172,18 +172,18 @@ class Blocking extends React.Component {
setWarningCompatibilityShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningCompatibility) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningCompatibility) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -196,18 +196,18 @@ class Blocking extends React.Component {
setWarningSlowInsecureShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningInsecure || tracker.warningSlow) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningInsecure || trackerEl.warningSlow) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -264,9 +264,11 @@ class DonutGraph extends React.Component {
this._endAngles.set(catId, d.endAngle);

return function(t) {
d.startAngle = lerpStartAngle(t);
d.endAngle = lerpEndAngle(t);
return trackerArc(d);
return trackerArc({
...d,
startAngle: lerpStartAngle(t),
endAngle: lerpEndAngle(t),
});
};
});

@@ -320,8 +322,10 @@ class DonutGraph extends React.Component {

const i = interpolate(d.startAngle, d.endAngle);
return function(t) {
d.endAngle = i(t);
return trackerArc(d);
return trackerArc({
...d,
endAngle: i(t)
});
};
})
.ease(easeLinear);
@@ -79,7 +79,8 @@ class StatsGraph extends React.Component {
}

const data = JSON.parse(JSON.stringify(this.props.data));
data.forEach((entry) => {
data.forEach((e) => {
const entry = e;
entry.date = parseMonth(entry.date);
});

@@ -168,11 +168,11 @@ const _updateTrackerTrustRestrict = (state, action) => {
// update tracker category for site-specific blocking
const updated_category = updated_categories[updated_categories.findIndex(item => item.id === msg.cat_id)];

updated_category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
if (tracker.id === app_id) {
tracker.ss_allowed = msg.trust;
tracker.ss_blocked = msg.restrict;
updated_category.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
if (trackerEl.id === app_id) {
trackerEl.ss_allowed = msg.trust;
trackerEl.ss_blocked = msg.restrict;
}
}
});
@@ -242,9 +242,9 @@ const _updateCliqzModuleWhitelist = (state, action) => {
addToWhitelist();
}

updatedUnknownCategory.unknownTrackers.forEach((tracker) => {
if (tracker.name === unknownTracker.name) {
tracker.whitelisted = !tracker.whitelisted;
updatedUnknownCategory.unknownTrackers.forEach((trackerEl) => {
if (trackerEl.name === unknownTracker.name) {
trackerEl.whitelisted = !trackerEl.whitelisted;
}
});

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