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

Update Linter & Remove Unsafe React Lifecycle Events #553

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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],
'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.