Skip to content

Commit

Permalink
eslint: warn about unused directives
Browse files Browse the repository at this point in the history
Make ESLint warn when directives
are not used, and remove the unused
directives from the source code.

The no-empty rule needs a comment
rather than an ignore directive
in empty catch blocks, so tweak
the config of the rule to admit
empty catch blocks, and report
on other empty bodies.
  • Loading branch information
pjonsson committed Dec 18, 2024
1 parent 9013ebe commit bcb4bac
Show file tree
Hide file tree
Showing 29 changed files with 34 additions and 111 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module.exports = {
"no-alert": ["error"],
"no-caller": ["error"],
"no-div-regex": ["error"],
"no-empty": ["error", { allowEmptyCatch: true }],
"no-eval": ["error"],
"no-extend-native": ["error"],
"no-fallthrough": 0,
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ gulp.task("lint", function (done) {
"--ext",
".jsx,.js,.ts,.tsx",
"--max-warnings",
"0"
"0",
"--report-unused-disable-directives"
]);

done();
Expand Down
4 changes: 1 addition & 3 deletions lib/ModelMixins/DiscretelyTimeVaryingMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ function DiscretelyTimeVaryingMixin<
tag: dt.tag !== undefined ? dt.tag : dt.time
});
}
} catch {
/* eslint-disable-line no-empty */
}
} catch {}
}
asJulian.sort((a, b) => JulianDate.compare(a.time, b.time));
return asJulian;
Expand Down
4 changes: 1 addition & 3 deletions lib/Models/Catalog/CatalogItems/CartoMapV3CatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ async function callCartoApi(url: string, auth?: string, body?: JsonObject) {
)
);
}
} catch {
/* eslint-disable-line no-empty */
}
} catch {}
}
return Result.error(e);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Models/Catalog/Ows/WebFeatureServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ class WebFeatureServiceCatalogItem extends GetCapabilitiesMixin(
let errorMessage: string | undefined;
try {
errorMessage = xml2json(getFeatureResponse).Exception?.ExceptionText;
} catch {
/* eslint-disable-line no-empty */
}
} catch {}

const originalError = isDefined(errorMessage)
? new TerriaError({
Expand Down
2 changes: 0 additions & 2 deletions lib/ReactViews/Analytics/InvokeFunction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ class InvokeFunction extends React.Component {
t: PropTypes.func.isRequired
};

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this.parametersViewModel = new FunctionViewModel(this.props.previewed);
}

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillUpdate(nextProps, _nextState) {
if (nextProps.previewed !== this.parametersViewModel.catalogFunction) {
// Clear previous parameters view model, because this is a different catalog function.
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Analytics/RegionPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const RegionPicker = createReactClass({
};
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this._loadingRegionProvider = undefined;
this._selectedRegionCatalogItem = undefined;
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/CleanDropdownPanel/CleanDropdownPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const CleanDropdownPanel = createReactClass({
}
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.forceClosed) {
this.onDismissed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class ChartExpandAndDownloadButtons extends React.Component<PropsType> {

try {
terria.addModel(itemToExpand);
} catch {
/* eslint-disable-line no-empty */
}
} catch {}
(await workbench.add(itemToExpand)).raiseError(terria, undefined, true);
});
}
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Custom/parseCustomHtmlToReact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function getProcessingInstructions(context: ParseCustomHtmlToReactContext) {
shouldProcessNode: (node: DomElement) => node.name === "a",
processNode: function (node: DomElement, children, index) {
// Make sure any <a href> tags open in a new window
// eslint-disable-line react/display-name
const elementProps = {
key: "anchor-" + keyIndex++,
target: "_blank",
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Generic/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const Dropdown = createReactClass({
};
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
// this._element is updated by the ref callback attribute, https://facebook.github.io/react/docs/more-about-refs.html
this.buttonElement = undefined;
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Generic/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable camelcase */
import React, { useRef } from "react";
import { Editor } from "@tinymce/tinymce-react";
import PropTypes from "prop-types";
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/HOCs/withControlledVisibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface WithControlledVisibilityProps {
* as prop
*/
export default <P extends object>(WrappedComponent: React.ComponentType<P>) => {
// eslint-disable-next-line require-jsdoc
function WithControlledVisibility({
elementConfig,
...props
Expand Down
2 changes: 0 additions & 2 deletions lib/ReactViews/Map/Panels/DropdownPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const DropdownPanel = createReactClass({
}
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.forceClosed) {
this.onDismissed();
Expand Down Expand Up @@ -99,7 +98,6 @@ const DropdownPanel = createReactClass({
ref={
this.props.btnRef || ((element) => (this.buttonElement = element))
}
/* eslint-disable-next-line react/no-unknown-property */
isOpen={this.isOpen()}
css={`
${(p) =>
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Map/Panels/InnerPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const InnerPanel = createReactClass({
onClick={this.forceClose}
title={t("general.close")}
aria-label={t("general.close")}
/* eslint-disable-next-line react/no-unknown-property */
showDropdownAsModal={this.props.showDropdownAsModal}
css={`
svg {
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Map/Panels/SharePanel/StorySharePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const StorySharePanel = createReactClass({
}
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.forceClosed) {
this.onDismissed();
Expand Down
4 changes: 1 addition & 3 deletions lib/ReactViews/Map/TerriaViewerWrapper/Splitter/dragHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ try {

window.addEventListener("test", callback, options);
window.removeEventListener("test", callback, options);
} catch (_err) {
/* eslint-disable-line no-empty */
}
} catch (_err) {}

const notPassive = passiveSupported ? { passive: false } : false;

Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Mobile/MobileModalWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class MobileModalWindow extends React.Component {
});
}

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillReceiveProps() {
const numItems = this.props.terria.workbench.items.length;
if (
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Notification/NotificationWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const NotificationWindow = createReactClass({
<div className={classNames(Styles.wrapper, `${type}`)}>
<div
className={Styles.notification}
/* eslint-disable-next-line react/no-unknown-property */
isStory={isStory}
css={`
background: ${(p) =>
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Search/SearchBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const SearchBox = createReactClass({
};
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this.searchWithDebounce = debounce(this.search, DEBOUNCE_INTERVAL);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import PropTypes from "prop-types";
* passed to it is true or false.
*/
export default (LargeScreenComponent, SmallScreenComponent) => {
// eslint-disable-next-line require-jsdoc
function ResponsiveSwitch(props) {
return props.smallScreen ? (
<SmallScreenComponent {...props} />
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Story/StoryEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class StoryEditor extends React.Component {
this.escKeyListener = null;
}

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
const story = this.props.story;
this.setState({
Expand Down
4 changes: 1 addition & 3 deletions lib/ReactViews/Tools/DiffTool/DiffTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ class DiffTool extends React.Component<PropsType> {
this.leftItem = leftItem;
this.rightItem = rightItem;
});
} catch {
/* eslint-disable-line no-empty */
}
} catch {}
}

@action
Expand Down
3 changes: 1 addition & 2 deletions lib/ReactViews/Workbench/Controls/ColorScaleRangeSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ const ColorScaleRangeSection = createReactClass({
};
},

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
this.setState({
minRange: this.props.minValue,
maxRange: this.props.maxValue
});
},
/* eslint-disable-next-line camelcase */

UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({
minRange: nextProps.minValue,
Expand Down
1 change: 0 additions & 1 deletion lib/ReactViews/Workbench/Controls/ViewingControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class ViewingControls extends React.Component<
};
}

/* eslint-disable-next-line camelcase */
UNSAFE_componentWillMount() {
window.addEventListener("click", this.hideMenu.bind(this));
}
Expand Down
Loading

0 comments on commit bcb4bac

Please sign in to comment.