Skip to content

Commit 51e3a23

Browse files
authored
Migrate to biome for formatting/linting (#232)
* Switch from prettier to biome * Update to biome 2.0.4 * Write files, tweak config * Bump typescript from 5.2.2 to 5.8.3 * Separate tsc/biome ci checks * Revert "Bump typescript from 5.2.2 to 5.8.3" This reverts commit 4055543.
1 parent f40810e commit 51e3a23

File tree

15 files changed

+132
-34
lines changed

15 files changed

+132
-34
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ jobs:
2626
- name: Install dependencies
2727
run: yarn --frozen-lockfile
2828

29-
- name: ESLint
29+
- name: Typescript check
30+
run: yarn tsc
31+
32+
- name: Biome lint check
3033
run: yarn lint
3134

3235
- name: Unit tests

biome.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"files": {
4+
"includes": [
5+
"src/**/*.ts"
6+
]
7+
},
8+
"formatter": {
9+
"enabled": true,
10+
"formatWithErrors": false,
11+
"indentStyle": "space",
12+
"indentWidth": 2,
13+
"lineEnding": "lf",
14+
"lineWidth": 100,
15+
"attributePosition": "auto"
16+
},
17+
"linter": {
18+
"enabled": true,
19+
"rules": {
20+
"recommended": true,
21+
"complexity": {
22+
"noForEach": "off",
23+
"noUselessSwitchCase": "off"
24+
},
25+
"a11y": {
26+
"noSvgWithoutTitle": "off"
27+
},
28+
"suspicious": {
29+
"noArrayIndexKey": "warn",
30+
"noDoubleEquals": "off"
31+
},
32+
"style": {
33+
"useImportType": "warn"
34+
}
35+
}
36+
},
37+
"javascript": {
38+
"formatter": {
39+
"quoteProperties": "asNeeded",
40+
"semicolons": "asNeeded",
41+
"arrowParentheses": "always",
42+
"bracketSpacing": true,
43+
"bracketSameLine": false,
44+
"quoteStyle": "single",
45+
"attributePosition": "auto"
46+
}
47+
}
48+
}

package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"start": "tsc --watch",
1919
"prepare": "tsc",
2020
"coverage": "jest --coverage",
21-
"lint": "tsc && prettier --list-different --write src tests",
21+
"tsc": "tsc --noEmit",
22+
"lint": "biome lint --diagnostic-level=error src",
2223
"test": "jest"
2324
},
2425
"repository": {
@@ -39,26 +40,20 @@
3940
},
4041
"devDependencies": {
4142
"@arethetypeswrong/cli": "0.15.4",
43+
"@biomejs/biome": "2.0.4",
4244
"@types/jest": "29.5.12",
4345
"@types/node": "20.12.5",
4446
"expect-type": "^0.19.0",
4547
"husky": "9.0.11",
4648
"jest": "29.7.0",
47-
"prettier": "3.2.5",
4849
"ts-jest": "29.1.2",
4950
"typescript": "5.2.2"
5051
},
5152
"author": "Aaron Franks",
5253
"license": "MIT",
53-
"prettier": {
54-
"printWidth": 100,
55-
"semi": false,
56-
"singleQuote": true,
57-
"trailingComma": "all"
58-
},
5954
"husky": {
6055
"hooks": {
61-
"pre-commit": "yarn lint",
56+
"pre-commit": "yarn lint && yarn tsc",
6257
"pre-push": "yarn test"
6358
}
6459
}

src/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EnvError, EnvMissingError } from './errors'
2-
import { CleanOptions, SpecsOutput, Spec, ValidatorSpec } from './types'
2+
import type { CleanOptions, SpecsOutput, Spec, ValidatorSpec } from './types'
33
import { defaultReporter } from './reporter'
44

55
export const testOnlySymbol = Symbol('envalid - test only')
@@ -56,7 +56,7 @@ export function getSanitizedEnv<S>(
5656
specs: S,
5757
options: CleanOptions<SpecsOutput<S>> = {},
5858
): SpecsOutput<S> {
59-
let cleanedEnv = {} as SpecsOutput<S>
59+
const cleanedEnv = {} as SpecsOutput<S>
6060
const castedSpecs = specs as unknown as Record<keyof S, ValidatorSpec<unknown>>
6161
const errors = {} as Record<keyof S, Error>
6262
const varKeys = Object.keys(castedSpecs) as Array<keyof S>
@@ -72,7 +72,7 @@ export function getSanitizedEnv<S>(
7272
if (rawValue === undefined) {
7373
// Use devDefault values only if NODE_ENV was explicitly set, and isn't 'production'
7474
const usingDevDefault =
75-
rawNodeEnv && rawNodeEnv !== 'production' && spec.hasOwnProperty('devDefault')
75+
rawNodeEnv && rawNodeEnv !== 'production' && Object.hasOwn(spec, 'devDefault')
7676

7777
if (usingDevDefault) {
7878
cleanedEnv[k] = spec.devDefault

src/envalid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CleanedEnv, CleanOptions } from './types'
1+
import type { CleanedEnv, CleanOptions } from './types'
22
import { getSanitizedEnv, testOnlySymbol } from './core'
33
import { applyDefaultMiddleware } from './middleware'
44

src/makers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Spec, BaseValidator, StructuredValidator, ExactValidator } from './types'
1+
import type { Spec, BaseValidator, StructuredValidator, ExactValidator } from './types'
22

33
const internalMakeValidator = <T>(parseFn: (input: string) => T) => {
44
return (spec?: Spec<unknown>) => ({ ...spec, _parse: parseFn })

src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CleanedEnvAccessors, StrictProxyMiddlewareOptions } from './types'
1+
import type { CleanedEnvAccessors, StrictProxyMiddlewareOptions } from './types'
22

33
export const strictProxyMiddleware = <T extends object>(
44
envObj: T,
@@ -43,7 +43,7 @@ export const strictProxyMiddleware = <T extends object>(
4343
return target[name]
4444
}
4545

46-
const varExists = target.hasOwnProperty(name)
46+
const varExists = Object.hasOwn(target, name)
4747
if (!varExists) {
4848
if (typeof rawEnv === 'object' && rawEnv?.hasOwnProperty?.(name)) {
4949
throw new ReferenceError(

src/reporter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint-disable no-console */
21
import { EnvMissingError } from './errors'
3-
import { ReporterOptions } from './types'
2+
import type { ReporterOptions } from './types'
43

54
type Errors<T> = Partial<Record<keyof T, Error>>
65
type Logger = (data: any, ...args: any[]) => void

src/validators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { makeExactValidator, makeStructuredValidator, makeValidator } from './ma
55
const isFQDN = (input: string) => {
66
if (!input.length) return false
77
const parts = input.split('.')
8-
for (let part, i = 0; i < parts.length; i++) {
8+
for (let part: string, i = 0; i < parts.length; i++) {
99
part = parts[i]
1010
if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) return false
1111
if (/[\uff01-\uff5e]/.test(part)) return false // disallow full-width chars

tests/basics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanEnv, str, num, testOnly, ReporterOptions } from '../src'
1+
import { cleanEnv, str, num, testOnly, type ReporterOptions } from '../src'
22
import { assertPassthrough } from './utils'
33
import { expectTypeOf } from 'expect-type'
44

0 commit comments

Comments
 (0)