Skip to content

Commit

Permalink
Enable the new rule react/no-unused-class-component-methods and fix e…
Browse files Browse the repository at this point in the history
…slint errors
  • Loading branch information
julienw committed Nov 22, 2021
1 parent 7b4ea84 commit 1f3c1cb
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 37 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Expand Up @@ -36,6 +36,7 @@ module.exports = {
'react/no-did-update-set-state': 'error',
'react/no-will-update-set-state': 'error',
'react/no-redundant-should-component-update': 'error',
'react/no-unused-class-component-methods': 'error',
'react/no-this-in-sfc': 'error',
'react/no-typos': 'error',
// Flow provides enough coverage over the prop types, and there can be errors
Expand Down Expand Up @@ -128,8 +129,8 @@ module.exports = {
settings: {
react: {
pragma: 'React',
version: '15.0',
flowVersion: '0.63.1',
version: '17.0',
flowVersion: '0.96.0',
},
'import/resolver': {
alias: {
Expand Down
5 changes: 0 additions & 5 deletions src/components/app/MenuButtons/Permalink.js
Expand Up @@ -26,11 +26,7 @@ type State = {|
|};

export class MenuButtonsPermalink extends React.PureComponent<Props, State> {
_permalinkButton: ButtonWithPanel | null;
_permalinkTextField: HTMLInputElement | null;
_takePermalinkButtonRef = (elem: ButtonWithPanel | null) => {
this._permalinkButton = elem;
};
_takePermalinkTextFieldRef = (elem: HTMLInputElement | null) => {
this._permalinkTextField = elem;
};
Expand Down Expand Up @@ -74,7 +70,6 @@ export class MenuButtonsPermalink extends React.PureComponent<Props, State> {
<Localized id="MenuButtons--permalink--button" attrs={{ label: true }}>
<ButtonWithPanel
buttonClassName="menuButtonsButton menuButtonsButton-hasIcon menuButtonsPermalinkButtonButton"
ref={this._takePermalinkButtonRef}
label="Permalink"
initialOpen={this.props.isNewlyPublished}
onPanelOpen={this._shortenUrlAndFocusTextFieldOnCompletion}
Expand Down
15 changes: 0 additions & 15 deletions src/components/app/MenuButtons/Publish.js
Expand Up @@ -201,21 +201,6 @@ class MenuButtonsPublishImpl extends React.PureComponent<PublishProps> {
);
}

_closePanelAfterUpload = () => {
const { resetUploadState } = this.props;
// Only reset it after the panel animation disappears.
setTimeout(resetUploadState, 300);

const { body } = document;
if (body) {
// This is a hack to close the arrow panel. See the following issue on
// moving this to the Redux state.
//
// https://github.com/firefox-devtools/profiler/issues/1888
body.dispatchEvent(new MouseEvent('mousedown'));
}
};

_renderUploadPanel() {
const {
uploadProgress,
Expand Down
4 changes: 0 additions & 4 deletions src/components/app/ProfileDeleteButton.js
Expand Up @@ -152,10 +152,6 @@ export class ProfileDeletePanel extends PureComponent<PanelProps, PanelState> {
}
};

onCancelDeletion = () => {
this.props.onProfileDeleteCanceled();
};

preventClick(e: SyntheticMouseEvent<>) {
e.preventDefault();
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/flame-graph/FlameGraph.js
Expand Up @@ -122,6 +122,8 @@ class FlameGraphImpl extends React.PureComponent<Props> {
this._viewport = viewport;
};

/* This method is called from MaybeFlameGraph. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
focus = () => {
if (this._viewport) {
this._viewport.focus();
Expand Down
2 changes: 0 additions & 2 deletions src/components/js-tracer/index.js
Expand Up @@ -40,8 +40,6 @@ type StateProps = {|
type Props = ConnectedProps<{||}, StateProps, DispatchProps>;

class JsTracerImpl extends React.PureComponent<Props> {
_rafGeneration: number = 0;

render() {
const { profile, jsTracerTable, showJsTracerSummary, threadsKey } =
this.props;
Expand Down
5 changes: 5 additions & 0 deletions src/components/shared/ButtonWithPanel/ArrowPanel.js
Expand Up @@ -35,6 +35,10 @@ export class ArrowPanel extends React.PureComponent<Props, State> {
openGeneration: 0,
};

/* These 2 methods are called from other components.
/* See https://github.com/firefox-devtools/profiler/issues/1888 and
* https://github.com/firefox-devtools/profiler/issues/1641 */
/* eslint-disable-next-line react/no-unused-class-component-methods */
open() {
if (this.state.open) {
return;
Expand All @@ -43,6 +47,7 @@ export class ArrowPanel extends React.PureComponent<Props, State> {
this.setState({ open: true });
}

/* eslint-disable-next-line react/no-unused-class-component-methods */
close() {
this.setState((state) => {
if (!state.open) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/shared/TreeView.js
Expand Up @@ -429,6 +429,8 @@ export class TreeView<DisplayData: Object> extends React.PureComponent<
{ limit: 1 }
);

/* This method is used by users of this component. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
scrollSelectionIntoView() {
const { selectedNodeId, tree } = this.props;
if (this._list && selectedNodeId !== null) {
Expand Down Expand Up @@ -703,6 +705,8 @@ export class TreeView<DisplayData: Object> extends React.PureComponent<
}
};

/* This method is used by users of this component. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
focus() {
if (this._list) {
this._list.focus();
Expand Down
6 changes: 6 additions & 0 deletions src/components/shared/VirtualList.js
Expand Up @@ -160,6 +160,8 @@ class VirtualListInner<Item> extends React.PureComponent<
this._container = element;
};

/* This method is used by users of this component. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
getBoundingClientRect() {
if (this._container) {
return this._container.getBoundingClientRect();
Expand Down Expand Up @@ -339,6 +341,8 @@ export class VirtualList<Item> extends React.PureComponent<
return { visibleRangeStart, visibleRangeEnd };
}

/* This method is used by users of this component. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
scrollItemIntoView(itemIndex: number, offsetX: CssPixels) {
const container = this._container.current;
if (!container) {
Expand Down Expand Up @@ -370,6 +374,8 @@ export class VirtualList<Item> extends React.PureComponent<
}
}

/* This method is used by users of this component. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
focus() {
const container = this._container.current;
if (container) {
Expand Down
3 changes: 0 additions & 3 deletions src/components/stack-chart/Canvas.js
Expand Up @@ -88,9 +88,6 @@ const FONT_SIZE = 10;
const BORDER_OPACITY = 0.4;

class StackChartCanvasImpl extends React.PureComponent<Props> {
_leftMarginGradient: null | CanvasGradient = null;
_rightMarginGradient: null | CanvasGradient = null;

componentDidUpdate(prevProps) {
// We want to scroll the selection into view when this component
// is mounted, but using componentDidMount won't work here as the
Expand Down
3 changes: 0 additions & 3 deletions src/components/timeline/EmptyThreadIndicator.js
Expand Up @@ -38,9 +38,6 @@ type Props = {|
* thread was shut down.
*/
class EmptyThreadIndicatorImpl extends PureComponent<Props> {
_canvas: HTMLCanvasElement | null;
_requestedAnimationFrame: boolean | null;

render() {
const style = getIndicatorPositions(this.props);
return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/timeline/OriginsTimeline.js
Expand Up @@ -72,7 +72,9 @@ class OriginsTimelineView extends React.PureComponent<Props, State> {
/**
* This method collects the initially selected track's HTMLElement. This allows the timeline
* to scroll the initially selected track into view once the page is loaded.
*/
* It's not used currently but it will be used when we implement this
* component better. */
/* eslint-disable-next-line react/no-unused-class-component-methods */
setInitialSelected = (el: InitialSelectedTrackReference) => {
this.setState({ initialSelected: el });
};
Expand Down
2 changes: 0 additions & 2 deletions src/components/tooltip/Tooltip.js
Expand Up @@ -29,8 +29,6 @@ type PositionFromMouse = 'before-mouse' | 'after-mouse';
type TooltipPosition = PositionFromMouse | 'window-edge';

export class Tooltip extends React.PureComponent<Props> {
_isMounted: boolean = false;
_isLayoutScheduled: boolean = false;
_interiorElementRef: {| current: HTMLDivElement | null |} = React.createRef();

// This keeps the previous tooltip positioning relatively to the mouse cursor.
Expand Down

0 comments on commit 1f3c1cb

Please sign in to comment.