Skip to content

Commit

Permalink
chore(deps): adopt biome
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Aug 10, 2024
1 parent 8b2e372 commit ddf48ec
Show file tree
Hide file tree
Showing 37 changed files with 608 additions and 1,093 deletions.
4 changes: 4 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"extends": ["node_modules/@naturalcycles/dev-lib/cfg/biome.jsonc"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
"yargs": "^17.0.0"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@naturalcycles/bench-lib": "^3.0.0",
"@naturalcycles/dev-lib": "^15.0.4",
"@sentry/node": "^7.0.0",
"@types/ejs": "^3.0.0",
"@types/node": "^20.1.0",
"@types/node": "^22.2.0",
"@types/yargs": "^16.0.0",
"fastify": "^4.0.0",
"jest": "^29.0.1"
Expand Down
6 changes: 2 additions & 4 deletions scripts/consoleVSProcessBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ yarn tsn consoleVSProcessBench
*/

/* eslint-disable unused-imports/no-unused-vars */

import { runBenchScript } from '@naturalcycles/bench-lib'
import { _range } from '@naturalcycles/js-lib'
import { _inspect } from '@naturalcycles/nodejs-lib'
Expand All @@ -15,10 +13,10 @@ const data = _range(10).map(n => _inspect({ a: 'b', n }))
runBenchScript({
fns: {
consoleLog: () => {
const out = data.map(s => console.log(s))
const _out = data.map(s => console.log(s))
},
processWrite: () => {
const out = data.map(s => process.stdout.write(s + '\n'))
const _out = data.map(s => process.stdout.write(s + '\n'))
},
},
runs: 2,
Expand Down
2 changes: 1 addition & 1 deletion scripts/profile/01-bare-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import http from 'node:http'

export async function createServerBareNode(): Promise<http.Server> {
return http.createServer((req, res) => {
return http.createServer((_req, res) => {
res.setHeader('content-type', 'application/json; charset=utf-8')
res.end(JSON.stringify({ hello: 'world' }))
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/profile/03-bare-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export async function createServerBareExpress(): Promise<http.Server> {
const app = express()
app.disable('etag')
app.disable('x-powered-by')
app.get('/', (req, res) => res.json({ hello: 'world' }))
app.get('/', (_req, res) => res.json({ hello: 'world' }))
return http.createServer(app)
}
2 changes: 1 addition & 1 deletion scripts/profile/04-express-middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function createServerExpressMiddlewares(): Promise<http.Server> {
app.use(helmet.ieNoOpen())
app.use(helmet.xssFilter())

app.get('/', (req, res) => res.json({ hello: 'world' }))
app.get('/', (_req, res) => res.json({ hello: 'world' }))

return http.createServer(app)
}
2 changes: 1 addition & 1 deletion scripts/profile/05-backend-lib-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function createServerBackendLib(): Promise<http.Server> {
// const router = Router()

const helloResource = router
router.get('/', (req, res) => res.json({ hello: 'world' }))
router.get('/', (_req, res) => res.json({ hello: 'world' }))

// Testing the effect of logging
// router.get('/', (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/uncaught.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process.on('uncaughtException', (err, origin) => {
console.error('here', origin, err)
})

process.on('unhandledRejection', (reason, promise) => {
process.on('unhandledRejection', (reason, _promise) => {
console.error('unhandledRejection:', reason)
// console.error('Unhandled Rejection at:', promise, 'reason:', reason);
})
Expand Down
4 changes: 2 additions & 2 deletions scripts/validation.bench.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runScript(async () => {
{
'01-no-validation': async () => {
const app = createApp()
app.post('/', (req, res) => res.json({ hello: 'world' }))
app.post('/', (_req, res) => res.json({ hello: 'world' }))
return http.createServer(app)
},
'02-ajv': async () => {
Expand All @@ -44,7 +44,7 @@ runScript(async () => {
pw: jsonSchema.string().min(6),
}),
),
(req, res) => res.json({ hello: 'world' }),
(_req, res) => res.json({ hello: 'world' }),
)
return http.createServer(app)
},
Expand Down
7 changes: 4 additions & 3 deletions src/admin/admin.resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mockTime } from '@naturalcycles/dev-lib/dist/testing'
import { BaseAdminService, FirebaseSharedService, getDefaultRouter } from '../index'
import { expressTestService } from '../testing'

export const firebaseService = new FirebaseSharedService({
const firebaseService = new FirebaseSharedService({
authDomain: 'FIREBASE_AUTH_DOMAIN',
apiKey: 'FIREBASE_API_KEY',
// serviceAccount: 'FIREBASE_SERVICE_ACCOUNT_PATH',
Expand All @@ -12,13 +12,14 @@ class AdminService extends BaseAdminService {
override async getEmailPermissions(email?: string): Promise<Set<string> | undefined> {
if (email === '[email protected]') {
return new Set(['p1', 'p2'])
} else if (email === '[email protected]') {
}
if (email === '[email protected]') {
return new Set(['s1', 's2'])
}
}
}

export const adminService = new AdminService(firebaseService.auth(), {
const adminService = new AdminService(firebaseService.auth(), {
// authEnabled: false,
})

Expand Down
2 changes: 1 addition & 1 deletion src/admin/adminMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function loginHtml(firebaseServiceCfg: FirebaseSharedServiceCfg): Backend
adminAuthProvider: firebaseAuthProvider = 'GoogleAuthProvider',
} = firebaseServiceCfg

return (req, res) => {
return (_req, res) => {
res.send(
getLoginHtml({
firebaseApiKey,
Expand Down
2 changes: 1 addition & 1 deletion src/admin/base.admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class BaseAdminService {
req: BackendRequest,
reqPermissions: string[] = [],
meta: Record<string, any> = {},
andComparison: boolean = true,
andComparison = true,
): Promise<AdminInfo> {
if (!this.cfg.authEnabled) return adminInfoDisabled()

Expand Down
4 changes: 2 additions & 2 deletions src/db/httpDBRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export function httpDBRequestHandler(db: CommonDB): BackendRouter {
})

// ping
router.get('/ping', async (req, res) => {
router.get('/ping', async (_req, res) => {
await db.ping()
res.end()
})

// getTables
router.get('/tables', async (req, res) => {
router.get('/tables', async (_req, res) => {
res.json(await db.getTables())
})

Expand Down
2 changes: 1 addition & 1 deletion src/deploy/backend.cfg.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const backendCfgSchema = AjvSchema.readJsonSync<BackendCfg>(
},
)

export function getBackendCfg(projectDir: string = '.'): BackendCfg {
export function getBackendCfg(projectDir = '.'): BackendCfg {
const backendCfgYamlPath = `${projectDir}/backend.cfg.yaml`

requireFileToExist(backendCfgYamlPath)
Expand Down
2 changes: 1 addition & 1 deletion src/env/env.shared.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { testDir } from '../paths.cnst'
import { EnvSharedService, EnvSharedServiceCfg } from './env.shared.service'

export const envDir = `${testDir}/env`
const envDir = `${testDir}/env`

const cfg: EnvSharedServiceCfg = {
envDir,
Expand Down
2 changes: 0 additions & 2 deletions src/leak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ test('should not leak', () => {
require('.')
require('./testing')
})

export {}
4 changes: 2 additions & 2 deletions src/sentry/sentry.shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
StringMap,
} from '@naturalcycles/js-lib'
import { _inspect, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
// eslint-disable-next-line import/no-duplicates
// eslint-disable-next-line import-x/no-duplicates
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
// eslint-disable-next-line import/no-duplicates
// eslint-disable-next-line import-x/no-duplicates
import type * as SentryLib from '@sentry/node'
import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'

Expand Down
4 changes: 2 additions & 2 deletions src/server/appEngineLogMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function logToCI(args: any[]): void {
export function appEngineLogMiddleware(): BackendRequestHandler {
if (!isGAE || !GOOGLE_CLOUD_PROJECT) {
// Local machine, return "simple" logToDev middleware with request numbering
return function gaeLogMiddlewareDev(req, res, next) {
return function gaeLogMiddlewareDev(req, _res, next) {
// Local machine
req.requestId = String(++reqCounter)
req.log = req.warn = req.error = (...args: any[]) => logToDev(req.requestId!, args)
Expand All @@ -79,7 +79,7 @@ export function appEngineLogMiddleware(): BackendRequestHandler {

// Otherwise, we're in AppEngine

return function appEngineLogHandler(req, res, next) {
return function appEngineLogHandler(req, _res, next) {
const traceHeader = req.header('x-cloud-trace-context')
if (traceHeader) {
const [trace] = traceHeader.split('/')
Expand Down
2 changes: 1 addition & 1 deletion src/server/asyncLocalStorageMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface RequestLocalStorage {
const storage = _lazyValue(() => new AsyncLocalStorage<RequestLocalStorage>())

export function asyncLocalStorageMiddleware(): BackendRequestHandler {
return (req, res, next) => {
return (req, _res, next) => {
const store: RequestLocalStorage = {
req,
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/bodyParserTimeoutMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function bodyParserTimeoutMiddleware(
* Should be called AFTER bodyParser
*/
export function clearBodyParserTimeout(): BackendRequestHandler {
return (req, res, next) => {
return (req, _res, next) => {
clearTimeout(req.bodyParserTimeout)
next()
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/methodOverrideMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function methodOverrideMiddleware(
...cfg,
}

return (req, res, next) => {
return (req, _res, next) => {
if (req.query[methodKey]) {
req.method = req.query[methodKey] as string
// delete req.query[methodKey]
Expand Down
2 changes: 1 addition & 1 deletion src/server/okMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BackendRequestHandler } from './server.model'

export function okMiddleware(): BackendRequestHandler {
return (req, res) => {
return (_req, res) => {
res.json({ ok: 1 })
}
}
2 changes: 1 addition & 1 deletion src/server/safeJsonMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BackendRequestHandler, BackendResponse } from './server.model'
* Original: https://github.com/expressjs/express/blob/master/lib/response.js
*/
export function safeJsonMiddleware(): BackendRequestHandler {
return function safeJsonHandler(req, res, next) {
return function safeJsonHandler(_req, res, next) {
res.json = (input: any): BackendResponse => {
if (!res.get('Content-Type')) {
res.set('Content-Type', 'application/json')
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function enableDestroy(server: Server): DestroyableServer {
const connections: StringMap<Socket> = {}
const srv = server as DestroyableServer

srv.on('connection', function (conn) {
srv.on('connection', conn => {
const key = conn.remoteAddress + ':' + conn.remotePort
connections[key] = conn
conn.on('close', () => delete connections[key])
Expand Down
2 changes: 1 addition & 1 deletion src/server/serverStatusMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { versions } = process
const { GAE_APPLICATION, GAE_SERVICE, GAE_VERSION, APP_ENV, NODE_OPTIONS } = process.env

export function serverStatusMiddleware(projectDir?: string, extra?: any): BackendRequestHandler {
return async (req, res) => {
return async (_req, res) => {
res.json(getServerStatusData(projectDir, extra))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/simpleRequestLoggerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function simpleRequestLoggerMiddleware(
): BackendRequestHandler {
// Disable logger in AppEngine, as it doesn't make sense there
// UPD: Only log in dev environment
if (APP_ENV !== 'dev') return (req, res, next) => next()
if (APP_ENV !== 'dev') return (_req, _res, next) => next()

const cfg: SimpleRequestLoggerMiddlewareCfg = {
logStart: false,
Expand Down
2 changes: 1 addition & 1 deletion src/server/validation/validateMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function validateObject(
const reportPredicate =
typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined

return (req, res, next) => {
return (req, _res, next) => {
const error = ajvSchema.getValidationError(req[prop])
if (error) {
const report = reportPredicate(error)
Expand Down
2 changes: 1 addition & 1 deletion src/server/validation/zodValidateMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function zodReqValidate(
const reportPredicate =
typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined

return (req, res, next) => {
return (req, _res, next) => {
const { error } = zSafeValidate(req[prop], schema)
if (!error) {
return next()
Expand Down
2 changes: 1 addition & 1 deletion src/test/debug.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { validateBody } from '../server/validation/validateMiddleware'
const router = getDefaultRouter()
export const debugResource = router

router.get('/', async (req, res) => {
router.get('/', async (_req, res) => {
res.json({ ok: 1 })
})

Expand Down
1 change: 1 addition & 0 deletions src/test/env/test1.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const test1Env = {
a: 'a1',
}

// biome-ignore lint/style/noDefaultExport: ok
export default test1Env
1 change: 1 addition & 0 deletions src/test/env/test2.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const test2Env = {
a: 'a2',
}

// biome-ignore lint/style/noDefaultExport: ok
export default test2Env
3 changes: 2 additions & 1 deletion src/test/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ declare global {
}
}

// eslint-disable-next-line import/no-anonymous-default-export, unicorn/no-anonymous-default-export
/* eslint-disable import-x/no-anonymous-default-export, unicorn/no-anonymous-default-export */
// biome-ignore lint/style/noDefaultExport: ok
export default async (): Promise<void> => {
const resources = [debugResource]

Expand Down
3 changes: 2 additions & 1 deletion src/test/globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { _since } from '@naturalcycles/js-lib'

// eslint-disable-next-line import/no-anonymous-default-export, unicorn/no-anonymous-default-export
/* eslint-disable import-x/no-anonymous-default-export, unicorn/no-anonymous-default-export */
// biome-ignore lint/style/noDefaultExport: ok
export default async (): Promise<void> => {
const started = Date.now()
// @ts-expect-error
Expand Down
2 changes: 1 addition & 1 deletion src/test/gotTimeout.manual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getDefaultRouter } from '../server/getDefaultRouter'
import { expressTestService } from '../testing'

const res = getDefaultRouter()
res.get('/', async (req, res) => {
res.get('/', async (_req, res) => {
await pDelay(10_000)
res.json('ok')
})
Expand Down
2 changes: 1 addition & 1 deletion src/test/project/src/a.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
console.log('a.ts')

export {}
export type {}
4 changes: 2 additions & 2 deletions src/test/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ router.get(
},
realm: 'dungeon',
}),
(req, res) => {
(_req, res) => {
res.send('welcome in!')
},
)
Expand Down Expand Up @@ -96,7 +96,7 @@ router.get('/log', async (req, res) => {
res.json({})
})

router.get('/log2', async (req, res) => {
router.get('/log2', async (_req, res) => {
requestLogger.log('yo')
requestLogger.log('yo2')
requestLogger.log('yo3')
Expand Down
Loading

0 comments on commit ddf48ec

Please sign in to comment.