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

add linting for no-mixed-operators and fix resulting linting errors

  • Loading branch information
IAmThePan committed May 6, 2020
commit d4d84dcefbebf0e02049b4daecd2e4c9c86d9b20
@@ -54,7 +54,7 @@ module.exports = {
'lines-between-class-members': [1],
'max-len': [0],
'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 2 }],
'no-mixed-operators': [0], // TODO: enable this check
'no-mixed-operators': [1],
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@christophertino

christophertino Jun 4, 2020
Member

Same, remove this line.

This comment has been minimized.

@IAmThePan

IAmThePan Jun 11, 2020
Author Contributor

updated in feature/cleanup-cleanup as this PR was already merged.

This comment has been minimized.

@wlycdgr

wlycdgr Jun 11, 2020
Member

lgtm in feature/cleanup-cleanup

'no-nested-ternary': [0],
'no-param-reassign': ['error', {
props: true,
@@ -189,7 +189,7 @@ class CreateAccountViewContainer extends Component {
handleSubmit: this._handleCreateAccountAttempt
};
const signedInChildProps = {
email: user && user.email || email,
email: (user && user.email) || email,
};

return loggedIn ? (
@@ -117,7 +117,7 @@ class HomeViewContainer extends Component {
_render() {
const { justInstalled } = this.state;
const { home, user } = this.props;
const isPlus = user && user.subscriptionsPlus || false;
const isPlus = (user && user.subscriptionsPlus) || false;
const {
premium_promo_modal_shown,
setup_complete,
@@ -137,7 +137,7 @@ class LogInViewContainer extends Component {
handleSubmit: this._handleLoginAttempt,
};
const signedInChildProps = {
email: user && user.email || 'email',
email: (user && user.email) || 'email',
};

return loggedIn ? (
@@ -44,7 +44,7 @@ class PlusViewContainer extends Component {
*/
render() {
const childProps = {
isPlus: this.props.user && this.props.user.subscriptionsPlus || false,
isPlus: (this.props.user && this.props.user.subscriptionsPlus) || false,
onPlusClick: this._sendPlusPing,
};

@@ -21,8 +21,8 @@ function trustRestrictTracker({
const siteSpecificUnblocks = blocking.site_specific_unblocks;
const siteSpecificBlocks = blocking.site_specific_blocks;

const pageUnblocks = siteSpecificUnblocks[pageHost] && siteSpecificUnblocks[pageHost].slice(0) || []; // clone
const pageBlocks = siteSpecificBlocks[pageHost] && siteSpecificBlocks[pageHost].slice(0) || []; // clone
const pageUnblocks = (siteSpecificUnblocks[pageHost] && siteSpecificUnblocks[pageHost].slice(0)) || []; // clone
const pageBlocks = (siteSpecificBlocks[pageHost] && siteSpecificBlocks[pageHost].slice(0)) || []; // clone
let updated_site_specific_unblocks = {};
let updated_site_specific_blocks = {};

@@ -64,7 +64,7 @@ export default class FixedMenu extends React.Component {
return total;
}
case 'enable_ad_block':
return this.adBlockData && this.adBlockData.totalCount || 0;
return (this.adBlockData && this.adBlockData.totalCount) || 0;
case 'enable_smart_block':
Object.keys(this.smartBlockData.blocked || {}).forEach(() => {
total++;
@@ -43,7 +43,7 @@ export default class Path extends React.Component {
}

static polarToCartesian(centerX, centerY, radius, angleInDegrees) {
const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
const angleInRadians = (angleInDegrees - 90) * (Math.PI / 180.0);

return {
x: centerX + (radius * Math.cos(angleInRadians)),
@@ -28,7 +28,7 @@ export function fromTrackersToChartData(trackers) {
const sum = trackers.map(tracker => tracker.numTotal).reduce((a, b) => a + b, 0);

for (let i = 0; i < trackers.length; i += 1) {
const endAngle = startAngle + (trackers[i].numTotal * 360 / sum);
const endAngle = startAngle + (trackers[i].numTotal * (360 / sum));

arcs.push({
start: startAngle,
@@ -75,7 +75,7 @@ class Blocking extends React.Component {
// Update the summary blocking count whenever the blocking component updated.
// This will also show pending blocking changes if the panel is re-opened
// before a page refresh
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (this.props.smartBlockActive && this.props.smartBlock) || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}

@@ -56,7 +56,7 @@ class BlockingHeader extends React.Component {

if (typeof this.props.actions.updateTrackerCounts === 'function') {
// if we're on GlobalSettings, we don't need to run this function
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (this.props.smartBlockActive && this.props.smartBlock) || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}
}
@@ -133,7 +133,7 @@ class BlockingHeader extends React.Component {

if (typeof this.props.actions.updateTrackerCounts === 'function') {
// if we're on GlobalSettings, we don't need to run this function
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (this.props.smartBlockActive && this.props.smartBlock) || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}

@@ -143,7 +143,7 @@ class DonutGraph extends React.Component {
* Helper function that calculates domain value for greyscale / redscale rendering
*/
static getTone(catCount, catIndex) {
return catCount > 1 ? 100 / (catCount - 1) * catIndex * 0.01 : 0;
return catCount > 1 ? (100 / (catCount - 1)) * catIndex * 0.01 : 0;
}

/**
@@ -109,7 +109,7 @@ class Header extends React.Component {
}

let accountIcon;
if (!loggedIn || loggedIn && user && !user.emailValidated) {
if (!loggedIn || (loggedIn && user && !user.emailValidated)) {
accountIcon = (
<div className="g-tooltip">
<svg className="profile-svg" width="26" height="40" viewBox="0 0 26 16">
@@ -328,7 +328,7 @@ class Summary extends React.Component {
enable_ad_block,
} = this.props;

return enable_ad_block && adBlock && adBlock.trackerCount || 0;
return (enable_ad_block && adBlock && adBlock.trackerCount) || 0;
}

_antiTrackUnsafe() {
@@ -337,7 +337,7 @@ class Summary extends React.Component {
enable_anti_tracking,
} = this.props;

return enable_anti_tracking && antiTracking && antiTracking.trackerCount || 0;
return (enable_anti_tracking && antiTracking && antiTracking.trackerCount) || 0;
}

_requestsModifiedCount() {
@@ -353,7 +353,7 @@ class Summary extends React.Component {
_sbBlocked() {
const { smartBlock, trackerCounts } = this.props;

let sbBlocked = smartBlock && smartBlock.blocked && Object.keys(smartBlock.blocked).length || 0;
let sbBlocked = (smartBlock && smartBlock.blocked && Object.keys(smartBlock.blocked).length) || 0;
if (sbBlocked === trackerCounts.sbBlocked) {
sbBlocked = 0;
}
@@ -364,7 +364,7 @@ class Summary extends React.Component {
_sbAllowed() {
const { smartBlock, trackerCounts } = this.props;

let sbAllowed = smartBlock && smartBlock.unblocked && Object.keys(smartBlock.unblocked).length || 0;
let sbAllowed = (smartBlock && smartBlock.unblocked && Object.keys(smartBlock.unblocked).length) || 0;
if (sbAllowed === trackerCounts.sbAllowed) {
sbAllowed = 0;
}
@@ -375,7 +375,7 @@ class Summary extends React.Component {
_sbAdjust() {
const { enable_smart_block } = this.props;

return enable_smart_block && (this._sbBlocked() - this._sbAllowed()) || 0;
return enable_smart_block && ((this._sbBlocked() - this._sbAllowed()) || 0);
}

_totalTrackersBlockedCount() {
@@ -142,8 +142,8 @@ const _updateTrackerTrustRestrict = (state, action) => {
const { pageHost } = action;
const siteSpecificUnblocks = state.site_specific_unblocks;
const siteSpecificBlocks = state.site_specific_blocks;
const pageUnblocks = siteSpecificUnblocks[pageHost] && siteSpecificUnblocks[pageHost].slice(0) || []; // clone
const pageBlocks = siteSpecificBlocks[pageHost] && siteSpecificBlocks[pageHost].slice(0) || []; // clone
const pageUnblocks = (siteSpecificUnblocks[pageHost] && siteSpecificUnblocks[pageHost].slice(0)) || []; // clone
const pageBlocks = (siteSpecificBlocks[pageHost] && siteSpecificBlocks[pageHost].slice(0)) || []; // clone

// Site specific un-blocking
if (msg.trust) {
@@ -76,7 +76,7 @@ export function updateBlockAllTrackers(state, action) {
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)) || [];
const { smartBlockActive } = action.data;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (smartBlockActive && action.data.smartBlock) || { blocked: {}, unblocked: {} };

updated_categories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
@@ -117,7 +117,7 @@ export function updateBlockAllTrackers(state, action) {
*/
export function updateCategoryBlocked(state, action) {
const { blocked, smartBlockActive } = action.data;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (smartBlockActive && action.data.smartBlock) || { blocked: {}, unblocked: {} };
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)); // deep clone
const catIndex = updated_categories.findIndex(item => item.id === action.data.category);
@@ -186,7 +186,7 @@ export function updateTrackerBlocked(state, action) {
}

const { blocked, smartBlockActive } = action.data;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };
const smartBlock = (smartBlockActive && action.data.smartBlock) || { blocked: {}, unblocked: {} };
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)) || []; // deep clone
const catIndex = updated_categories.findIndex(item => item.id === action.data.cat_id);
@@ -135,7 +135,7 @@ export function validateConfirmEmail(email, confirmEmail) {
}
const lEmail = email.toLowerCase();
const lConfirmEmail = confirmEmail.toLowerCase();
return validateEmail(confirmEmail) && (lEmail === lConfirmEmail) || false;
return (validateEmail(confirmEmail) && (lEmail === lConfirmEmail)) || false;
}

/**
@@ -75,7 +75,7 @@ class PanelData {
const { url } = tab;

this._activeTab = tab;
this._activeTab.pageHost = url && processUrl(url).hostname || '';
this._activeTab.pageHost = (url && processUrl(url).hostname) || '';

this._attachListeners();

@@ -172,7 +172,7 @@ class PanelData {
// Android panel only
const { url } = tab;
this._activeTab = tab;
this._activeTab.pageHost = url && processUrl(url).hostname || '';
this._activeTab.pageHost = (url && processUrl(url).hostname) || '';
this._setTrackerListAndCategories();
switch (view) {
case 'panel':
@@ -192,7 +192,7 @@ class PolicySmartBlock {

return (
pageProtocol === 'https' &&
(requestProtocol === 'http' || requestProtocol === 'ws') || false
((requestProtocol === 'http' || requestProtocol === 'ws') || false)
);
}

@@ -232,7 +232,7 @@ class PolicySmartBlock {

return (
tabInfo.getTabInfoPersist(tabId, 'numOfReloads') > 1 &&
((Date.now() - tabInfo.getTabInfoPersist(tabId, 'firstLoadTimestamp')) < SMART_BLOCK_BEHAVIOR_THRESHOLD) || false
(((Date.now() - tabInfo.getTabInfoPersist(tabId, 'firstLoadTimestamp')) < SMART_BLOCK_BEHAVIOR_THRESHOLD) || false)
);
}

@@ -58,7 +58,7 @@ class TabInfo {
timestamp: Date.now(),
// assign only when smartBlock is enabled so avoid false positives
// when enabling smartBlock is enabled for the first time
firstLoadTimestamp: PolicySmartBlock.shouldCheck(tab_id) && (numOfReloads === 0 ? Date.now() : (this.getTabInfoPersist(tab_id, 'firstLoadTimestamp') || 0)) || 0,
firstLoadTimestamp: PolicySmartBlock.shouldCheck(tab_id) && (numOfReloads === 0 ? Date.now() : ((this.getTabInfoPersist(tab_id, 'firstLoadTimestamp') || 0)) || 0),
reloaded: PolicySmartBlock.checkReloadThreshold(tab_id),
numOfReloads,
smartBlock: {
@@ -184,7 +184,7 @@ export function* objectEntries(obj) {
* @return {string} unescaped str
*/
function _base64urlUnescape(str) {
str += new Array(5 - str.length % 4).join('='); // eslint-disable-line no-param-reassign
str += new Array(5 - (str.length % 4)).join('='); // eslint-disable-line no-param-reassign
return str.replace(/\-/g, '+').replace(/_/g, '/'); // eslint-disable-line no-useless-escape
}

@@ -593,7 +593,7 @@ export function injectNotifications(tab_id, importExport = false) {
}
const tab = tabInfo.getTabInfo(tab_id);
// check for prefetching, chrome new tab page and Firefox about:pages
if (tab && tab.prefetched === true || tab.path.includes('_/chrome/newtab') || tab.protocol === 'about' || (!importExport && globals.EXCLUDES.includes(tab.host))) {
if (tab && (tab.prefetched === true || tab.path.includes('_/chrome/newtab') || tab.protocol === 'about' || (!importExport && globals.EXCLUDES.includes(tab.host)))) {
// return false to prevent sendMessage calls
return Promise.resolve(false);
}
ProTip! Use n and p to navigate between commits in a pull request.