Skip to content

Commit

Permalink
Enable unicorn no-await-expression-member and prefer-add-event-listener
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Aug 21, 2023
1 parent ac3925a commit 408c59f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ module.exports = {
'unicorn/consistent-destructuring': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-empty-file': 'off',
'unicorn/no-new-array': 'off',
'unicorn/no-null': 'off',
'unicorn/prefer-add-event-listener': 'off',
'unicorn/prefer-array-some': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prevent-abbreviations': 'off',
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-collaboration-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async function mongoDBURIFactory(
const uriFile = configService.get('MONGODB_URI_FILE', {
infer: true,
})!
uri = (await fs.readFile(uriFile, 'utf8')).trim()
const uriFileText = await fs.readFile(uriFile, 'utf8')
uri = uriFileText.trim()
}
return {
uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ async function jwtConfigFactory(
if (!jwtSecret) {
// We can use non-null assertion since joi already checks this for us
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const uriFile = configService.get('JWT_SECRET_FILE', {
const jwtFile = configService.get('JWT_SECRET_FILE', {
infer: true,
})!
jwtSecret = (await fs.readFile(uriFile, 'utf8')).trim()
const jwtFileText = await fs.readFile(jwtFile, 'utf8')
jwtSecret = jwtFileText.trim()
}
return { secret: jwtSecret, signOptions: { expiresIn: '1d' } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export async function textSearch(
tx?: Transaction<['nodes']>,
signal?: AbortSignal,
) {
const myTx = tx ?? (await this.db).transaction(['nodes'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes'])

checkAbortSignal(signal)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ describe('OntologyStore', () => {
expect(ex).toEqual(['http://purl.obolibrary.org/obo/SO_0000039'])
})
it('can query valid part_of for match', async () => {
const parentTypeTerms = (
await so.getTermsWithLabelOrSynonym('match', {
includeSubclasses: false,
})
const parentTypeTerms = await so.getTermsWithLabelOrSynonym('match', {
includeSubclasses: false,
})
// eslint-disable-next-line unicorn/no-array-callback-reference
const parentTypeClassTerms = parentTypeTerms.filter(isOntologyClass)
expect(parentTypeClassTerms).toMatchSnapshot()
const subpartTerms = await so.getClassesThat(
'part_of',
parentTypeClassTerms,
)
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isOntologyClass)
expect(parentTypeTerms).toMatchSnapshot()
const subpartTerms = await so.getClassesThat('part_of', parentTypeTerms)
expect(subpartTerms.length).toBeGreaterThan(0)
})

it('SO clone_insert_end is among valid subparts of BAC_cloned_genomic_insert', async () => {
const bcgi = (
await so.getTermsWithLabelOrSynonym('BAC_cloned_genomic_insert', {
includeSubclasses: false,
})
const bcgi = await so.getTermsWithLabelOrSynonym(
'BAC_cloned_genomic_insert',
{ includeSubclasses: false },
)
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isOntologyClass)
expect(bcgi.length).toBe(1)
expect(bcgi[0].lbl).toBe('BAC_cloned_genomic_insert')
const subpartTerms = await so.getClassesThat('part_of', bcgi)
// eslint-disable-next-line unicorn/no-array-callback-reference
const bcgiClas = bcgi.filter(isOntologyClass)
expect(bcgiClas.length).toBe(1)
expect(bcgiClas[0].lbl).toBe('BAC_cloned_genomic_insert')
const subpartTerms = await so.getClassesThat('part_of', bcgiClas)
expect(subpartTerms.length).toBeGreaterThan(0)
expect(subpartTerms.find((t) => t.lbl === 'clone_insert_end')).toBeTruthy()
expect(subpartTerms).toMatchSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export default class OntologyStore {
}

async termCount(tx?: Transaction<['nodes']>) {
const myTx = tx ?? (await this.db).transaction('nodes')
const db = await this.db
const myTx = tx ?? db.transaction('nodes')
return myTx.objectStore('nodes').count()
}

Expand All @@ -210,7 +211,8 @@ export default class OntologyStore {
tx?: Transaction<['nodes', 'edges']>,
): Promise<OntologyTerm[]> {
const includeSubclasses = options?.includeSubclasses ?? true
const myTx = tx ?? (await this.db).transaction(['nodes', 'edges'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes', 'edges'])
const nodes = myTx.objectStore('nodes')
const resultNodes = [
...(await nodes.index('by-label').getAll(termLabelOrSynonym)),
Expand Down Expand Up @@ -254,15 +256,17 @@ export default class OntologyStore {
): Promise<OntologyProperty[]> {
const includeSubProperties = options?.includeSubProperties ?? true

const myTx = tx ?? (await this.db).transaction(['nodes', 'edges'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes', 'edges'])

const properties = (
await this.getTermsWithLabelOrSynonym(
propertyLabel,
{ includeSubclasses: false },
myTx,
)
).filter((p): p is OntologyProperty => isOntologyProperty(p))
const terms = await this.getTermsWithLabelOrSynonym(
propertyLabel,
{ includeSubclasses: false },
myTx,
)
const properties = terms.filter((p): p is OntologyProperty =>
isOntologyProperty(p),
)

if (includeSubProperties) {
const subPropertyIds = await this.recurseEdges(
Expand Down Expand Up @@ -334,7 +338,8 @@ export default class OntologyStore {
direction: 'superclasses' | 'subclasses',
tx?: Transaction<['edges']>,
) {
const myTx = tx ?? (await this.db).transaction(['edges'])
const db = await this.db
const myTx = tx ?? db.transaction(['edges'])
const startingNodes = [...startingNodeIds]
const subclassIds = await this.recurseEdges(
direction === 'subclasses' ? 'by-object' : 'by-subject',
Expand Down Expand Up @@ -392,7 +397,8 @@ export default class OntologyStore {
targetTerms: OntologyClass[],
tx?: Transaction<['nodes', 'edges']>,
) {
const myTx = tx ?? (await this.db).transaction(['nodes', 'edges'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes', 'edges'])

// find all the terms for the properties we are using
const relatingProperties = await this.getPropertiesByLabel(
Expand Down Expand Up @@ -444,7 +450,8 @@ export default class OntologyStore {
options: PropertiesOptions,
tx?: Transaction<['nodes', 'edges']>,
) {
const myTx = tx ?? (await this.db).transaction(['nodes', 'edges'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes', 'edges'])
const nodeStore = myTx.objectStore('nodes')
const edgeStore = myTx.objectStore('edges')

Expand Down Expand Up @@ -501,7 +508,8 @@ export default class OntologyStore {
}

async getAllClasses(tx?: Transaction<['nodes']>): Promise<OntologyClass[]> {
const myTx = tx ?? (await this.db).transaction(['nodes'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes'])
const all = (await myTx
.objectStore('nodes')
.index('by-type')
Expand All @@ -510,7 +518,8 @@ export default class OntologyStore {
}

async getAllTerms(tx?: Transaction<['nodes']>): Promise<OntologyTerm[]> {
const myTx = tx ?? (await this.db).transaction(['nodes'])
const db = await this.db
const myTx = tx ?? db.transaction(['nodes'])
const all = await myTx.objectStore('nodes').getAll()
return all.filter((term) => !isDeprecated(term))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,16 @@ async function fetchValidTypeTerms(
if (parentFeature) {
// if this is a child of an existing feature, restrict the autocomplete choices to valid
// parts of that feature
const parentTypeTerms = (
await ontologyStore.getTermsWithLabelOrSynonym(parentFeature.type, {
includeSubclasses: false,
})
const parentTypeTerms = await ontologyStore.getTermsWithLabelOrSynonym(
parentFeature.type,
{ includeSubclasses: false },
)
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isOntologyClass)
if (parentTypeTerms.length > 0) {
// eslint-disable-next-line unicorn/no-array-callback-reference
const parentTypeClassTerms = parentTypeTerms.filter(isOntologyClass)
if (parentTypeClassTerms.length > 0) {
const subpartTerms = await ontologyStore.getClassesThat(
'part_of',
parentTypeTerms,
parentTypeClassTerms,
)
return subpartTerms
}
Expand Down
15 changes: 7 additions & 8 deletions packages/jbrowse-plugin-apollo/src/components/AddFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ async function fetchValidDescendantTerms(
if (parentFeature) {
// since this is a child of an existing feature, restrict the autocomplete choices to valid
// parts of that feature
const parentTypeTerms = (
await ontologyStore.getTermsWithLabelOrSynonym(parentFeature.type, {
includeSubclasses: false,
})
const parentTypeTerms = await ontologyStore.getTermsWithLabelOrSynonym(
parentFeature.type,
{ includeSubclasses: false },
)
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isOntologyClass)
if (parentTypeTerms.length > 0) {
// eslint-disable-next-line unicorn/no-array-callback-reference
const parentTypeClassTerms = parentTypeTerms.filter(isOntologyClass)
if (parentTypeClassTerms.length > 0) {
const subpartTerms = await ontologyStore.getClassesThat(
'part_of',
parentTypeTerms,
parentTypeClassTerms,
)
return subpartTerms
}
Expand Down

0 comments on commit 408c59f

Please sign in to comment.