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

re-add linting rule react/sort-comp and fix resulting errors

  • Loading branch information
IAmThePan committed May 26, 2020
commit 3ca24023a35b1e5faed5b6c460cf25b42e7ca345
@@ -99,7 +99,7 @@ module.exports = {
'react/no-danger': [0],
'react/prop-types': [0],
'react/jsx-fragments': [1, 'element'],
'react/sort-comp': [0, { //TODO: enable this check
'react/sort-comp': [1, {
order: [
"static-variables",
"instance-variables",
@@ -23,6 +23,11 @@ import { ToastMessage } from '../../../../shared-components';
* @memberof HubComponents
*/
class SetupBlockingDropdown extends Component {
/**
* Debounce the hide alert function after 3 seconds
*/
_hideToastDebounce = debounce(this._hideToast, 3000)

constructor(props) {
super(props);
this.state = {
@@ -59,11 +64,6 @@ class SetupBlockingDropdown extends Component {
});
}

/**
* Debounce the hide alert function after 3 seconds
*/
_hideToastDebounce = debounce(this._hideToast, 3000)

/**
* React's required render function. Returns JSX
* @return {JSX} JSX for rendering the Blocking Dropdown Component
@@ -23,27 +23,6 @@ export default class Path extends React.Component {
this.timer = null;
}

componentDidMount() {
const node = this.myRef.current;
node.style.setProperty('--stroke-length', `${node.getTotalLength()}`);
// Check and call props.handler() if the animationEnd event doesn't get fired somehow
this.timer = setInterval(() => {
clearInterval(this.timer); // Run this only once
const { handler } = this.props;
handler();
}, INTERVAL);
}

componentWillUnmount() {
clearInterval(this.timer);
}

onAnimationEndHandler = () => {
clearInterval(this.timer);
const { handler } = this.props;
handler();
}

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

@@ -67,6 +46,27 @@ export default class Path extends React.Component {
return d;
}

componentDidMount() {
const node = this.myRef.current;
node.style.setProperty('--stroke-length', `${node.getTotalLength()}`);
// Check and call props.handler() if the animationEnd event doesn't get fired somehow
this.timer = setInterval(() => {
clearInterval(this.timer); // Run this only once
const { handler } = this.props;
handler();
}, INTERVAL);
}

componentWillUnmount() {
clearInterval(this.timer);
}

onAnimationEndHandler = () => {
clearInterval(this.timer);
const { handler } = this.props;
handler();
}

render() {
const { radius, path } = this.props;
const { start, category } = path;
@@ -56,19 +56,47 @@ class Blocking extends React.Component {
/**
* Lifecycle event
*/
componentDidMount() {
this._dynamicUIPort = this.context;
this._dynamicUIPort.onMessage.addListener(this.handlePortMessage);
this._dynamicUIPort.postMessage({ name: 'BlockingComponentDidMount' });
static getDerivedStateFromProps(nextProps) {
const blockingClasses = Blocking.buildBlockingClasses(nextProps).join(' ');
const disableBlocking = Blocking.computeSiteNotScanned(nextProps);
return { blockingClasses, disableBlocking };
}

/**
* Build dynamic classes on .blocking-trackers. Return classes
* @param {Object} props
*/
static buildBlockingClasses(props) {
const classes = [];

classes.push((props.toggle_individual_trackers) ? 'show-individual' : '');
classes.push((props.paused_blocking) ? 'paused' : '');
classes.push((props.sitePolicy) ? (props.sitePolicy === 2) ? 'trusted' : 'restricted' : '');

return classes;
}

/**
* Compute whether a site cannot be scanned by Ghostery.
* @param {Object} props nextProps
*/
static computeSiteNotScanned(props) {
const { siteNotScanned, categories } = props;
const pageUrl = props.pageUrl || '';

if (siteNotScanned || !categories || pageUrl.search('http') === -1) {
return true;
}
return false;
}

/**
* Lifecycle event
*/
static getDerivedStateFromProps(nextProps) {
const blockingClasses = Blocking.buildBlockingClasses(nextProps).join(' ');
const disableBlocking = Blocking.computeSiteNotScanned(nextProps);
return { blockingClasses, disableBlocking };
componentDidMount() {
this._dynamicUIPort = this.context;
this._dynamicUIPort.onMessage.addListener(this.handlePortMessage);
this._dynamicUIPort.postMessage({ name: 'BlockingComponentDidMount' });
}

/**
@@ -240,20 +268,6 @@ class Blocking extends React.Component {
actions.updateBlockingData(msg.body);
}

/**
* Build dynamic classes on .blocking-trackers. Return classes
* @param {Object} props
*/
static buildBlockingClasses(props) {
const classes = [];

classes.push((props.toggle_individual_trackers) ? 'show-individual' : '');
classes.push((props.paused_blocking) ? 'paused' : '');
classes.push((props.sitePolicy) ? (props.sitePolicy === 2) ? 'trusted' : 'restricted' : '');

return classes;
}

/**
* Set dynamic classes on .blocking-trackers. Set state.
* @param {Object} props
@@ -268,20 +282,6 @@ class Blocking extends React.Component {
}
}

/**
* Compute whether a site cannot be scanned by Ghostery.
* @param {Object} props nextProps
*/
static computeSiteNotScanned(props) {
const { siteNotScanned, categories } = props;
const pageUrl = props.pageUrl || '';

if (siteNotScanned || !categories || pageUrl.search('http') === -1) {
return true;
}
return false;
}

/**
* Disable controls for a site that cannot be scanned by Ghostery. Set state.
* @param {Object} props nextProps
@@ -46,32 +46,6 @@ class BlockingHeader extends React.Component {
this.filterNew = this.filterNew.bind(this);
}

/**
* Lifecycle event
*/
componentDidMount() {
const {
actions, categories, smartBlock, smartBlockActive
} = this.props;
const { fromHere } = this.state;
if (categories) {
const updates = BlockingHeader.updateBlockAll(categories, fromHere);
if (updates) {
this.setState({
allBlocked: updates.allBlocked,
fromHere: updates.fromHere,
filtered: updates.filtered
});
}
}

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

/**
* Lifecycle event
* Refactor Notes:
@@ -115,6 +89,32 @@ class BlockingHeader extends React.Component {
return null;
}

/**
* Lifecycle event
*/
componentDidMount() {
const {
actions, categories, smartBlock, smartBlockActive
} = this.props;
const { fromHere } = this.state;
if (categories) {
const updates = BlockingHeader.updateBlockAll(categories, fromHere);
if (updates) {
this.setState({
allBlocked: updates.allBlocked,
fromHere: updates.fromHere,
filtered: updates.filtered
});
}
}

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

/**
* Implement handler for "Expand All/Collapse All" in the Blocking header.
* Trigger action which expands/contracts all categories.
@@ -43,28 +43,6 @@ class Category extends React.Component {
this.hideTooltip = this.hideTooltip.bind(this);
}

/**
* Lifecycle event. When view is opening we save in state
* new values related to tracker blocking to ensure correct rendering.
*/
componentDidMount() {
const { category } = this.props;
if (category) {
const {
allShownBlocked,
totalShownBlocked,
} = Category.updateCategoryCheckbox(category);
this.setState({ allShownBlocked, totalShownBlocked });
}
}

/**
* Lifecycle event
*/
componentDidUpdate(prevProps) {
this.updateCategoryExpanded(prevProps);
}

/**
* Lifecycle event.
*/
@@ -80,24 +58,6 @@ class Category extends React.Component {
};
}

/**
* Set tooltip showing state to true in state which results in actual showing
* of the tooltip.
* @param {Object} event mouseover event
*/
showTooltip() {
this.setState({ showTooltip: true });
}

/**
* Set tooltip showing state to false in state which results in eventual hiding
* of the tooltip.
* @param {Object} event mouseover event
*/
hideTooltip() {
this.setState({ showTooltip: false });
}

/**
* Calculate and save in state the number of blocked trackers
* and if this number covers all trackers in the category.
@@ -125,6 +85,46 @@ class Category extends React.Component {
};
}

/**
* Lifecycle event. When view is opening we save in state
* new values related to tracker blocking to ensure correct rendering.
*/
componentDidMount() {
const { category } = this.props;
if (category) {
const {
allShownBlocked,
totalShownBlocked,
} = Category.updateCategoryCheckbox(category);
this.setState({ allShownBlocked, totalShownBlocked });
}
}

/**
* Lifecycle event
*/
componentDidUpdate(prevProps) {
this.updateCategoryExpanded(prevProps);
}

/**
* Set tooltip showing state to true in state which results in actual showing
* of the tooltip.
* @param {Object} event mouseover event
*/
showTooltip() {
this.setState({ showTooltip: true });
}

/**
* Set tooltip showing state to false in state which results in eventual hiding
* of the tooltip.
* @param {Object} event mouseover event
*/
hideTooltip() {
this.setState({ showTooltip: false });
}

/**
* Implement handler for clicking on the category name or on the chevron.
*/
ProTip! Use n and p to navigate between commits in a pull request.