From 4b5536478c30f898312b67c7480038d1b7791671 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Tue, 1 Oct 2024 16:09:13 +0200 Subject: [PATCH 1/4] ESLint: enable @typescript-eslint/ban-types This fixes the error: error Don't use `{}` as a type. `{}` actually means "any non-nullish value". - If you want a type meaning "any object", you probably want `object` instead. - If you want a type meaning "any value", you probably want `unknown` instead. - If you want a type meaning "empty object", you probably want `Record` instead. - If you really want a type meaning "any non-nullish value", you probably want `NonNullable` instead @typescript-eslint/ban-types --- .eslintrc | 3 +++ lib/ReactViews/Disclaimer.d.ts | 2 +- lib/ReactViews/DragDropNotification.d.ts | 2 +- lib/ReactViews/Map/Panels/HelpPanel/HelpPanel.d.ts | 2 +- lib/ReactViews/Tour/TourPortal.d.ts | 2 +- lib/ReactViews/WelcomeMessage/WelcomeMessage.d.ts | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.eslintrc b/.eslintrc index d30c30a8de..e9bb623786 100644 --- a/.eslintrc +++ b/.eslintrc @@ -33,6 +33,9 @@ } }, "rules": { + /* ban-types is split in ESLint v8: + https://typescript-eslint.io/rules/ban-types/ */ + "@typescript-eslint/ban-types": "error", "react-hooks/exhaustive-deps": "error", "react/jsx-boolean-value": ["error", "never", { "always": [] }], "react/no-arrow-function-lifecycle": "error", diff --git a/lib/ReactViews/Disclaimer.d.ts b/lib/ReactViews/Disclaimer.d.ts index 7c6ae10693..70c0b6bf9c 100644 --- a/lib/ReactViews/Disclaimer.d.ts +++ b/lib/ReactViews/Disclaimer.d.ts @@ -1,5 +1,5 @@ import React from "react"; -declare class Disclaimer extends React.Component<{}> {} +declare class Disclaimer extends React.Component {} export default Disclaimer; diff --git a/lib/ReactViews/DragDropNotification.d.ts b/lib/ReactViews/DragDropNotification.d.ts index 33b2a35345..5f1b70e96d 100644 --- a/lib/ReactViews/DragDropNotification.d.ts +++ b/lib/ReactViews/DragDropNotification.d.ts @@ -1,5 +1,5 @@ import React from "react"; -declare class DragDropNotification extends React.Component<{}> {} +declare class DragDropNotification extends React.Component {} export default DragDropNotification; diff --git a/lib/ReactViews/Map/Panels/HelpPanel/HelpPanel.d.ts b/lib/ReactViews/Map/Panels/HelpPanel/HelpPanel.d.ts index 807fe6c1d6..c8c01c27f8 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/HelpPanel.d.ts +++ b/lib/ReactViews/Map/Panels/HelpPanel/HelpPanel.d.ts @@ -1,4 +1,4 @@ import React from "react"; -declare class HelpPanel extends React.Component<{}> {} +declare class HelpPanel extends React.Component {} export default HelpPanel; diff --git a/lib/ReactViews/Tour/TourPortal.d.ts b/lib/ReactViews/Tour/TourPortal.d.ts index d7392d851b..9b38e2b875 100644 --- a/lib/ReactViews/Tour/TourPortal.d.ts +++ b/lib/ReactViews/Tour/TourPortal.d.ts @@ -1,6 +1,6 @@ export declare const TourExplanation: React.FC; export declare const TourPreface: React.FC; -declare const TourPortal: React.FC<{}>; +declare const TourPortal: React.FC; export default TourPortal; diff --git a/lib/ReactViews/WelcomeMessage/WelcomeMessage.d.ts b/lib/ReactViews/WelcomeMessage/WelcomeMessage.d.ts index 858b381635..edeaf484c3 100644 --- a/lib/ReactViews/WelcomeMessage/WelcomeMessage.d.ts +++ b/lib/ReactViews/WelcomeMessage/WelcomeMessage.d.ts @@ -8,5 +8,5 @@ interface WelcomeMessagePurePropsType { export declare const WelcomeMessagePure: React.FC; -declare class WelcomeMessage extends React.Component<{}> {} +declare class WelcomeMessage extends React.Component {} export default WelcomeMessage; From c8b8bf57541174339b47633c83c170a59de81272 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Tue, 1 Oct 2024 16:32:58 +0200 Subject: [PATCH 2/4] ESLint: return from onToggle functions This makes the return type correspond to the boolean that the comment at the interface suggests. --- lib/ReactViews/Notification/terriaErrorNotification.tsx | 2 +- lib/ReactViews/SelectableDimensions/Group.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ReactViews/Notification/terriaErrorNotification.tsx b/lib/ReactViews/Notification/terriaErrorNotification.tsx index 58cfe94249..1edf9558b8 100644 --- a/lib/ReactViews/Notification/terriaErrorNotification.tsx +++ b/lib/ReactViews/Notification/terriaErrorNotification.tsx @@ -125,7 +125,7 @@ export const terriaErrorNotification = (error: TerriaError) => bodyBoxProps={{ padded: true }} isOpen={error.showDetails} onToggle={(show) => { - runInAction(() => (error.showDetails = show)); + return runInAction(() => (error.showDetails = show)); }} > diff --git a/lib/ReactViews/SelectableDimensions/Group.tsx b/lib/ReactViews/SelectableDimensions/Group.tsx index 1df8d3e241..58b01d72d6 100644 --- a/lib/ReactViews/SelectableDimensions/Group.tsx +++ b/lib/ReactViews/SelectableDimensions/Group.tsx @@ -48,11 +48,13 @@ export const SelectableDimensionGroup: React.FC<{ onToggle={ dim.type === "group" ? dim.onToggle - : (isOpen) => + : (isOpen) => { dim.setDimensionValue( CommonStrata.user, isOpen ? "true" : "false" - ) + ); + return true; + } } btnStyle={dim.type === "checkbox-group" ? "checkbox" : undefined} btnRight={dim.type === "group"} From 803e50d8836d96cce2224bcd09e516cb35e6107a Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Tue, 1 Oct 2024 16:41:48 +0200 Subject: [PATCH 3/4] ESLint: enable @typescript-eslint/unified-signatures There is a single type signature that does not pass this check in the current code base, so update that signature and enable the lint rule. --- .eslintrc | 1 + lib/Models/Definition/addModelStrataView.ts | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.eslintrc b/.eslintrc index e9bb623786..871d079e60 100644 --- a/.eslintrc +++ b/.eslintrc @@ -36,6 +36,7 @@ /* ban-types is split in ESLint v8: https://typescript-eslint.io/rules/ban-types/ */ "@typescript-eslint/ban-types": "error", + "@typescript-eslint/unified-signatures": "error", "react-hooks/exhaustive-deps": "error", "react/jsx-boolean-value": ["error", "never", { "always": [] }], "react/no-arrow-function-lifecycle": "error", diff --git a/lib/Models/Definition/addModelStrataView.ts b/lib/Models/Definition/addModelStrataView.ts index 61cf9b6aab..7269daec4f 100644 --- a/lib/Models/Definition/addModelStrataView.ts +++ b/lib/Models/Definition/addModelStrataView.ts @@ -14,14 +14,11 @@ import ModelPropertiesFromTraits from "./ModelPropertiesFromTraits"; export default function addModelStrataView< T extends TraitsConstructor >( - model: Stratified>, + /* TODO: Use a more specific type than "Function". */ + /* eslint-disable-next-line @typescript-eslint/ban-types */ + model: Stratified> | Function, Traits: T ): ModelPropertiesFromTraits>; -export default function addModelStrataView< - T extends TraitsConstructor - /* TODO: Fix this overload type */ - /* eslint-disable-next-line @typescript-eslint/ban-types */ ->(model: Function, Traits: T): ModelPropertiesFromTraits>; export default function addModelStrataView< T extends TraitsConstructor >(model: any, Traits: T): ModelPropertiesFromTraits> { From 09f699409836b92b7a7aabc031c519e85fbdcf93 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Tue, 1 Oct 2024 17:16:14 +0200 Subject: [PATCH 4/4] ESLint: enable @typescript-eslint/no-useless-constructor Remove constructors that just call super() with their arguments and enable @typescript-eslint/no-useless-constructor. --- .eslintrc | 4 ++++ .../CatalogReferences/ThreddsItemReference.ts | 12 ------------ lib/Models/Catalog/CatalogReferences/UrlReference.ts | 11 ----------- .../Catalog/Gtfs/GtfsRealtimeProtoBufReaders.ts | 4 ---- lib/ReactViews/Disclaimer.jsx | 4 ---- .../Map/MapNavigation/Items/MapNavigationItem.tsx | 4 ---- .../Map/MapNavigation/Items/ZoomControl.tsx | 4 ---- .../Map/Panels/HelpPanel/HelpPanelItem.jsx | 4 ---- .../Map/Panels/HelpPanel/HelpVideoPanel.jsx | 4 ---- lib/ReactViews/Map/Panels/HelpPanel/StyledHtml.jsx | 4 ---- lib/ReactViews/Map/Panels/HelpPanel/TrainerPane.jsx | 4 ---- lib/ReactViews/Map/Panels/HelpPanel/VideoGuide.jsx | 4 ---- lib/ReactViews/RelatedMaps/RelatedMaps.tsx | 7 ------- lib/Table/createLongitudeLatitudeFeaturePerId.ts | 2 -- lib/Traits/Decorators/anyTrait.ts | 4 ---- .../SearchProviders/SearchProviderMixinSpec.ts | 4 ---- 16 files changed, 4 insertions(+), 76 deletions(-) diff --git a/.eslintrc b/.eslintrc index 871d079e60..3181f1c0e7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -117,6 +117,10 @@ { "files": ["**/*.ts", "**/*.tsx"], "rules": { + /* The no-useless-constructor needs to be disabled for + the @typescript-eslint-rule. */ + "no-useless-constructor": "off", + "@typescript-eslint/no-useless-constructor": "error", // @TODO: revise these rules "@typescript-eslint/consistent-type-assertions": "error", "no-unused-vars": "off", diff --git a/lib/Models/Catalog/CatalogReferences/ThreddsItemReference.ts b/lib/Models/Catalog/CatalogReferences/ThreddsItemReference.ts index 34f86a1847..257c119ba3 100644 --- a/lib/Models/Catalog/CatalogReferences/ThreddsItemReference.ts +++ b/lib/Models/Catalog/CatalogReferences/ThreddsItemReference.ts @@ -3,7 +3,6 @@ import { runInAction } from "mobx"; import ReferenceMixin from "../../../ModelMixins/ReferenceMixin"; import UrlMixin from "../../../ModelMixins/UrlMixin"; import ThreddsItemReferenceTraits from "../../../Traits/TraitsClasses/ThreddsItemReferenceTraits"; -import ModelTraits from "../../../Traits/ModelTraits"; import ThreddsCatalogGroup, { ThreddsDataset } from "../CatalogGroups/ThreddsCatalogGroup"; @@ -11,9 +10,7 @@ import CatalogMemberFactory from "../CatalogMemberFactory"; import CreateModel from "../../Definition/CreateModel"; import LoadableStratum from "../../Definition/LoadableStratum"; import { BaseModel } from "../../Definition/Model"; -import StratumFromTraits from "../../Definition/StratumFromTraits"; import StratumOrder from "../../Definition/StratumOrder"; -import Terria from "../../Terria"; import WebMapServiceCatalogGroup from "../Ows/WebMapServiceCatalogGroup"; export class ThreddsDatasetStratum extends LoadableStratum( @@ -71,15 +68,6 @@ export default class ThreddsItemReference extends UrlMixin( _threddsDataset: ThreddsDataset | undefined = undefined; _threddsCatalogGroup: ThreddsCatalogGroup | undefined = undefined; - constructor( - id: string | undefined, - terria: Terria, - sourceReference?: BaseModel, - strata?: Map> - ) { - super(id, terria, sourceReference, strata); - } - setDataset(dataset: ThreddsDataset) { this._threddsDataset = dataset; } diff --git a/lib/Models/Catalog/CatalogReferences/UrlReference.ts b/lib/Models/Catalog/CatalogReferences/UrlReference.ts index 4fdf4c6134..2d0fea98b3 100644 --- a/lib/Models/Catalog/CatalogReferences/UrlReference.ts +++ b/lib/Models/Catalog/CatalogReferences/UrlReference.ts @@ -3,9 +3,7 @@ import UrlMixin from "../../../ModelMixins/UrlMixin"; import CatalogMemberFactory from "../CatalogMemberFactory"; import CreateModel from "../../Definition/CreateModel"; import { BaseModel } from "../../Definition/Model"; -import StratumFromTraits from "../../Definition/StratumFromTraits"; import Terria from "../../Terria"; -import ModelTraits from "../../../Traits/ModelTraits"; import UrlReferenceTraits from "../../../Traits/TraitsClasses/UrlReferenceTraits"; import StratumOrder from "../../Definition/StratumOrder"; import CatalogMemberMixin from "../../../ModelMixins/CatalogMemberMixin"; @@ -23,15 +21,6 @@ export default class UrlReference extends UrlMixin( return UrlReference.type; } - constructor( - id: string | undefined, - terria: Terria, - sourceReference?: BaseModel, - strata?: Map> - ) { - super(id, terria, sourceReference, strata); - } - protected forceLoadReference( _previousTarget: BaseModel | undefined ): Promise { diff --git a/lib/Models/Catalog/Gtfs/GtfsRealtimeProtoBufReaders.ts b/lib/Models/Catalog/Gtfs/GtfsRealtimeProtoBufReaders.ts index ceb7eb76a6..a6f6af746c 100644 --- a/lib/Models/Catalog/Gtfs/GtfsRealtimeProtoBufReaders.ts +++ b/lib/Models/Catalog/Gtfs/GtfsRealtimeProtoBufReaders.ts @@ -29,10 +29,6 @@ export class FeedMessageReader extends ProtobufMessageReader { entity: [] }; - constructor() { - super(); - } - protected readField(tag: number, obj?: FeedMessage, pbf?: Pbf): void { if (pbf === null || pbf === undefined) { return; diff --git a/lib/ReactViews/Disclaimer.jsx b/lib/ReactViews/Disclaimer.jsx index a6b4479c0f..46ffd468ee 100644 --- a/lib/ReactViews/Disclaimer.jsx +++ b/lib/ReactViews/Disclaimer.jsx @@ -51,10 +51,6 @@ class Disclaimer extends React.Component { t: PropTypes.func.isRequired }; - constructor(props) { - super(props); - } - confirm(confirmCallbackFn) { if (confirmCallbackFn) { confirmCallbackFn(); diff --git a/lib/ReactViews/Map/MapNavigation/Items/MapNavigationItem.tsx b/lib/ReactViews/Map/MapNavigation/Items/MapNavigationItem.tsx index 7cf03c5e46..85aae8eaef 100644 --- a/lib/ReactViews/Map/MapNavigation/Items/MapNavigationItem.tsx +++ b/lib/ReactViews/Map/MapNavigation/Items/MapNavigationItem.tsx @@ -20,10 +20,6 @@ interface PropTypes { @observer class MapNavigationItemBase extends React.Component { - constructor(props: PropTypes) { - super(props); - } - render() { const { closeTool = true, item, expandInPlace, i18n } = this.props; if (item.render) diff --git a/lib/ReactViews/Map/MapNavigation/Items/ZoomControl.tsx b/lib/ReactViews/Map/MapNavigation/Items/ZoomControl.tsx index 4697d8c173..44e4875fbf 100644 --- a/lib/ReactViews/Map/MapNavigation/Items/ZoomControl.tsx +++ b/lib/ReactViews/Map/MapNavigation/Items/ZoomControl.tsx @@ -31,10 +31,6 @@ export const ZOOM_CONTROL_ID = "zoom"; class ZoomControlBase extends React.Component { static displayName = "ZoomControl"; - constructor(props: PropTypes) { - super(props); - } - flyToPosition( scene: Scene, position: Cartesian3, diff --git a/lib/ReactViews/Map/Panels/HelpPanel/HelpPanelItem.jsx b/lib/ReactViews/Map/Panels/HelpPanel/HelpPanelItem.jsx index c2bca7af62..5747beab04 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/HelpPanelItem.jsx +++ b/lib/ReactViews/Map/Panels/HelpPanel/HelpPanelItem.jsx @@ -26,10 +26,6 @@ class HelpPanelItem extends React.Component { i18n: PropTypes.object.isRequired }; - constructor(props) { - super(props); - } - render() { const { i18n } = this.props; diff --git a/lib/ReactViews/Map/Panels/HelpPanel/HelpVideoPanel.jsx b/lib/ReactViews/Map/Panels/HelpPanel/HelpVideoPanel.jsx index 93101fe8cf..9fd972dacf 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/HelpVideoPanel.jsx +++ b/lib/ReactViews/Map/Panels/HelpPanel/HelpVideoPanel.jsx @@ -34,10 +34,6 @@ class HelpVideoPanel extends React.Component { i18n: PropTypes.object.isRequired }; - constructor(props) { - super(props); - } - render() { const helpItemType = this.props.paneMode || "videoAndContent"; // default is video panel const itemSelected = diff --git a/lib/ReactViews/Map/Panels/HelpPanel/StyledHtml.jsx b/lib/ReactViews/Map/Panels/HelpPanel/StyledHtml.jsx index f1a019e774..06213c2548 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/StyledHtml.jsx +++ b/lib/ReactViews/Map/Panels/HelpPanel/StyledHtml.jsx @@ -51,10 +51,6 @@ export class StyledHtmlRaw extends React.Component { injectTooltips: true }; - constructor(props) { - super(props); - } - render() { const { viewState, injectTooltips, i18n } = this.props; const styledTextProps = this.props.styledTextProps || {}; diff --git a/lib/ReactViews/Map/Panels/HelpPanel/TrainerPane.jsx b/lib/ReactViews/Map/Panels/HelpPanel/TrainerPane.jsx index 73fa0a75e3..05ebecb4aa 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/TrainerPane.jsx +++ b/lib/ReactViews/Map/Panels/HelpPanel/TrainerPane.jsx @@ -33,10 +33,6 @@ class TrainerPane extends React.Component { i18n: PropTypes.object.isRequired }; - constructor(props) { - super(props); - } - render() { const { content, i18n, viewState } = this.props; const { trainerItems, markdownText } = content; diff --git a/lib/ReactViews/Map/Panels/HelpPanel/VideoGuide.jsx b/lib/ReactViews/Map/Panels/HelpPanel/VideoGuide.jsx index 9fb0fead6a..bfec5ad568 100644 --- a/lib/ReactViews/Map/Panels/HelpPanel/VideoGuide.jsx +++ b/lib/ReactViews/Map/Panels/HelpPanel/VideoGuide.jsx @@ -69,10 +69,6 @@ class VideoGuide extends React.Component { t: PropTypes.func }; - constructor(props) { - super(props); - } - render() { const backgroundOpacity = this.props.backgroundOpacity; const backgroundBlackOverlay = diff --git a/lib/ReactViews/RelatedMaps/RelatedMaps.tsx b/lib/ReactViews/RelatedMaps/RelatedMaps.tsx index 3f7cf62d38..3b917f229c 100644 --- a/lib/ReactViews/RelatedMaps/RelatedMaps.tsx +++ b/lib/ReactViews/RelatedMaps/RelatedMaps.tsx @@ -20,13 +20,6 @@ type PropTypes = WithViewState & @observer class RelatedMaps extends React.Component { - /** - * @param {Props} props - */ - constructor(props: PropTypes) { - super(props); - } - render() { const t = this.props.t; const dropdownTheme = { diff --git a/lib/Table/createLongitudeLatitudeFeaturePerId.ts b/lib/Table/createLongitudeLatitudeFeaturePerId.ts index 805e2256f2..e0ad39b0fb 100644 --- a/lib/Table/createLongitudeLatitudeFeaturePerId.ts +++ b/lib/Table/createLongitudeLatitudeFeaturePerId.ts @@ -119,8 +119,6 @@ class PreSampledPositionProperty { private allValuesAreTheSame = true; - constructor() {} - getProperty() { if (this.allValuesAreTheSame) { return new ConstantPositionProperty(this.values[0]); diff --git a/lib/Traits/Decorators/anyTrait.ts b/lib/Traits/Decorators/anyTrait.ts index a7a9517c29..94757f89d1 100644 --- a/lib/Traits/Decorators/anyTrait.ts +++ b/lib/Traits/Decorators/anyTrait.ts @@ -22,10 +22,6 @@ export default function anyTrait(options: TraitOptions) { export class AnyTrait extends Trait { readonly decoratorForFlattened = computed.struct; - constructor(id: string, options: AnyTraitOptions, parent: any) { - super(id, options, parent); - } - getValue(model: BaseModel): any { for (const stratum of model.strataTopToBottom.values()) { const stratumAny: any = stratum; diff --git a/test/ModelMixins/SearchProviders/SearchProviderMixinSpec.ts b/test/ModelMixins/SearchProviders/SearchProviderMixinSpec.ts index 44227b8735..4b0b50048c 100644 --- a/test/ModelMixins/SearchProviders/SearchProviderMixinSpec.ts +++ b/test/ModelMixins/SearchProviders/SearchProviderMixinSpec.ts @@ -9,10 +9,6 @@ class TestSearchProvider extends SearchProviderMixin( ) { type = "test"; - constructor(uniqueId: string | undefined, terria: Terria) { - super(uniqueId, terria); - } - public override logEvent = jasmine.createSpy(); public override doSearch = jasmine .createSpy()