mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-10 23:31:08 +00:00
Widen loadEnv schema type and allow rest-sibling destructuring in lint
loadEnv's ZodSchema<T> parameter required schema input === output,
which breaks any schema using .transform() (e.g. AppConfigSchema's
boolean coercion). Widen to ZodType<T, ZodTypeDef, unknown>, matching
existing runtime behavior. Also allow ignoreRestSiblings in the
no-unused-vars rule so 'const { X, ...rest } = obj' omission tests
don't trip the linter.
This commit is contained in:
@@ -7,6 +7,9 @@ module.exports = {
|
|||||||
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
||||||
ignorePatterns: ['dist', 'node_modules'],
|
ignorePatterns: ['dist', 'node_modules'],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
'@typescript-eslint/no-unused-vars': [
|
||||||
|
'error',
|
||||||
|
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import type { ZodSchema } from 'zod';
|
import type { ZodType, ZodTypeDef } from 'zod';
|
||||||
|
|
||||||
export function loadEnv<T>(schema: ZodSchema<T>, source: NodeJS.ProcessEnv = process.env): T {
|
export function loadEnv<T>(
|
||||||
|
schema: ZodType<T, ZodTypeDef, unknown>,
|
||||||
|
source: NodeJS.ProcessEnv = process.env
|
||||||
|
): T {
|
||||||
const result = schema.safeParse(source);
|
const result = schema.safeParse(source);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throw new Error(`Invalid environment configuration: ${result.error.message}`);
|
throw new Error(`Invalid environment configuration: ${result.error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user