From c4df25f16fa63a685d0632524e8ecd1fd9fb880c Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 12 Dec 2024 19:52:22 +0000 Subject: [PATCH 1/2] build(deps-dev): replace standard with neostandard --- README.md | 2 +- benchmark/bench-cmp-lib.js | 1 - package.json | 11 +-- types/index.d.ts | 50 ++++++------- types/index.test-d.ts | 146 ++++++++++++++++++------------------- 5 files changed, 102 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 3796d480..06d50c74 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify) -[![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) [![NPM downloads](https://img.shields.io/npm/dm/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify) diff --git a/benchmark/bench-cmp-lib.js b/benchmark/bench-cmp-lib.js index 373b2e42..658e3a14 100644 --- a/benchmark/bench-cmp-lib.js +++ b/benchmark/bench-cmp-lib.js @@ -134,7 +134,6 @@ const getRandomString = (length) => { return result[0].toUpperCase() + result.slice(1) } -// eslint-disable-next-line for (let i = 0; i < STR_LEN; i++) { largeArray[i] = { firstName: getRandomString(8), diff --git a/package.json b/package.json index 223a080d..0e382d7c 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "bench:cmp": "node ./benchmark/bench-cmp-branch.js", "bench:cmp:ci": "node ./benchmark/bench-cmp-branch.js --ci", "benchmark": "node ./benchmark/bench-cmp-lib.js", - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "test:typescript": "tsd", "test:unit": "c8 node --test", "test": "npm run test:unit && npm run test:typescript" @@ -45,8 +45,8 @@ "compile-json-stringify": "^0.1.2", "fast-json-stringify": ".", "is-my-json-valid": "^2.20.6", + "neostandard": "^0.11.9", "simple-git": "^3.23.0", - "standard": "^17.1.0", "tsd": "^0.31.0", "webpack": "^5.90.3" }, @@ -58,10 +58,5 @@ "json-schema-ref-resolver": "^2.0.0", "rfdc": "^1.2.0" }, - "standard": { - "ignore": [ - "schema-validator.js" - ] - }, "runkitExampleFilename": "./examples/example.js" } diff --git a/types/index.d.ts b/types/index.d.ts index 1abf2640..84721295 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,4 @@ -import Ajv, { Options as AjvOptions } from "ajv" +import Ajv, { Options as AjvOptions } from 'ajv' type Build = typeof build @@ -70,28 +70,28 @@ declare namespace build { } export interface StringSchema extends BaseSchema { - type: "string"; + type: 'string'; format?: string; } export interface IntegerSchema extends BaseSchema { - type: "integer"; + type: 'integer'; } export interface NumberSchema extends BaseSchema { - type: "number"; + type: 'number'; } export interface NullSchema extends BaseSchema { - type: "null"; + type: 'null'; } export interface BooleanSchema extends BaseSchema { - type: "boolean"; + type: 'boolean'; } export interface ArraySchema extends BaseSchema { - type: "array"; + type: 'array'; /** * The schema for the items in the array */ @@ -99,7 +99,7 @@ declare namespace build { } export interface TupleSchema extends BaseSchema { - type: "array"; + type: 'array'; /** * The schemas for the items in the tuple */ @@ -115,7 +115,7 @@ declare namespace build { } export interface ObjectSchema extends BaseSchema { - type: "object"; + type: 'object'; /** * Describe the properties of the object */ @@ -145,7 +145,7 @@ declare namespace build { | BooleanSchema | ArraySchema | TupleSchema - | ObjectSchema; + | ObjectSchema export interface Options { /** @@ -208,24 +208,24 @@ interface StandaloneOption extends build.Options { mode: 'standalone' } -type StringCoercible = string | Date | RegExp; -type IntegerCoercible = number | BigInt; +type StringCoercible = string | Date | RegExp +type IntegerCoercible = number | BigInt /** * Build a stringify function using a schema of the documents that should be stringified * @param schema The schema used to stringify values * @param options The options to use (optional) */ -declare function build(schema: build.AnySchema, options: DebugOption): { code: string, ajv: Ajv }; -declare function build(schema: build.AnySchema, options: DeprecateDebugOption): { code: string, ajv: Ajv }; -declare function build(schema: build.AnySchema, options: StandaloneOption): string; -declare function build(schema: build.AnySchema, options?: build.Options): (doc: TDoc) => any; -declare function build(schema: build.StringSchema, options?: build.Options): (doc: TDoc) => string; -declare function build(schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): (doc: TDoc) => string; -declare function build(schema: build.NullSchema, options?: build.Options): (doc: TDoc) => "null"; -declare function build(schema: build.BooleanSchema, options?: build.Options): (doc: TDoc) => string; -declare function build(schema: build.ArraySchema | build.TupleSchema, options?: build.Options): (doc: TDoc) => string; -declare function build(schema: build.ObjectSchema, options?: build.Options): (doc: TDoc) => string; -declare function build(schema: build.Schema, options?: build.Options): (doc: TDoc) => string; - -export = build; +declare function build (schema: build.AnySchema, options: DebugOption): { code: string, ajv: Ajv } +declare function build (schema: build.AnySchema, options: DeprecateDebugOption): { code: string, ajv: Ajv } +declare function build (schema: build.AnySchema, options: StandaloneOption): string +declare function build (schema: build.AnySchema, options?: build.Options): (doc: TDoc) => any +declare function build (schema: build.StringSchema, options?: build.Options): (doc: TDoc) => string +declare function build (schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): (doc: TDoc) => string +declare function build (schema: build.NullSchema, options?: build.Options): (doc: TDoc) => 'null' +declare function build (schema: build.BooleanSchema, options?: build.Options): (doc: TDoc) => string +declare function build (schema: build.ArraySchema | build.TupleSchema, options?: build.Options): (doc: TDoc) => string +declare function build (schema: build.ObjectSchema, options?: build.Options): (doc: TDoc) => string +declare function build (schema: build.Schema, options?: build.Options): (doc: TDoc) => string + +export = build diff --git a/types/index.test-d.ts b/types/index.test-d.ts index e314d804..6f61d808 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -4,29 +4,29 @@ import { expectError, expectType } from 'tsd' // Number schemas build({ - type: 'number' + type: 'number' })(25) build({ - type: 'integer' + type: 'integer' })(-5) build({ - type: 'integer' + type: 'integer' })(5n) build({ - type: 'number' + type: 'number' }, { rounding: 'ceil' }) build({ - type: 'number' + type: 'number' }, { rounding: 'floor' }) build({ - type: 'number' + type: 'number' }, { rounding: 'round' }) build({ - type: 'number' + type: 'number' }, { rounding: 'trunc' }) expectError(build({ - type: 'number' + type: 'number' }, { rounding: 'invalid' })) // String schema @@ -36,55 +36,55 @@ build({ // Boolean schema build({ - type: 'boolean' + type: 'boolean' })(true) // Null schema build({ - type: 'null' + type: 'null' })(null) // Array schemas build({ - type: 'array', - items: { type: 'number' } + type: 'array', + items: { type: 'number' } })([25]) build({ - type: 'array', - items: [{ type: 'string'}, {type: 'integer'}] + type: 'array', + items: [{ type: 'string' }, { type: 'integer' }] })(['hello', 42]) // Object schemas build({ - type: 'object' + type: 'object' })({}) build({ - type: 'object', - properties: { - foo: { type: 'string' }, - bar: { type: 'integer' } - }, - required: ['foo'], - patternProperties: { - 'baz*': { type: 'null' } - }, - additionalProperties: { - type: 'boolean' - } + type: 'object', + properties: { + foo: { type: 'string' }, + bar: { type: 'integer' } + }, + required: ['foo'], + patternProperties: { + 'baz*': { type: 'null' } + }, + additionalProperties: { + type: 'boolean' + } })({ foo: 'bar' }) build({ - type: 'object', - properties: { - foo: { type: 'string' }, - bar: { type: 'integer' } - }, - required: ['foo'], - patternProperties: { - 'baz*': { type: 'null' } - }, - additionalProperties: { - type: 'boolean' - } + type: 'object', + properties: { + foo: { type: 'string' }, + bar: { type: 'integer' } + }, + required: ['foo'], + patternProperties: { + 'baz*': { type: 'null' } + }, + additionalProperties: { + type: 'boolean' + } }, { rounding: 'floor' })({ foo: 'bar' }) // Reference schemas @@ -113,7 +113,7 @@ build({ } }, patternProperties: { - 'num': { + num: { $ref: '#/definitions/num' } }, @@ -207,52 +207,52 @@ interface InferenceSchema { } const stringify3 = build({ - type: "object", - properties: { a: { type: "string" } }, -}); -stringify3({ id: "123" }); -stringify3({ a: 123, id: "123" }); -expectError(stringify3({ anotherOne: "bar" })); -expectError(stringify3({ a: "bar" })); + type: 'object', + properties: { a: { type: 'string' } }, +}) +stringify3({ id: '123' }) +stringify3({ a: 123, id: '123' }) +expectError(stringify3({ anotherOne: 'bar' })) +expectError(stringify3({ a: 'bar' })) // Without inference const stringify4 = build({ - type: "object", - properties: { a: { type: "string" } }, -}); -stringify4({ id: "123" }); -stringify4({ a: 123, id: "123" }); -stringify4({ anotherOne: "bar" }); -stringify4({ a: "bar" }); + type: 'object', + properties: { a: { type: 'string' } }, +}) +stringify4({ id: '123' }) +stringify4({ a: 123, id: '123' }) +stringify4({ anotherOne: 'bar' }) +stringify4({ a: 'bar' }) // Without inference - string type const stringify5 = build({ - type: "string", -}); -stringify5("foo"); -expectError(stringify5({ id: "123" })); + type: 'string', +}) +stringify5('foo') +expectError(stringify5({ id: '123' })) // Without inference - null type const stringify6 = build({ - type: "null", -}); -stringify6(null); -expectError(stringify6("a string")); + type: 'null', +}) +stringify6(null) +expectError(stringify6('a string')) // Without inference - boolean type const stringify7 = build({ - type: "boolean", -}); -stringify7(true); -expectError(stringify7("a string")); + type: 'boolean', +}) +stringify7(true) +expectError(stringify7('a string')) // largeArrayMechanism -build({}, { largeArrayMechanism: 'json-stringify'} ) -build({}, { largeArrayMechanism: 'default'} ) -expectError(build({} as Schema, { largeArrayMechanism: 'invalid'} )) +build({}, { largeArrayMechanism: 'json-stringify' }) +build({}, { largeArrayMechanism: 'default' }) +expectError(build({} as Schema, { largeArrayMechanism: 'invalid' })) -build({}, { largeArraySize: 2000 } ) -build({}, { largeArraySize: '2e4' } ) -build({}, { largeArraySize: 2n } ) -expectError(build({} as Schema, { largeArraySize: ['asdf']} )) \ No newline at end of file +build({}, { largeArraySize: 2000 }) +build({}, { largeArraySize: '2e4' }) +build({}, { largeArraySize: 2n }) +expectError(build({} as Schema, { largeArraySize: ['asdf'] })) From 046040ece52ef357bfd1a9e449f98210992fd402 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 12 Dec 2024 19:52:46 +0000 Subject: [PATCH 2/2] test(types): ignore unused import --- eslint.config.js | 9 +++++++++ types/index.test-d.ts | 1 + 2 files changed, 10 insertions(+) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..252fdf4b --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,9 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: [ + ...require('neostandard').resolveIgnoresFromGitignore(), + 'lib/schema-validator.js' + ], + ts: true +}) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 6f61d808..50da4201 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683 import Ajv from 'ajv' import build, { restore, Schema, validLargeArrayMechanisms } from '..' import { expectError, expectType } from 'tsd'