Skip to content

Commit

Permalink
Enable unicorn consistent-destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Aug 21, 2023
1 parent 54eedc3 commit e210881
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 140 deletions.
7 changes: 3 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ module.exports = {
// eslint-plugin-tsdoc rules
'tsdoc/syntax': 'warn',
// eslint-plugin-unicorn rules (override recommended)
'unicorn/consistent-destructuring': 'off',
'unicorn/filename-case': 'off',
'unicorn/filename-case': 'off', // Doesn't match our file naming, maybe can be configured later
'unicorn/no-empty-file': 'off', // False positives
'unicorn/no-null': 'off',
'unicorn/no-null': 'off', // A lot of null in React and other libraries
'unicorn/prefer-module': 'off', // Cypress and apollo-collaboration-server need this
'unicorn/prevent-abbreviations': 'off',
'unicorn/prevent-abbreviations': 'off', // Doesn't guess a lot of abbreviations correctly
// Special case @typescript-eslint/eslint-plugin rule
// Will be part of "plugin:@typescript-eslint/recommended-type-checked" when
// that extension is enabled. Remove from here at that time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,36 @@ export class OperationsService {
async executeOperation<T extends Operation>(
serializedOperation: ReturnType<T['toJSON']>,
): Promise<ReturnType<T['executeOnServer']>> {
const { logger } = this
const {
assemblyModel,
connection,
countersService,
featureModel,
fileModel,
filesService,
logger,
pluginsService,
refSeqChunkModel,
refSeqModel,
userModel,
} = this
const OperationType = operationRegistry.getOperationType(
serializedOperation.typeName,
)
const operation = new OperationType(serializedOperation, { logger })
const session = await this.connection.startSession()
const session = await connection.startSession()
const result = (await operation.execute({
typeName: 'Server',
featureModel: this.featureModel,
assemblyModel: this.assemblyModel,
refSeqModel: this.refSeqModel,
refSeqChunkModel: this.refSeqChunkModel,
fileModel: this.fileModel,
userModel: this.userModel,
featureModel,
assemblyModel,
refSeqModel,
refSeqChunkModel,
fileModel,
userModel,
session,
filesService: this.filesService,
counterService: this.countersService,
pluginsService: this.pluginsService,
filesService,
counterService: countersService,
pluginsService,
user: '',
})) as ReturnType<T['executeOnServer']>
await session.endSession()
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-common/src/AssemblySpecificChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ export abstract class AssemblySpecificChange extends Change {
if (!refSeqDoc) {
throw new Error('No refSeq document found')
}
const { chunkSize } = refSeqDoc
const { _id, chunkSize } = refSeqDoc
sequenceBuffer += line.replaceAll(/\s/g, '')
// If sequence block > chunk size then save chunk into Mongo
while (sequenceBuffer.length >= chunkSize) {
const sequence = sequenceBuffer.slice(0, chunkSize)
refSeqLen += sequence.length
logger.debug?.(
`Creating refSeq chunk number ${chunkIndex} of "${refSeqDoc._id}"`,
`Creating refSeq chunk number ${chunkIndex} of "${_id}"`,
)
// We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction
await refSeqChunkModel.create([
{
refSeq: refSeqDoc._id,
refSeq: _id,
n: chunkIndex,
sequence,
user,
Expand Down
12 changes: 6 additions & 6 deletions packages/apollo-shared/src/Changes/AddFeatureChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class AddFeatureChange extends FeatureChange {
for (const change of changes) {
logger.debug?.(`change: ${JSON.stringify(change)}`)
const { addedFeature, allIds, copyFeature, parentFeatureId } = change
const { refSeq } = addedFeature
const { _id, refSeq } = addedFeature
const refSeqDoc = await refSeqModel
.findById(refSeq)
.session(session)
Expand All @@ -111,7 +111,7 @@ export class AddFeatureChange extends FeatureChange {
)
featureCnt++
} else {
addedFeature.gffId = addedFeature._id // User added manually new feature so then gffId = _id
addedFeature.gffId = _id // User added manually new feature so then gffId = _id
// Adding new child feature
if (parentFeatureId) {
const topLevelFeature = await featureModel
Expand Down Expand Up @@ -146,19 +146,19 @@ export class AddFeatureChange extends FeatureChange {
}
parentFeature.attributes = attributes
}
parentFeature.children.set(addedFeature._id, {
parentFeature.children.set(_id, {
allIds: [],
...addedFeature,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
_id: addedFeature._id,
_id,
})
const childIds = this.getChildFeatureIds(addedFeature)
topLevelFeature.allIds.push(addedFeature._id, ...childIds)
topLevelFeature.allIds.push(_id, ...childIds)
await topLevelFeature.save()
} else {
const childIds = this.getChildFeatureIds(addedFeature)
const allIdsV2 = [addedFeature._id, ...childIds]
const allIdsV2 = [_id, ...childIds]
const [newFeatureDoc] = await featureModel.create(
[{ allIds: allIdsV2, ...addedFeature }],
{ session },
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-shared/src/Changes/DeleteAssemblyChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class DeleteAssemblyChange extends AssemblySpecificChange {
await refSeqModel.deleteMany({ assembly }).exec()
await assemblyModel.findByIdAndDelete(assembly).exec()

this.logger.debug?.(`Assembly "${assembly}" deleted from database.`)
logger.debug?.(`Assembly "${assembly}" deleted from database.`)
}

async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
Expand Down
6 changes: 2 additions & 4 deletions packages/apollo-shared/src/Changes/DeleteFeatureChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class DeleteFeatureChange extends FeatureChange {
if (!feature.children) {
throw new Error(`Feature ${feature._id} has no children`)
}
const { children } = feature
const { _id, children } = feature
const child = children.get(featureIdToDelete)
if (child) {
const deletedIds = this.getChildFeatureIds(child)
Expand All @@ -147,9 +147,7 @@ export class DeleteFeatureChange extends FeatureChange {
}
}

throw new Error(
`Feature "${featureIdToDelete}" not found in ${feature._id}`,
)
throw new Error(`Feature "${featureIdToDelete}" not found in ${_id}`)
}

async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
Expand Down
34 changes: 19 additions & 15 deletions packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ const stateModelFactory = (
'No LastChangeSequence stored in session. Please, refresh you browser to get last updates from server',
)
}
const { baseURL } = self
const { baseURL, lastChangeSequenceNumber } = self

const url = new URL('changes', baseURL)
const searchParams = new URLSearchParams({
since: String(self.lastChangeSequenceNumber),
since: String(lastChangeSequenceNumber),
sort: '1',
})
url.search = searchParams.toString()
Expand Down Expand Up @@ -319,7 +319,7 @@ const stateModelFactory = (
'label' in menuItem && menuItem.label === 'Add Assembly',
)
) {
pluginManager.rootModel.insertInMenu(
rootModel.insertInMenu(
'Apollo',
{
label: 'Add Assembly',
Expand All @@ -339,7 +339,7 @@ const stateModelFactory = (
},
0,
)
pluginManager.rootModel.insertInMenu(
rootModel.insertInMenu(
'Apollo',
{
label: 'Delete Assembly',
Expand All @@ -359,7 +359,7 @@ const stateModelFactory = (
},
1,
)
pluginManager.rootModel.insertInMenu(
rootModel.insertInMenu(
'Apollo',
{
label: 'Import Features',
Expand All @@ -379,7 +379,7 @@ const stateModelFactory = (
},
2,
)
pluginManager.rootModel.insertInMenu(
rootModel.insertInMenu(
'Apollo',
{
label: 'Manage Users',
Expand All @@ -399,7 +399,7 @@ const stateModelFactory = (
},
9,
)
pluginManager.rootModel.insertInMenu(
rootModel.insertInMenu(
'Apollo',
{
label: 'Undo',
Expand Down Expand Up @@ -555,8 +555,11 @@ const stateModelFactory = (
}))
.actions((self) => {
const {
authType,
getFetcher: superGetFetcher,
getPreAuthorizationInformation: superGetPreAuthorizationInformation,
googleAuthInternetAccount,
microsoftAuthInternetAccount,
retrieveToken: superRetrieveToken,
} = self
let authTypePromise: Promise<AuthType> | undefined
Expand All @@ -574,16 +577,16 @@ const stateModelFactory = (
}
},
retrieveToken() {
if (self.authType === 'google') {
return self.googleAuthInternetAccount.retrieveToken()
if (authType === 'google') {
return googleAuthInternetAccount.retrieveToken()
}
if (self.authType === 'microsoft') {
return self.microsoftAuthInternetAccount.retrieveToken()
if (authType === 'microsoft') {
return microsoftAuthInternetAccount.retrieveToken()
}
if (self.authType === 'guest') {
if (authType === 'guest') {
return superRetrieveToken()
}
throw new Error(`Unknown authType "${self.authType}"`)
throw new Error(`Unknown authType "${authType}"`)
},
getFetcher(
location?: UriLocation,
Expand All @@ -593,6 +596,7 @@ const stateModelFactory = (
init?: RequestInit,
): Promise<Response> => {
let { authType } = self
const { googleClientId, microsoftClientId } = self
if (!authType) {
if (!authTypePromise) {
if (location?.internetAccountPreAuthorization) {
Expand Down Expand Up @@ -624,8 +628,8 @@ const stateModelFactory = (
}
doneCallback()
},
google: Boolean(self.googleClientId),
microsoft: Boolean(self.microsoftClientId),
google: Boolean(googleClientId),
microsoft: Boolean(microsoftClientId),
allowGuestUser,
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const LinearApolloDisplay = observer(function LinearApolloDisplay(
contextMenuItems: getContextMenuItems,
cursor,
featuresHeight,
isShown,
onMouseDown,
onMouseLeave,
onMouseMove,
Expand All @@ -54,7 +55,7 @@ export const LinearApolloDisplay = observer(function LinearApolloDisplay(
const [contextCoord, setContextCoord] = useState<Coord>()
const [contextMenuItems, setContextMenuItems] = useState<MenuItem[]>([])
const message = regionCannotBeRendered()
if (!model.isShown) {
if (!isShown) {
return null
}
return (
Expand Down
Loading

0 comments on commit e210881

Please sign in to comment.