From 1d6522b5f73bdd20d8158d2324a1d4086c063092 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Wed, 15 Nov 2023 12:54:06 +0100 Subject: [PATCH] Fix code style according to new linting rules --- src/providers/base-provider.js | 36 ++++++++++++++----- .../label-search-suggestion-provider.js | 4 ++- src/providers/mycore-provider.js | 4 ++- src/providers/skohub-provider.js | 12 +++++-- test/providers/base-provider.js | 8 +++-- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/providers/base-provider.js b/src/providers/base-provider.js index 433ddfa..c1a1d70 100644 --- a/src/providers/base-provider.js +++ b/src/providers/base-provider.js @@ -190,7 +190,9 @@ export default class BaseProvider { ) { error.config._retryCount = count + 1 // from: https://github.com/axios/axios/issues/934#issuecomment-531463172 - if (error.config.data) error.config.data = JSON.parse(error.config.data) + if (error.config.data) { + error.config.data = JSON.parse(error.config.data) + } return new Promise((resolve, reject) => { setTimeout(() => { this.axios(error.config).then(resolve).catch(reject) @@ -212,7 +214,9 @@ export default class BaseProvider { // Make sure all methods exist, but thrown an error if they are not implemented const existingMethod = this[method] && this[method].bind(this) if (!existingMethod) { - this[method] = () => { throw new errors.MethodNotImplementedError({ method }) } + this[method] = () => { + throw new errors.MethodNotImplementedError({ method }) + } continue } this[method] = (options = {}) => { @@ -295,13 +299,27 @@ export default class BaseProvider { } // Expose some properties from original registry object as getters - get uri() { return this._jskos.uri } - get notation() { return this._jskos.notation } - get prefLabel() { return this._jskos.prefLabel } - get definition() { return this._jskos.definition } - get schemes() { return this._jskos.schemes } - get excludedSchemes() { return this._jskos.excludedSchemes } - get stored() { return this._jskos.stored !== undefined ? this._jskos.stored : this.constructor.stored } + get uri() { + return this._jskos.uri + } + get notation() { + return this._jskos.notation + } + get prefLabel() { + return this._jskos.prefLabel + } + get definition() { + return this._jskos.definition + } + get schemes() { + return this._jskos.schemes + } + get excludedSchemes() { + return this._jskos.excludedSchemes + } + get stored() { + return this._jskos.stored !== undefined ? this._jskos.stored : this.constructor.stored + } /** * Load data about registry via the status endpoint. diff --git a/src/providers/label-search-suggestion-provider.js b/src/providers/label-search-suggestion-provider.js index 12cdfcc..de6896c 100644 --- a/src/providers/label-search-suggestion-provider.js +++ b/src/providers/label-search-suggestion-provider.js @@ -140,7 +140,9 @@ export default class LabelSearchSuggestionProvider extends BaseProvider { fallbackToUri: false, language, }) - if (!label) continue + if (!label) { + continue + } results = await this._getResults({ ...config, label, targetScheme, limit }) // Stop if there are results from a broader concept if (results.length) { diff --git a/src/providers/mycore-provider.js b/src/providers/mycore-provider.js index 00c7d47..ce6bd95 100644 --- a/src/providers/mycore-provider.js +++ b/src/providers/mycore-provider.js @@ -132,7 +132,9 @@ export default class MyCoReProvider extends BaseProvider { * Helper function that replaces `narrower` key with [null] if it has values. Use this before returning concepts. */ _removeNarrower(concept) { - if (!concept) return concept + if (!concept) { + return concept + } return Object.assign({}, concept, { narrower: (concept.narrower && concept.narrower.length) ? [null] : []}) } diff --git a/src/providers/skohub-provider.js b/src/providers/skohub-provider.js index 34dc813..eef6129 100644 --- a/src/providers/skohub-provider.js +++ b/src/providers/skohub-provider.js @@ -61,9 +61,15 @@ export default class SkohubProvider extends BaseProvider { } } - get _index() { return data[this.uri] && data[this.uri].index } - get _conceptCache() { return data[this.uri] && data[this.uri].conceptCache } - get _schemeCache() { return data[this.uri] && data[this.uri].schemeCache } + get _index() { + return data[this.uri] && data[this.uri].index + } + get _conceptCache() { + return data[this.uri] && data[this.uri].conceptCache + } + get _schemeCache() { + return data[this.uri] && data[this.uri].schemeCache + } /** * Used by `registryForScheme` (see src/lib/CocodaSDK.js) to determine a provider config for a concept schceme. diff --git a/test/providers/base-provider.js b/test/providers/base-provider.js index 8f89eb5..57c913f 100644 --- a/test/providers/base-provider.js +++ b/test/providers/base-provider.js @@ -16,7 +16,9 @@ describe("BaseProvider", () => { }) it("should initialize without parameters", () => { - assert.doesNotThrow(() => { provider = getProvider() }) + assert.doesNotThrow(() => { + provider = getProvider() + }) }) it("should have certain properties", () => { @@ -32,7 +34,9 @@ describe("BaseProvider", () => { for (let { method } of utils.requestMethods) { assert.ok(!!provider[method], `could not find method ${method}`) // All request methods should throw by default - await assert.rejects(async () => { await provider[method]() }, `method ${method} does not throw by default`) + await assert.rejects(async () => { + await provider[method]() + }, `method ${method} does not throw by default`) } })