Skip to content

Commit aafe2ff

Browse files
committed
chore: tweaks
1 parent 410c432 commit aafe2ff

15 files changed

Lines changed: 278 additions & 233 deletions

.oxfmtrc.json renamed to .oxfmtrc.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "./node_modules/oxfmt/configuration_schema.json",
33
"ignorePatterns": ["coverage/", "dist/"],
44
"experimentalSortPackageJson": {
5-
"sortScripts": true
6-
}
5+
"sortScripts": true,
6+
},
77
}
Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"pedantic": "warn",
77
"perf": "warn",
88
"style": "warn",
9-
"restriction": "warn"
9+
"restriction": "warn",
1010
},
1111
"rules": {
1212
// oxlint core rules
@@ -48,6 +48,9 @@
4848
"no-void": "off",
4949
// normally we do not enforce numeric separator usage
5050
"numeric-separators-style": "off",
51+
// some functions that return promise and plain values in different conditions
52+
// need an async declaration while not always using await
53+
"require-await": "off",
5154
// we prefer to sort imports with its pkg name
5255
"sort-imports": "off",
5356
// object keys are not supposed to be sorted in many cases
@@ -111,38 +114,41 @@
111114
{
112115
"selector": "variable",
113116
"filter": { "regex": "^__(?:dirname|filename)$", "match": true },
114-
"format": null
117+
"format": null,
115118
},
116119
{
117120
"selector": "variable",
118-
"filter": { "regex": "^(?:_{0,2})[A-Z][A-z0-9]*(?:_[A-Z][A-z0-9]*)*$", "match": true },
119-
"format": null
121+
"filter": {
122+
"regex": "^(?:_{0,2})[A-Z][A-z0-9]*(?:_[A-Z][A-z0-9]*)*$",
123+
"match": true,
124+
},
125+
"format": null,
120126
},
121127
{
122128
"selector": ["variable"],
123129
"format": ["camelCase", "PascalCase", "UPPER_CASE"],
124-
"leadingUnderscore": "allow"
130+
"leadingUnderscore": "allow",
125131
},
126132
{
127133
"selector": ["parameter"],
128134
"format": ["camelCase", "PascalCase"],
129-
"leadingUnderscore": "allow"
135+
"leadingUnderscore": "allow",
130136
},
131137
{
132138
"selector": ["property"],
133139
"format": ["camelCase", "PascalCase", "UPPER_CASE"],
134140
"leadingUnderscore": "allow",
135-
"trailingUnderscore": "allow"
141+
"trailingUnderscore": "allow",
136142
},
137143
{ "selector": "import", "format": ["PascalCase", "camelCase"] },
138144
{ "selector": "typeLike", "format": ["PascalCase"] },
139-
{ "selector": "enumMember", "format": ["PascalCase"] }
140-
]
145+
{ "selector": "enumMember", "format": ["PascalCase"] },
146+
],
141147
],
142148
// allow non-null assertions in some cases
143149
"typescript/strict-boolean-expressions": [
144150
"warn",
145-
{ "allowNullableString": true, "allowNullableBoolean": true }
151+
{ "allowNullableString": true, "allowNullableBoolean": true },
146152
],
147153
// missing async with await will be reported by typescript itself
148154
"typescript/promise-function-async": "off",
@@ -151,6 +157,8 @@
151157
// filename should not be enforced strictly, e.g. Vue SFC files shall be PascalCased
152158
// we shall expect a project level setting
153159
"unicorn/filename-case": "off",
160+
// this rule introduce too many false positives
161+
"unicorn/explicit-length-check": "off",
154162
// toReversed can introduce memory overhead,
155163
// in some chained calls it is better to use reverse as the "reversed" array is also a temp variable.
156164
"unicorn/no-array-reverse": "off",
@@ -159,6 +167,8 @@
159167
"unicorn/no-array-sort": "off",
160168
// Array.forEach has its use cases
161169
"unicorn/no-array-for-each": "off",
170+
// for code simplicity we may not want to create temp variables for single use
171+
"unicorn/no-await-expression-member": "off",
162172
// conflicts with oxfmt code style
163173
"unicorn/no-nested-ternary": "off",
164174
// conflicts with oxfmt code style
@@ -168,6 +178,8 @@
168178
// support starts with chrome71, firefox68. safari12.1, node12
169179
// leaving it to warn for edge cases
170180
"unicorn/prefer-global-this": "warn",
181+
// prefer utf-8 over utf8
182+
"unicorn/text-encoding-identifier-case": ["error", { "withDash": true }],
171183

172184
// stylistic rules with default being tweaked
173185
"catch-error-name": ["warn", { "name": "err" }],
@@ -188,27 +200,27 @@
188200
// type generics
189201
"T",
190202
// parameter name for unused variables
191-
"_"
192-
]
193-
}
203+
"_",
204+
],
205+
},
194206
],
195207
"max-dependencies": ["warn", { "ignoreTypeImports": true, "max": 15 }],
196208
"max-lines": ["warn", { "max": 500, "skipBlankLines": true, "skipComments": true }],
197209
"max-lines-per-function": [
198210
"warn",
199-
{ "max": 100, "skipBlankLines": true, "skipComments": true }
211+
{ "max": 100, "skipBlankLines": true, "skipComments": true },
200212
],
201213
"max-params": ["warn", 4],
202-
"max-statements": ["warn", { "max": 30 }]
214+
"max-statements": ["warn", { "max": 30 }],
203215
},
204216
"overrides": [
205217
{
206218
"files": ["scripts/**/*.{js,ts}", "*.config.{js,ts}"],
207219
"plugins": ["node"],
208220
"rules": {
209221
// config files shall be allowed to access process.env
210-
"node/no-process-env": "off"
211-
}
222+
"node/no-process-env": "off",
223+
},
212224
},
213225
{
214226
"files": ["*.{jsx,tsx}"],
@@ -218,20 +230,20 @@
218230
// disable jsdoc rules in react components
219231
"jsdoc/require-returns": "off",
220232
// allow loose boolean expressions in react components
221-
"typescript/strict-boolean-expressions": "off"
222-
}
233+
"typescript/strict-boolean-expressions": "off",
234+
},
223235
},
224236
{
225237
"files": ["*.d.ts"],
226238
"rules": {
227239
// to extend existing modules, import/export must not appear in declaration files at top level
228240
"import/unambiguous": "off",
229241
// we need `export {}` to convert a file to a module
230-
"unicorn/require-module-specifiers": "off"
231-
}
242+
"unicorn/require-module-specifiers": "off",
243+
},
232244
},
233245
{
234-
"files": ["*.bench.{js,ts}", "*.test.{js,ts}"],
246+
"files": ["*.{bench,spec,test}.{js,ts}", "*.{spec,test}.{js,ts}", "*.{spec,test}-d.ts"],
235247
"plugins": ["vitest"],
236248
"rules": {
237249
"id-length": "off",
@@ -246,8 +258,12 @@
246258
"typescript/prefer-ts-expect-error": "off",
247259
"typescript/require-array-sort-compare": "off",
248260
"vitest/prefer-called-once": "off",
249-
"unicorn/consistent-function-scoping": "off"
250-
}
251-
}
252-
]
261+
"vitest/consistent-test-filename": [
262+
"warn",
263+
{ "allTestPattern": "__tests__", "pattern": ".*\\.spec\\.ts$" },
264+
],
265+
"unicorn/consistent-function-scoping": "off",
266+
},
267+
},
268+
],
253269
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3-
"extends": ["./.oxlintrc.base.json"],
3+
"extends": ["./.oxlintrc.base.jsonc"],
44
"ignorePatterns": ["coverage/", "dist/"],
55
"plugins": ["typescript", "oxc", "jsdoc", "import", "promise", "unicorn", "node"],
66
"rules": {
77
"id-length": "off",
8-
"no-bitwise": "off"
9-
}
8+
"no-bitwise": "off",
9+
},
1010
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![npm downloads](https://img.shields.io/npm/dw/bcrypt-ts)](https://www.npmjs.com/package/bcrypt-ts)
55
[![types](https://img.shields.io/npm/types/bcrypt-ts)](https://mister-hope.github.io/bcrypt-ts/)
66

7-
[![Test](https://github.com/Mister-Hope/bcrypt-ts/actions/workflows/test.yml/badge.svg)](https://github.com/Mister-Hope/bcrypt-ts/actions/workflows/test.yml)
87
[![DeepScan grade](https://deepscan.io/api/teams/15982/projects/28024/branches/898932/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=15982&pid=28024&bid=898932) [![codecov](https://codecov.io/gh/Mister-Hope/bcrypt-ts/graph/badge.svg?token=oO5gZq2aHe)](https://codecov.io/gh/Mister-Hope/bcrypt-ts)
98

109
Optimized bcrypt in TypeScript with zero dependencies. Compatible to the C++ [bcrypt](https://npmjs.org/package/bcrypt) binding on Node.js and also working in the browser.

__tests__/base64.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ describe(decodeBase64, () => {
4141
expect(result.length).toBeLessThanOrEqual(5);
4242
});
4343

44+
it("should handle characters with code >= BASE64_INDEX.length", () => {
45+
// \u0080 has code 128, which is >= BASE64_INDEX.length (128)
46+
const result1 = decodeBase64("\u0080\u0080\u0080\u0080", 5);
47+
expect(result1.length).toBe(0);
48+
49+
const result2 = decodeBase64("..\u0080\u0080", 5);
50+
expect(result2.length).toBe(1);
51+
52+
const result3 = decodeBase64("...\u0080", 5);
53+
expect(result3.length).toBe(3);
54+
});
55+
4456
it("should handle early break on invalid c1 or c2", () => {
4557
// Test with string containing invalid characters at start
4658
const result = decodeBase64("@invalid", 5);

__tests__/hash.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe(hash, () => {
1515
expect(hash4).toBeTypeOf("string");
1616
expect(hash1).not.toEqual(hash2);
1717
expect(hash3).not.toEqual(hash4);
18+
19+
const hash5 = await hash("hello", 4);
20+
expect(hash5).toContain("$04$");
21+
22+
const hash6 = await hash("hello", "$2$10$abcdefghijklmnopqrstuv");
23+
expect(hash6).toContain("$2$10$");
1824
});
1925

2026
it("should reject for invalid argument types", async () => {
@@ -64,13 +70,21 @@ describe(hashSync, () => {
6470
const hash2 = hashSync("hello", 10);
6571
const hash3 = hashSync("中国我爱你!", 10);
6672
const hash4 = hashSync("中国我爱你!", 10);
73+
const hash7 = hashSync("hello");
6774

6875
expect(hash1).toBeTypeOf("string");
6976
expect(hash2).toBeTypeOf("string");
7077
expect(hash3).toBeTypeOf("string");
7178
expect(hash4).toBeTypeOf("string");
79+
expect(hash7).toBeTypeOf("string");
7280
expect(hash1).not.toEqual(hash2);
7381
expect(hash3).not.toEqual(hash4);
82+
83+
const hash5 = hashSync("hello", 4);
84+
expect(hash5).toContain("$04$");
85+
86+
const hash6 = hashSync("hello", "$2$10$abcdefghijklmnopqrstuv");
87+
expect(hash6).toContain("$2$10$");
7488
});
7589

7690
it("should throw error for invalid argument types", () => {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
},
5555
"devDependencies": {
5656
"@codecov/rollup-plugin": "1.9.1",
57-
"@commitlint/cli": "20.4.0",
58-
"@commitlint/config-conventional": "20.4.0",
57+
"@commitlint/cli": "20.4.1",
58+
"@commitlint/config-conventional": "20.4.1",
5959
"@types/node": "25.2.0",
6060
"@vitest/coverage-istanbul": "4.0.18",
6161
"husky": "9.1.7",
6262
"nano-staged": "0.9.0",
63-
"oxfmt": "0.27.0",
64-
"oxlint": "1.42.0",
63+
"oxfmt": "0.28.0",
64+
"oxlint": "1.43.0",
6565
"oxlint-tsgolint": "0.11.4",
6666
"rimraf": "6.1.2",
6767
"tsdown": "0.20.1",

0 commit comments

Comments
 (0)