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 #552

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

add linting for react/no-access-state-in-setstate and fix resulting l…

…inting errors
  • Loading branch information
IAmThePan committed May 8, 2020
commit a77cd1b72bba037fa83f1b933c20dfe4feb8cfac
@@ -86,7 +86,7 @@ module.exports = {
'react/jsx-indent': [1, 'tab'],
'react/jsx-indent-props': [1, 'tab'],
'react/jsx-props-no-spreading': [0], // TODO: enable this check
'react/no-access-state-in-setstate': [0], // TODO: enable this check
'react/no-access-state-in-setstate': [1],
'react/no-danger': [0],
'react/prop-types': [0],
'react/jsx-fragments': [1, 'element'],
@@ -33,7 +33,7 @@ class License extends React.Component {
* Toggle expansion of a license full text.
*/
toggleLicenseText() {
this.setState({ expanded: !this.state.expanded });
this.setState(prevState => ({ expanded: !prevState.expanded }));
}

/**
@@ -99,9 +99,9 @@ export default class Accordion extends React.Component {
const boundingRect = accordionContentNode.getBoundingClientRect();
// Try lo load more when needed
if (scrollTop + window.innerHeight - (accordionContentNode.offsetTop + boundingRect.height) > -needToUpdateHeight) {
const itemsLength = Math.min(this.state.currentItemsLength + this.nExtraItems, this.props.numTotal);
this.setState({
currentItemsLength: itemsLength,
this.setState((prevState) => {
const itemsLength = Math.min(prevState.currentItemsLength + this.nExtraItems, this.props.numTotal);
return { currentItemsLength: itemsLength };
});
}
}
@@ -186,7 +186,7 @@ class BlockingHeader extends React.Component {
* @param {Object} event mouseclick event
*/
clickFilterText() {
this.setState({ filterMenuOpened: !this.state.filterMenuOpened });
this.setState(prevState => ({ filterMenuOpened: !prevState.filterMenuOpened }));
}

/**
@@ -47,7 +47,7 @@ class GlobalTracker extends React.Component {
*/
toggleDescription() {
const { tracker } = this.props;
this.setState({ showMoreInfo: !this.state.showMoreInfo });
this.setState(prevState => ({ showMoreInfo: !prevState.showMoreInfo }));

if (this.state.description) {
return;
@@ -82,7 +82,7 @@ class Tracker extends React.Component {
*/
toggleDescription() {
const { tracker } = this.props;
this.setState({ showMoreInfo: !this.state.showMoreInfo });
this.setState(prevState => ({ showMoreInfo: !prevState.showMoreInfo }));

if (this.state.description) {
return;
@@ -50,9 +50,7 @@ class ToggleSlider extends React.Component {
if (typeof this.props.onChange === 'function') {
this.props.onChange(event);
} else {
this.setState({
checked: !this.state.checked,
});
this.setState(prevState => ({ checked: !prevState.checked }));
}
}

@@ -41,12 +41,14 @@ class DetailMenu extends React.Component {
* @param {Object} event click event
*/
setActiveTab(event) {
const menu = { ...this.state.menu };
const selectionId = event.currentTarget.id;

Object.keys(menu).forEach((key) => { menu[key] = selectionId === key; });
sendMessage('ping', DetailMenu.pings[selectionId]);
this.setState({ menu });

this.setState((prevState) => {
const menu = { ...prevState.menu };
Object.keys(menu).forEach((key) => { menu[key] = selectionId === key; });
return { menu };
});
}

/**
@@ -65,7 +65,7 @@ class Header extends React.Component {
* Handles toggling the drop-down pane open/closed
*/
toggleDropdown = () => {
this.setState({ dropdownOpen: !this.state.dropdownOpen });
this.setState(prevState => ({ dropdownOpen: !prevState.dropdownOpen }));
}

handleSignin = () => {
@@ -43,15 +43,11 @@ class TrustAndRestrict extends React.Component {
*/
setActivePane(event) {
this.showWarning('');
const newMenuState = { ...this.state.menu };
Object.keys(newMenuState).forEach((key) => {
if (key === event.currentTarget.id) {
newMenuState[key] = true;
} else {
newMenuState[key] = false;
}
});
this.setState({ menu: newMenuState });
const menu = {
showTrustedSites: event.currentTarget.id === 'showTrustedSites',
showRestrictedSites: event.currentTarget.id === 'showRestrictedSites',
};
this.setState({ menu });
}

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