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 37bc8da commit 8304b22
Show file tree
Hide file tree
Showing 21 changed files with 540 additions and 1,223 deletions.
65 changes: 1 addition & 64 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -1,67 +1,4 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto"
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"organizeImports": { "enabled": false },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"useShorthandFunctionType": "error",
"useShorthandAssign": "error",
"useForOf": "error",
"useConsistentArrayType": "error",
"useShorthandArrayType": "error",
"noDefaultExport": "error",
"noCommaOperator": "error",
"noArguments": "error",
"noNonNullAssertion": "off",
"useImportType": "off",
"noParameterAssign": "off",
"useTemplate": "off",
"useNumberNamespace": "off",
"noUnusedTemplateLiteral": "off"
},
"correctness": {
"noUnusedImports": "error",
"useArrayLiterals": "error"
},
"suspicious": {
"noExplicitAny": "off",
"noAssignInExpressions": "off",
"noAsyncPromiseExecutor": "off",
"noPrototypeBuiltins": "off",
"noThenProperty": "off"
},
"complexity": {
// "useSimplifiedLogicExpression": "error", // consider
"noForEach": "off",
"noUselessThisAlias": "off",
"useLiteralKeys": "off",
"noBannedTypes": "off"
}
}
},
"overrides": [{ "include": ["tsconfig.json", "tsconfig.*.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 @@ -20,6 +20,7 @@
"zod": "^3.20.2"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@naturalcycles/bench-lib": "^3.0.0",
"@naturalcycles/dev-lib": "^15.0.3",
"@naturalcycles/nodejs-lib": "^13.0.1",
Expand All @@ -46,7 +47,7 @@
"types": "dist/index.d.ts",
"sideEffects": false,
"engines": {
"node": ">=18.12.0"
"node": ">=20.13.0"
},
"publishConfig": {
"provenance": true,
Expand Down
50 changes: 24 additions & 26 deletions scripts/dateParseBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ yarn tsn dateParseBench
*/

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

import { runBenchScript } from '@naturalcycles/bench-lib'
import { dayjs } from '@naturalcycles/time-lib'
import { localDate } from '../src'
Expand All @@ -19,54 +17,54 @@ const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
runBenchScript({
fns: {
dayjs: () => {
let y
let m
let d
let _y: number
let _m: number
let _d: number

strings.forEach(s => {
const dd = dayjs(s)

y = dd.year()
m = dd.month()
d = dd.day()
_y = dd.year()
_m = dd.month()
_d = dd.day()
})
},
split: () => {
let y
let m
let d
let _y: number
let _m: number
let _d: number

strings.forEach(s => {
const [year, month, day] = s.slice(0, 10).split('-').map(Number)
y = year
m = month
d = day
_y = year!
_m = month!
_d = day!
})
},
regex: () => {
let y
let m
let d
let _y: number
let _m: number
let _d: number

strings.forEach(s => {
const matches: string[] | null = DATE.exec(s.slice(0, 10)) as string[]

y = Number(matches[1])
m = Number(matches[2])
d = Number(matches[3])
_y = Number(matches[1])
_m = Number(matches[2])
_d = Number(matches[3])
})
},
localDate: () => {
let y
let m
let d
let _y: number
let _m: number
let _d: number

strings.forEach(s => {
const dd = localDate(s)

y = dd.year
m = dd.month
d = dd.day
_y = dd.year
_m = dd.month
_d = dd.day
})
},
},
Expand Down
9 changes: 5 additions & 4 deletions scripts/filterBench.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const objects = _range(1000).map(n => ({
runBenchScript({
fns: {
candidate: () => {
const res = objects.map(o => filterNullishCandidate(o))
const _res = objects.map(o => filterNullishCandidate(o))
// const res = filterNullishCandidate(objects[0]!)
},
// candidate2: done => {
Expand All @@ -37,13 +37,13 @@ runBenchScript({
// },
// // mutation should come later
filterNullishMutate: () => {
const res = objects.map(o => _filterNullishValues(o, true))
const _res = objects.map(o => _filterNullishValues(o, true))
// const res = _filterNullishValues(objects[0]!, true)
},
},
})

function filterNullishCandidate<T extends AnyObject>(obj: T, mutate = false): T {
function filterNullishCandidate<T extends AnyObject>(obj: T, _mutate = false): T {
const o: any = {}

Object.entries(obj).forEach(([k, v]) => {
Expand All @@ -55,7 +55,8 @@ function filterNullishCandidate<T extends AnyObject>(obj: T, mutate = false): T
return o
}

function filterNullishCandidate2<T extends AnyObject>(obj: T, mutate = false): T {
// biome-ignore lint: ok
function filterNullishCandidate2<T extends AnyObject>(obj: T, _mutate = false): T {
const o: any = {}

for (const k of Object.keys(obj)) {
Expand Down
6 changes: 2 additions & 4 deletions scripts/jsonBench.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ yarn tsn jsonBench
*/

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

import { runBenchScript } from '@naturalcycles/bench-lib'
import { mockAllKindsOfThings } from '@naturalcycles/dev-lib/dist/testing'
import { _range, _safeJsonStringify } from '../src'
Expand All @@ -15,10 +13,10 @@ const data = _range(10).map(() => mockAllKindsOfThings())
runBenchScript({
fns: {
native: () => {
const s = JSON.stringify(data)
const _s = JSON.stringify(data)
},
safeJsonStringify: () => {
const s = _safeJsonStringify(data)
const _s = _safeJsonStringify(data)
},
},
})
6 changes: 2 additions & 4 deletions scripts/jsonParseBench.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ yarn tsn jsonParseBench
*/

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

import { runBenchScript } from '@naturalcycles/bench-lib'
import { mockAllKindsOfThings } from '@naturalcycles/dev-lib/dist/testing'
import { _jsonParseIfPossible } from '../src'
Expand All @@ -18,10 +16,10 @@ const data = mockAllKindsOfThings()
runBenchScript({
fns: {
before: () => {
const out = data.map(t => before(t))
const _out = data.map(t => before(t))
},
after: () => {
const out = data.map(t => _jsonParseIfPossible(t))
const _out = data.map(t => _jsonParseIfPossible(t))
},
},
runs: 2,
Expand Down
3 changes: 1 addition & 2 deletions scripts/lazyLocalDateBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ yarn tsn lazyLocalDateBench
*/

/* eslint-disable unused-imports/no-unused-vars */
import { runBenchScript } from '@naturalcycles/bench-lib'
// import { LazyLocalDate } from '../src/__exclude/lazyLocalDate'
import { localDate } from '../src'
Expand All @@ -16,7 +15,7 @@ runBenchScript({
localDate: () => {
const d = localDate(str)
const s = d.toISODate()
const s2 = s
const _s2 = s
},
// lazyLocalDate: done => {
// const d = new LazyLocalDate(str)
Expand Down
7 changes: 3 additions & 4 deletions scripts/localDateBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ yarn tsn localDateBench
*/

/* eslint-disable unused-imports/no-unused-vars */
import { runBenchScript } from '@naturalcycles/bench-lib'
import { dayjs } from '@naturalcycles/time-lib'
import { localDate, localTime } from '../src'
Expand All @@ -17,19 +16,19 @@ runBenchScript({
const d = localDate(str)
const d2 = d.plus(100, 'day')
const s = d2.toString()
const s2 = s
const _s2 = s
},
localTime: () => {
const d = localTime(str)
const d2 = d.plus(100, 'day')
const s = d2.toString()
const s2 = s
const _s2 = s
},
dayjs: () => {
const d = dayjs(str)
const d2 = d.add(100, 'day')
const s = d2.toString()
const s2 = s
const _s2 = s
},
},
})
9 changes: 4 additions & 5 deletions scripts/memo.decorator.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
yarn tsn memo.decorator.bench
*/
/* eslint-disable unused-imports/no-unused-vars */

import { runBenchScript } from '@naturalcycles/bench-lib'
import { _Memo } from '../src'
import { memoSimple } from '../src/decorators/memoSimple.decorator'

let c = 0
let _c = 0

class C0 {
constructor(private inc?: number) {}

work(): void {
// c += this.inc
c++
_c++
}
}

Expand All @@ -43,11 +42,11 @@ class C3 {
const c1 = new C1()
const c2 = new C2()
const c3 = new C3()
const c0 = c1.getC0()
const _c0 = c1.getC0()

// const key = {a: 'b'}
// const key = 'a'
const key = 2
const _key = 2
// const key = undefined

runBenchScript({
Expand Down
4 changes: 2 additions & 2 deletions scripts/startsWithBench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const data = _range(10).map(n => `{ "a": "b", "n": ${n}}`)
runBenchScript({
fns: {
startsWith: () => {
const out = data.map(t => t.startsWith('{'))
const _out = data.map(t => t.startsWith('{'))
},
regex: () => {
const out = data.map(t => regex.test(t))
const _out = data.map(t => regex.test(t))
},
},
})
4 changes: 2 additions & 2 deletions src/decorators/debounce.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { _debounce, _throttle } from './debounce'

// eslint-disable-next-line @typescript-eslint/naming-convention
export function _Debounce(wait: number, opt: DebounceOptions = {}): MethodDecorator {
return (target, key, descriptor) => {
return (_target, _key, descriptor) => {
const originalFn = descriptor.value
descriptor.value = _debounce(originalFn as any, wait, opt)
return descriptor
Expand All @@ -12,7 +12,7 @@ export function _Debounce(wait: number, opt: DebounceOptions = {}): MethodDecora

// eslint-disable-next-line @typescript-eslint/naming-convention
export function _Throttle(wait: number, opt: ThrottleOptions = {}): MethodDecorator {
return (target, key, descriptor) => {
return (_target, _key, descriptor) => {
const originalFn = descriptor.value
descriptor.value = _throttle(originalFn as any, wait, opt)
return descriptor
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/retry.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pRetryFn } from '..'

// eslint-disable-next-line @typescript-eslint/naming-convention
export function _Retry(opt: PRetryOptions = {}): MethodDecorator {
return (target, key, descriptor) => {
return (_target, _key, descriptor) => {
const originalFn = descriptor.value
descriptor.value = pRetryFn(originalFn as any, opt)
return descriptor
Expand Down
2 changes: 1 addition & 1 deletion src/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function _defineProps<T extends AnyObject>(
): T {
return Object.defineProperties(
obj,
_mapValues(props, (k, pd) => ({
_mapValues(props, (_k, pd) => ({
writable: true,
configurable: true,
enumerable: true,
Expand Down
1 change: 0 additions & 1 deletion src/error/app.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ test('AppError with cause', () => {
const err1 = new AppError('cozz')
const err = new AppError('hello', {}, { cause: err1 })
expect(err.cause!.stack).toBeDefined()
// biome-ignore lint/performance/noDelete: ok
delete err.cause!.stack
expect(err.cause).toMatchInlineSnapshot(`
{
Expand Down
Loading

0 comments on commit 8304b22

Please sign in to comment.