Skip to content

Commit

Permalink
Fix code style according to new linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Nov 15, 2023
1 parent 3cd7eee commit 1d6522b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
36 changes: 27 additions & 9 deletions src/providers/base-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {}) => {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/providers/label-search-suggestion-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/providers/mycore-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] : []})
}

Expand Down
12 changes: 9 additions & 3 deletions src/providers/skohub-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions test/providers/base-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe("BaseProvider", () => {
})

it("should initialize without parameters", () => {
assert.doesNotThrow(() => { provider = getProvider() })
assert.doesNotThrow(() => {
provider = getProvider()
})
})

it("should have certain properties", () => {
Expand All @@ -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`)
}
})

Expand Down

0 comments on commit 1d6522b

Please sign in to comment.