Skip to content

Commit

Permalink
eslint-plugin-unicorn major version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Nov 16, 2024
1 parent fadd7fc commit 7bb9019
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-tsdoc": "^0.3.0",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-unicorn": "^56.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import * as fs from 'node:fs'
import * as path from 'node:path'
import path from 'node:path'
import { Args, Flags } from '@oclif/core'
import { ObjectId } from 'bson'

Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/commands/assembly/add-from-gff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'node:fs'
import * as path from 'node:path'
import path from 'node:path'

import { Args, Flags } from '@oclif/core'
import { ObjectId } from 'bson'
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-cli/src/commands/assembly/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { dirname } from 'node:path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { expect, test } from '@oclif/test'
Expand All @@ -26,7 +26,7 @@ describe.skip('apollo assembly get: Fail without token', () => {
const cmd = ['assembly:get']
test
.stderr()
.command(cmd, { root: dirname(dirname(__dirname)) })
.command(cmd, { root: path.dirname(path.dirname(__dirname)) })
.exit(1)
.do((output) =>
expect(output.stderr).to.contain('Profile "default" has no access token'),
Expand All @@ -47,7 +47,7 @@ describe.skip('apollo assembly get: Get assemblies as YAML string', () => {
const cmd = ['assembly:get']
test
.stdout()
.command(cmd, { root: dirname(dirname(__dirname)) })
.command(cmd, { root: path.dirname(path.dirname(__dirname)) })
.it(cmd.join(' '), (output) => {
JSON.parse(output.stdout)
})
Expand All @@ -60,7 +60,7 @@ describe.skip('apollo assembly get: Test nock', () => {
.nock('http://127.0.0.1:3999', (api) =>
api.persist().get('/assemblies').reply(200, { stuff: 'foo' }),
)
.command(cmd, { root: dirname(dirname(__dirname)) })
.command(cmd, { root: path.dirname(path.dirname(__dirname)) })
.it(cmd.join(' '), (output) => {
console.error(output.stdout)
// const out = JSON.parse(output.stdout)
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cli/src/commands/change/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { dirname } from 'node:path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { test } from '@oclif/test'
Expand All @@ -25,7 +25,7 @@ describe.skip('apollo change get: Get changes as YAML string', () => {
const cmd = ['change:get']
test
.stdout()
.command(cmd, { root: dirname(dirname(__dirname)) })
.command(cmd, { root: path.dirname(path.dirname(__dirname)) })
.it(cmd.join(' '), (output) => {
JSON.parse(output.stdout)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cli/src/commands/feature/add-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ to retrive the parent ID of interest and to populate the child feature with attr
}
const change: SerializedAddFeatureChange = {
typeName: 'AddFeatureChange',
// eslint-disable-next-line unicorn/consistent-destructuring

changedIds: [parentFeature._id],
assembly,
addedFeature: {
Expand All @@ -140,7 +140,7 @@ to retrive the parent ID of interest and to populate the child feature with attr
max,
type,
},
// eslint-disable-next-line unicorn/consistent-destructuring

parentFeatureId: parentFeature._id,
}
const url = new URL(localhostToAddress(`${address}/changes`))
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cli/src/commands/file/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export default class Upload extends FileCommand {
}

let isGzip = args['input-file'].endsWith('.gz')
// eslint-disable-next-line unicorn/consistent-destructuring

if (flags.gzip) {
isGzip = true
}
// eslint-disable-next-line unicorn/consistent-destructuring

if (flags.decompressed) {
isGzip = false
}
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cli/src/commands/user/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { dirname } from 'node:path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { expect, test } from '@oclif/test'
Expand All @@ -25,7 +25,7 @@ describe.skip('apollo user get: Get users as YAML string', () => {
const cmd = ['user:get']
test
.stdout()
.command(cmd, { root: dirname(dirname(__dirname)) })
.command(cmd, { root: path.dirname(path.dirname(__dirname)) })
.it(cmd.join(' '), (output) => {
const str: string = JSON.stringify(JSON.parse(output.stdout))
expect(str).contain('username')
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/fileCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'node:fs'
import * as path from 'node:path'
import path from 'node:path'
import {
Transform,
TransformCallback,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function getAssembly(
const assemblies = (await res.json()) as ApolloAssemblySnapshot[]
for (const x of assemblies) {
if (x._id === assemblyId[0]) {
return JSON.parse(JSON.stringify(x)) as ApolloAssemblySnapshot
return structuredClone(x)
}
}
throw new Error(`Assembly "${assemblyNameOrId}" not found`)
Expand Down
10 changes: 6 additions & 4 deletions packages/apollo-collaboration-server/src/files/files.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReadStream, createReadStream } from 'node:fs'
import { unlink } from 'node:fs/promises'
import { join } from 'node:path'
import path from 'node:path'
import { Gunzip, createGunzip } from 'node:zlib'

import { File, FileDocument } from '@apollo-annotation/schemas'
Expand Down Expand Up @@ -76,7 +76,9 @@ export class FilesService {
const fileUploadFolder = this.configService.get('FILE_UPLOAD_FOLDER', {
infer: true,
})
const fileStream = createReadStream(join(fileUploadFolder, file.checksum))
const fileStream = createReadStream(
path.join(fileUploadFolder, file.checksum),
)
if (compressed) {
return fileStream
}
Expand All @@ -90,7 +92,7 @@ export class FilesService {
const fileUploadFolder = this.configService.get('FILE_UPLOAD_FOLDER', {
infer: true,
})
const fileName = join(fileUploadFolder, file.checksum)
const fileName = path.join(fileUploadFolder, file.checksum)
switch (file.type) {
case 'text/x-fai':
case 'application/x-gzi': {
Expand Down Expand Up @@ -142,7 +144,7 @@ export class FilesService {
const fileUploadFolder = this.configService.get('FILE_UPLOAD_FOLDER', {
infer: true,
})
const compressedFullFileName = join(fileUploadFolder, file.checksum)
const compressedFullFileName = path.join(fileUploadFolder, file.checksum)
this.logger.debug(
`Delete the file "${compressedFullFileName}" from server folder`,
)
Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-collaboration-server/src/files/filesUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
rename,
rmdir,
} from 'node:fs/promises'
import { join } from 'node:path'
import path from 'node:path'
import { Readable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
import { promisify } from 'node:util'
Expand Down Expand Up @@ -41,8 +41,8 @@ export async function writeFileAndCalculateHash(
const { contentEncoding, originalname, size, stream } = file
await mkdir(fileUploadFolder, { recursive: true })
logger.log(`Starting file upload: "${originalname}"`)
const tmpDir = await mkdtemp(join(fileUploadFolder, 'upload-tmp-'))
const tmpFileName = join(tmpDir, `${originalname}.gz`)
const tmpDir = await mkdtemp(path.join(fileUploadFolder, 'upload-tmp-'))
const tmpFileName = path.join(tmpDir, `${originalname}.gz`)
logger.debug(`Uploading to temporary file "${tmpFileName}"`)

// We calculate the md5 hash as the file is being uploaded
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function writeFileAndCalculateHash(
const fileChecksum = hash.digest('hex')
logger.debug(`Uploaded file checksum: "${fileChecksum}"`)

const uploadedFileName = join(fileUploadFolder, fileChecksum)
const uploadedFileName = path.join(fileUploadFolder, fileChecksum)
logger.debug(
`File uploaded successfully, moving temporary file to final location: "${uploadedFileName}"`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class RefSeqsService {
}

findAll(filter?: FindRefSeqDto) {
// eslint-disable-next-line unicorn/no-array-callback-reference
return this.refSeqModel.find(filter ?? {}).exec()
}

Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-shared/src/Changes/AddFeatureChange.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import {
Expand Down Expand Up @@ -143,7 +143,7 @@ export class AddFeatureChange extends FeatureChange {
}
attributes = {
_id: [parentFeature._id.toString()],
...JSON.parse(JSON.stringify(attributes)),
...structuredClone(attributes),
}
parentFeature.attributes = attributes
}
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-shared/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function makeGFF3Feature(
// const locations = feature.discontinuousLocations?.length
// ? feature.discontinuousLocations
// : [{ start: feature.start, end: feature.end, phase: feature.phase }]
// eslint-disable-next-line unicorn/prefer-structured-clone
const attributes: Record<string, string[] | undefined> = JSON.parse(
JSON.stringify(feature.attributes),
)
Expand Down
4 changes: 2 additions & 2 deletions packages/jbrowse-plugin-apollo/cypress/e2e/editFeature.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ describe('Different ways of editing features', () => {
before(() => {
cy.deleteAssemblies()
cy.wrap(
window.indexedDB.databases().then((dbs) => {
globalThis.indexedDB.databases().then((dbs) => {
for (const db of dbs) {
if (db.name) {
window.indexedDB.deleteDatabase(db.name)
globalThis.indexedDB.deleteDatabase(db.name)
}
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const stateModelFactory = (configSchema: ApolloInternetAccountConfigModel) => {
) {
const redirectUri = isElectron
? 'http://localhost/auth'
: window.location.origin + window.location.pathname
: globalThis.location.origin + globalThis.location.pathname
const url = new URL('auth/login', self.baseURL)
const params = new URLSearchParams({
type,
Expand All @@ -144,7 +144,7 @@ const stateModelFactory = (configSchema: ApolloInternetAccountConfigModel) => {
url.search = params.toString()
const eventName = `JBrowseAuthWindow-${self.internetAccountId}`
if (isElectron) {
const { ipcRenderer } = window.require('electron')
const { ipcRenderer } = globalThis.require('electron')
const redirectUriFromElectron = await ipcRenderer.invoke(
'openAuthWindow',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ function ApolloRendering(props: ApolloRenderingProps) {
}
await changeManager.submit(change)
}
// eslint-disable-next-line unicorn/no-useless-undefined

setDragging(undefined)
setMovedDuringLastMouseDown(false)
}
Expand All @@ -575,7 +575,6 @@ function ApolloRendering(props: ApolloRenderingProps) {
}
data-testid="base_linear_display_context_menu"
onClose={() => {
// eslint-disable-next-line unicorn/no-useless-undefined
setContextMenuFeature(undefined)
}}
>
Expand All @@ -595,7 +594,7 @@ function ApolloRendering(props: ApolloRenderingProps) {
session,
handleClose: () => {
doneCallback()
// eslint-disable-next-line unicorn/no-useless-undefined

setContextMenuFeature(undefined)
},
changeManager,
Expand Down Expand Up @@ -625,7 +624,7 @@ function ApolloRendering(props: ApolloRenderingProps) {
session,
handleClose: () => {
doneCallback()
// eslint-disable-next-line unicorn/no-useless-undefined

setContextMenuFeature(undefined)
},
changeManager,
Expand Down Expand Up @@ -654,7 +653,7 @@ function ApolloRendering(props: ApolloRenderingProps) {
session,
handleClose: () => {
doneCallback()
// eslint-disable-next-line unicorn/no-useless-undefined

setContextMenuFeature(undefined)
},
changeManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let forwardFillLight: CanvasPattern | null = null
let backwardFillLight: CanvasPattern | null = null
let forwardFillDark: CanvasPattern | null = null
let backwardFillDark: CanvasPattern | null = null
if ('document' in window) {
if ('document' in globalThis) {
for (const direction of ['forward', 'backward']) {
for (const themeMode of ['light', 'dark']) {
const canvas = document.createElement('canvas')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export function elaborateMatch(
const sortedWordIndexes = [...queryWordIndexes].sort()
const matchedQueryWords = sortedWordIndexes.map((i) => queryWords[i])
const queryWordRegexps = matchedQueryWords.map((queryWord) => {
const escaped = queryWord.replaceAll(/[$()*+./?[\\\]^{|}-]/g, '\\$&')
const escaped = queryWord.replaceAll(
/[$()*+./?[\\\]^{|}-]/g,
String.raw`\$&`,
)
return new RegExp(`\\b${escaped}`, 'gi')
})
// const needle = matchedQueryWords.join(' ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jest.mock('jsonpath', () => {
...original,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
query: jest.fn((obj: any, pathExpression: string, count?: number) => {
const newObj =
obj instanceof Object ? obj : JSON.parse(JSON.stringify(obj))
const newObj = obj instanceof Object ? obj : structuredClone(obj)
return original.query(newObj, pathExpression, count)
}),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export function AddFeature({
break
}
default: {
// eslint-disable-next-line unicorn/no-useless-undefined
setStrand(undefined)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jbrowse-plugin-apollo/src/components/LogOut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function LogOut({ handleClose, session }: DeleteAssemblyProps) {
event.preventDefault()
setErrorMessage('')
selectedInternetAccount.removeToken()
window.location.reload()
globalThis.location.reload()
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function ManageChecks({ handleClose, session }: ManageChecksProps) {
}
} else {
const index = checks.indexOf(_id, 0)
if (index > -1) {
if (index !== -1) {
checks.splice(index, 1)
}
setSelectedChecks(checks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function ManageUsers({
key={`delete-${params.id}`}
icon={<DeleteIcon />}
onClick={async () => {
if (window.confirm('Delete this user?')) {
if (globalThis.confirm('Delete this user?')) {
await deleteUser(params.id)
}
}}
Expand Down
Loading

0 comments on commit 7bb9019

Please sign in to comment.