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/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 +}) diff --git a/package.json b/package.json index 5a8a02f..efc4546 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.12.0", "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..b64f029 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,46 +1,47 @@ -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 }); +/* eslint-disable no-new -- Testing constructor types, so no need to assign */ +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())