Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#192)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js
  • Loading branch information
Fdawgs authored Dec 8, 2024
1 parent 39723b3 commit 04af2c9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/env-schema/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/env-schema/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/env-schema.svg?style=flat)](https://www.npmjs.com/package/env-schema)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Utility to check environment variables using [JSON schema](https://json-schema.org/), [Ajv](http://npm.im/ajv), and
[dotenv](http://npm.im/dotenv).
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "c8 --100 node --test",
"test:typescript": "tsd"
Expand Down Expand Up @@ -41,8 +42,7 @@
"ajv-formats": "^3.0.1",
"c8": "^10.1.2",
"fluent-json-schema": "^5.0.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"neostandard": "^0.11.9",
"tsd": "^0.31.0"
},
"pre-commit": [
Expand Down
14 changes: 7 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv';
import { AnySchema } from 'ajv/dist/core';
import { DotenvConfigOptions } from 'dotenv';
import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv'
import { AnySchema } from 'ajv/dist/core'
import { DotenvConfigOptions } from 'dotenv'

type EnvSchema = typeof envSchema

declare namespace envSchema {
export type { JSONSchemaType };
export type { JSONSchemaType }

export type EnvSchemaData = {
[key: string]: unknown;
};
}

export type EnvSchemaOpt<T = EnvSchemaData> = {
schema?: JSONSchemaType<T> | AnySchema;
Expand All @@ -22,7 +22,7 @@ declare namespace envSchema {
| {
customOptions(ajvInstance: Ajv): Ajv;
};
};
}

export const keywords: {
separator: KeywordDefinition
Expand All @@ -32,5 +32,5 @@ declare namespace envSchema {
export { envSchema as default }
}

declare function envSchema<T = envSchema.EnvSchemaData>(_opts?: envSchema.EnvSchemaOpt<T>): T
declare function envSchema<T = envSchema.EnvSchemaData> (_opts?: envSchema.EnvSchemaOpt<T>): T
export = envSchema
86 changes: 43 additions & 43 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expectError, expectType } from 'tsd';
import { expectError, expectType } from 'tsd'
import envSchema, {
EnvSchemaData,
EnvSchemaOpt,
keywords,
envSchema as envSchemaNamed,
default as envSchemaDefault,
} from '..';
import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv';
import { Static, Type } from '@sinclair/typebox';
} from '..'
import Ajv, { KeywordDefinition, JSONSchemaType } from 'ajv'
import { Static, Type } from '@sinclair/typebox'

interface EnvData {
PORT: number;
Expand All @@ -22,94 +22,94 @@ const schemaWithType: JSONSchemaType<EnvData> = {
default: 3000,
},
},
};
}

const schemaTypebox = Type.Object({
PORT: Type.Number({ default: 3000 }),
});
})

type SchemaTypebox = Static<typeof schemaTypebox>;
type SchemaTypebox = Static<typeof schemaTypebox>

const data = {
foo: 'bar',
};
}

expectType<EnvSchemaData>(envSchema());
expectType<EnvSchemaData>(envSchemaNamed());
expectType<EnvSchemaData>(envSchemaDefault());
expectType<EnvSchemaData>(envSchema())
expectType<EnvSchemaData>(envSchemaNamed())
expectType<EnvSchemaData>(envSchemaDefault())

const emptyOpt: EnvSchemaOpt = {};
expectType<EnvSchemaOpt>(emptyOpt);
const emptyOpt: EnvSchemaOpt = {}
expectType<EnvSchemaOpt>(emptyOpt)

const optWithSchemaTypebox: EnvSchemaOpt = {
schema: schemaTypebox,
};
expectType<EnvSchemaOpt>(optWithSchemaTypebox);
}
expectType<EnvSchemaOpt>(optWithSchemaTypebox)

const optWithSchemaWithType: EnvSchemaOpt<EnvData> = {
schema: schemaWithType,
};
expectType<EnvSchemaOpt<EnvData>>(optWithSchemaWithType);
}
expectType<EnvSchemaOpt<EnvData>>(optWithSchemaWithType)

const optWithData: EnvSchemaOpt = {
data,
};
expectType<EnvSchemaOpt>(optWithData);
}
expectType<EnvSchemaOpt>(optWithData)

expectError<EnvSchemaOpt>({
data: [], // min 1 item
});
})

const optWithArrayData: EnvSchemaOpt = {
data: [{}],
};
expectType<EnvSchemaOpt>(optWithArrayData);
}
expectType<EnvSchemaOpt>(optWithArrayData)

const optWithMultipleItemArrayData: EnvSchemaOpt = {
data: [{}, {}],
};
expectType<EnvSchemaOpt>(optWithMultipleItemArrayData);
}
expectType<EnvSchemaOpt>(optWithMultipleItemArrayData)

const optWithDotEnvBoolean: EnvSchemaOpt = {
dotenv: true,
};
expectType<EnvSchemaOpt>(optWithDotEnvBoolean);
}
expectType<EnvSchemaOpt>(optWithDotEnvBoolean)

const optWithDotEnvOpt: EnvSchemaOpt = {
dotenv: {},
};
expectType<EnvSchemaOpt>(optWithDotEnvOpt);
}
expectType<EnvSchemaOpt>(optWithDotEnvOpt)

const optWithEnvExpand: EnvSchemaOpt = {
expandEnv: true,
};
expectType<EnvSchemaOpt>(optWithEnvExpand);
}
expectType<EnvSchemaOpt>(optWithEnvExpand)

const optWithAjvInstance: EnvSchemaOpt = {
ajv: new Ajv(),
};
expectType<EnvSchemaOpt>(optWithAjvInstance);
expectType<KeywordDefinition>(envSchema.keywords.separator);
}
expectType<EnvSchemaOpt>(optWithAjvInstance)
expectType<KeywordDefinition>(envSchema.keywords.separator)

const optWithAjvCustomOptions: EnvSchemaOpt = {
ajv: {
customOptions(ajvInstance: Ajv): Ajv {
return new Ajv();
customOptions (ajvInstance: Ajv): Ajv {
return new Ajv()
},
},
};
expectType<EnvSchemaOpt>(optWithAjvCustomOptions);
}
expectType<EnvSchemaOpt>(optWithAjvCustomOptions)
expectError<EnvSchemaOpt>({
ajv: {
customOptions(ajvInstance: Ajv) {},
customOptions (ajvInstance: Ajv) {},
},
});
})

const envSchemaWithType = envSchema({ schema: schemaWithType });
expectType<EnvData>(envSchemaWithType);
const envSchemaWithType = envSchema({ schema: schemaWithType })
expectType<EnvData>(envSchemaWithType)

const envSchemaTypebox = envSchema<SchemaTypebox>({ schema: schemaTypebox });
expectType<SchemaTypebox>(envSchemaTypebox);
const envSchemaTypebox = envSchema<SchemaTypebox>({ schema: schemaTypebox })
expectType<SchemaTypebox>(envSchemaTypebox)

expectType<KeywordDefinition>(keywords.separator)
expectType<KeywordDefinition>(envSchema.keywords.separator)

0 comments on commit 04af2c9

Please sign in to comment.