From fc0209dc8de28420fb17273be88fdeef15e36843 Mon Sep 17 00:00:00 2001 From: Alexandre Caron Date: Wed, 26 Feb 2025 09:18:42 -0500 Subject: [PATCH] fix: refactor OptionsApiService for better handling of source options and enhance ESLint rules --- eslint.config.mjs | 8 +++- .../shared/options/options-api.service.ts | 44 +++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 460258377..0ded7a008 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -47,7 +47,13 @@ export default tseslint.config( ], '@typescript-eslint/no-unused-vars': [ 'error', - { args: 'after-used', destructuredArrayIgnorePattern: '^_' } + { + vars: 'all', + args: 'after-used', + ignoreRestSiblings: true, + argsIgnorePattern: '^_', + destructuredArrayIgnorePattern: '^_' + } ], 'arrow-spacing': 'error', eqeqeq: ['error', 'smart'], diff --git a/packages/geo/src/lib/datasource/shared/options/options-api.service.ts b/packages/geo/src/lib/datasource/shared/options/options-api.service.ts index 6b60d1fca..77734764a 100644 --- a/packages/geo/src/lib/datasource/shared/options/options-api.service.ts +++ b/packages/geo/src/lib/datasource/shared/options/options-api.service.ts @@ -5,6 +5,7 @@ import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { + AnyDataSourceOptions, ArcGISRestDataSourceOptions, ArcGISRestImageDataSourceOptions, TileArcGISRestDataSourceOptions, @@ -57,16 +58,8 @@ export class OptionsApiService extends OptionsService { map( (res: { sourceOptions: WMSDataSourceOptions; - layerOptions: Record; - }) => { - if (!res || !res.sourceOptions) { - return {} as WMSDataSourceOptions; - } - if (res.layerOptions) { - res.sourceOptions._layerOptionsFromSource = res.layerOptions; - } - return res.sourceOptions; - } + layerOptions: { [keys: string]: string }; + }) => this.handleSourceOptions(res) ) ); } @@ -108,20 +101,25 @@ export class OptionsApiService extends OptionsService { | ArcGISRestDataSourceOptions | ArcGISRestImageDataSourceOptions | TileArcGISRestDataSourceOptions; - layerOptions: Record; - }) => { - if (!res || !res.sourceOptions) { - return {} as - | ArcGISRestDataSourceOptions - | ArcGISRestImageDataSourceOptions - | TileArcGISRestDataSourceOptions; - } - if (res.layerOptions) { - res.sourceOptions._layerOptionsFromSource = res.layerOptions; - } - return res.sourceOptions; - } + layerOptions: { [keys: string]: string }; + }) => this.handleSourceOptions(res) ) ); } + + private handleSourceOptions(res: { + sourceOptions: T; + layerOptions: { [keys: string]: string }; + }) { + if (!res || !res.sourceOptions) { + return {} as WMSDataSourceOptions; + } + if (res.layerOptions) { + res.sourceOptions._layerOptionsFromSource = res.layerOptions; + } else { + const { sourceOptions: _1, layerOptions: _2, ...restOptions } = res; + res.sourceOptions._layerOptionsFromSource = restOptions; + } + return res.sourceOptions; + } }