From 4f66667864238a2b655dd2df3f4ccf479e5c4e0a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:44:12 +0000 Subject: [PATCH 1/2] build(deps-dev): replace standard with neostandard --- README.md | 2 +- package.json | 6 +-- types/index.d.ts | 14 +++---- types/index.test-d.ts | 86 +++++++++++++++++++++---------------------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 5130915..7acaf29 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/package.json b/package.json index 763983e..3f76e40 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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": [ diff --git a/types/index.d.ts b/types/index.d.ts index 9004d84..c7f6d2c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 = { schema?: JSONSchemaType | AnySchema; @@ -22,7 +22,7 @@ declare namespace envSchema { | { customOptions(ajvInstance: Ajv): Ajv; }; - }; + } export const keywords: { separator: KeywordDefinition @@ -32,5 +32,5 @@ declare namespace envSchema { export { envSchema as default } } -declare function envSchema(_opts?: envSchema.EnvSchemaOpt): T +declare function envSchema (_opts?: envSchema.EnvSchemaOpt): T export = envSchema diff --git a/types/index.test-d.ts b/types/index.test-d.ts index cde6173..f906e9e 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -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; @@ -22,94 +22,94 @@ const schemaWithType: JSONSchemaType = { default: 3000, }, }, -}; +} const schemaTypebox = Type.Object({ PORT: Type.Number({ default: 3000 }), -}); +}) -type SchemaTypebox = Static; +type SchemaTypebox = Static const data = { foo: 'bar', -}; +} -expectType(envSchema()); -expectType(envSchemaNamed()); -expectType(envSchemaDefault()); +expectType(envSchema()) +expectType(envSchemaNamed()) +expectType(envSchemaDefault()) -const emptyOpt: EnvSchemaOpt = {}; -expectType(emptyOpt); +const emptyOpt: EnvSchemaOpt = {} +expectType(emptyOpt) const optWithSchemaTypebox: EnvSchemaOpt = { schema: schemaTypebox, -}; -expectType(optWithSchemaTypebox); +} +expectType(optWithSchemaTypebox) const optWithSchemaWithType: EnvSchemaOpt = { schema: schemaWithType, -}; -expectType>(optWithSchemaWithType); +} +expectType>(optWithSchemaWithType) const optWithData: EnvSchemaOpt = { data, -}; -expectType(optWithData); +} +expectType(optWithData) expectError({ data: [], // min 1 item -}); +}) const optWithArrayData: EnvSchemaOpt = { data: [{}], -}; -expectType(optWithArrayData); +} +expectType(optWithArrayData) const optWithMultipleItemArrayData: EnvSchemaOpt = { data: [{}, {}], -}; -expectType(optWithMultipleItemArrayData); +} +expectType(optWithMultipleItemArrayData) const optWithDotEnvBoolean: EnvSchemaOpt = { dotenv: true, -}; -expectType(optWithDotEnvBoolean); +} +expectType(optWithDotEnvBoolean) const optWithDotEnvOpt: EnvSchemaOpt = { dotenv: {}, -}; -expectType(optWithDotEnvOpt); +} +expectType(optWithDotEnvOpt) const optWithEnvExpand: EnvSchemaOpt = { expandEnv: true, -}; -expectType(optWithEnvExpand); +} +expectType(optWithEnvExpand) const optWithAjvInstance: EnvSchemaOpt = { ajv: new Ajv(), -}; -expectType(optWithAjvInstance); -expectType(envSchema.keywords.separator); +} +expectType(optWithAjvInstance) +expectType(envSchema.keywords.separator) const optWithAjvCustomOptions: EnvSchemaOpt = { ajv: { - customOptions(ajvInstance: Ajv): Ajv { - return new Ajv(); + customOptions (ajvInstance: Ajv): Ajv { + return new Ajv() }, }, -}; -expectType(optWithAjvCustomOptions); +} +expectType(optWithAjvCustomOptions) expectError({ ajv: { - customOptions(ajvInstance: Ajv) {}, + customOptions (ajvInstance: Ajv) {}, }, -}); +}) -const envSchemaWithType = envSchema({ schema: schemaWithType }); -expectType(envSchemaWithType); +const envSchemaWithType = envSchema({ schema: schemaWithType }) +expectType(envSchemaWithType) -const envSchemaTypebox = envSchema({ schema: schemaTypebox }); -expectType(envSchemaTypebox); +const envSchemaTypebox = envSchema({ schema: schemaTypebox }) +expectType(envSchemaTypebox) expectType(keywords.separator) expectType(envSchema.keywords.separator) From 3639e90b8ca5f8802bc298b5c4d661694fadce1a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:53:08 +0000 Subject: [PATCH 2/2] chore: add eslint.config.js --- eslint.config.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..89fd678 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: require('neostandard').resolveIgnoresFromGitignore(), + ts: true +})