From 30272b84b2f4008f0efe5d938b47a6801f5a3991 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:44:07 +0000 Subject: [PATCH 1/4] build(deps-dev): replace standard with neostandard --- README.md | 2 +- package.json | 5 ++-- types/index.d.ts | 14 ++++----- types/index.test-d.ts | 66 +++++++++++++++++++++---------------------- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 4125930..ca89001 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/csrf/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/csrf/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/csrf.svg?style=flat)](https://www.npmjs.com/package/@fastify/csrf) -[![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) Logic behind CSRF token creation and verification. diff --git a/package.json b/package.json index 5a8a02f..8cf33ab 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "homepage": "https://github.com/fastify/csrf#readme", "scripts": { "bench": "node benchmark/index.js", - "lint": "standard", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:unit": "tap", "test:typescript": "tsd" @@ -30,7 +31,7 @@ "@types/node": "^22.0.0", "beautify-benchmark": "^0.2.4", "benchmark": "^2.1.4", - "standard": "^17.1.0", + "neostandard": "^0.11.9", "tap": "^18.7.1", "tsd": "^0.31.0" }, diff --git a/types/index.d.ts b/types/index.d.ts index 630bf28..0b36c7f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,8 +1,8 @@ interface TokensConstructor { - (options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo; + (options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo; (options?: Tokens.Options): Tokens.TokensSimple; - new(options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo; + new(options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo; new(options?: Tokens.Options): Tokens.TokensSimple; } @@ -11,8 +11,8 @@ declare namespace Tokens { /** * Create a new secret key. */ - secret(callback: SecretCallback): void; - secret(): Promise; + secret(callback: SecretCallback): void; + secret(): Promise; /** * Create a new secret key synchronously. @@ -44,7 +44,7 @@ declare namespace Tokens { verify(secret: string, token: string, userInfo: string): boolean; } - export type SecretCallback = (err: Error | null, secret: string) => void; + export type SecretCallback = (err: Error | null, secret: string) => void export interface Options { /** @@ -100,7 +100,7 @@ type TypedArray = | Int32Array | Uint32Array | Float32Array - | Float64Array; + | Float64Array -declare function Tokens(...params: Parameters): ReturnType +declare function Tokens (...params: Parameters): ReturnType export = Tokens diff --git a/types/index.test-d.ts b/types/index.test-d.ts index da5d2ed..79e92a8 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,46 +1,46 @@ -import { expectError, expectType } from "tsd"; -import { Tokens } from ".."; - -Tokens(); -new Tokens(); -Tokens({}); -new Tokens({}); -Tokens({ algorithm: 'sha1' }); -Tokens({ algorithm: 'sha256' }); -Tokens({ saltLength: 10 }); -Tokens({ secretLength: 10 }); -Tokens({ userInfo: true }); -Tokens({ validity: 10000 }); -Tokens({ hmacKey: 'foo' }); -new Tokens({ saltLength: 10 }); -new Tokens({ secretLength: 10 }); -new Tokens({ userInfo: true }); -new Tokens({ validity: 10000 }); +import { expectError, expectType } from 'tsd' +import { Tokens } from '..' + +Tokens() +new Tokens() +Tokens({}) +new Tokens({}) +Tokens({ algorithm: 'sha1' }) +Tokens({ algorithm: 'sha256' }) +Tokens({ saltLength: 10 }) +Tokens({ secretLength: 10 }) +Tokens({ userInfo: true }) +Tokens({ validity: 10000 }) +Tokens({ hmacKey: 'foo' }) +new Tokens({ saltLength: 10 }) +new Tokens({ secretLength: 10 }) +new Tokens({ userInfo: true }) +new Tokens({ validity: 10000 }) expectError(Tokens('secret')) expectError(new Tokens('secret')) -expectError(new Tokens({}).create('secret', 'userInfo')); -expectError(new Tokens({ userInfo: false}).create('secret', 'userInfo')); -expectError(new Tokens({ userInfo: true }).create('secret')); +expectError(new Tokens({}).create('secret', 'userInfo')) +expectError(new Tokens({ userInfo: false }).create('secret', 'userInfo')) +expectError(new Tokens({ userInfo: true }).create('secret')) -expectError(new Tokens({}).verify('secret', 'token', 'userinfo')); -expectError(new Tokens({ userInfo: false}).verify('secret', 'token', 'userInfo')); -expectError(new Tokens({ userInfo: true }).verify('secret', 'token')); +expectError(new Tokens({}).verify('secret', 'token', 'userinfo')) +expectError(new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo')) +expectError(new Tokens({ userInfo: true }).verify('secret', 'token')) -expectError(new Tokens({ hmacKey: 123 })); +expectError(new Tokens({ hmacKey: 123 })) -expectType>(Tokens().secret()); -expectType>(new Tokens().secret()); +expectType>(Tokens().secret()) +expectType>(new Tokens().secret()) -expectType(Tokens().secret((err, secret ) => { - expectType(err) +expectType(Tokens().secret((err, secret) => { + expectType(err) expectType(secret) -})); -expectType(new Tokens().secret((err, secret ) => { - expectType(err) +})) +expectType(new Tokens().secret((err, secret) => { + expectType(err) expectType(secret) -})); +})) expectType(Tokens().secretSync()) expectType(new Tokens().secretSync()) From effc72d3dd93cb24e63ba7ab9a55f1d9a9fe41a4 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:53:03 +0000 Subject: [PATCH 2/4] 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 +}) From 3f80f3a61385ef1b2ae67441e37ceaa34646747b Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 12 Dec 2024 20:10:18 +0000 Subject: [PATCH 3/4] chore: ignore no-new eslint rule --- types/index.test-d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 79e92a8..b64f029 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-new -- Testing constructor types, so no need to assign */ import { expectError, expectType } from 'tsd' import { Tokens } from '..' From 526c9ae86ff9420f6ab5bdf9e272160f3e2eb7f7 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 13 Dec 2024 13:14:35 +0000 Subject: [PATCH 4/4] build: bump neostandard --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cf33ab..efc4546 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "@types/node": "^22.0.0", "beautify-benchmark": "^0.2.4", "benchmark": "^2.1.4", - "neostandard": "^0.11.9", + "neostandard": "^0.12.0", "tap": "^18.7.1", "tsd": "^0.31.0" },