Skip to content

Commit d411a9f

Browse files
authored
feat: use prettier, oxlint and vitest (#27)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a pre-commit hook to enforce code quality on staged files. - Added configuration files for OXLint and Prettier to standardize linting and formatting. - Updated lint-staged to automatically fix code style on commit. - **Chores** - Migrated project tooling from ESLint and egg-bin to OXLint, Prettier, and Vitest. - Updated CI workflows to use newer Node.js and Codecov versions. - Removed ESLint configuration and dependencies. - Improved environment variable handling in test configuration. - **Documentation** - Enhanced README formatting for clarity and readability. - **Refactor & Style** - Improved code formatting, type annotations, and consistency across all modules. - Refined method and function signatures for better type safety and readability. - Updated test files to use Vitest conventions and improved assertion clarity. - **Tests** - Migrated tests to Vitest and updated test hooks and assertions for consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1f7c506 commit d411a9f

23 files changed

+1664
-872
lines changed

.eslintrc

-6
This file was deleted.

.github/workflows/nodejs.yml

+25-25
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
node-version: [18, 20, 22, 23]
21+
node-version: [18, 20, 22, 24]
2222
os: [ubuntu-latest]
2323

2424
steps:
25-
- name: Checkout Git Source
26-
uses: actions/checkout@v4
27-
28-
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v4
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
33-
- name: Install Dependencies
34-
run: npm i
35-
36-
- name: Continuous Integration
37-
run: npm run ci
38-
env:
39-
OSS_CLIENT_ID: ${{ secrets.OSS_CLIENT_ID }}
40-
OSS_CLIENT_SECRET: ${{ secrets.OSS_CLIENT_SECRET }}
41-
OSS_CLIENT_REGION: ${{ secrets.OSS_CLIENT_REGION }}
42-
OSS_CLIENT_ENDPOINT: ${{ secrets.OSS_CLIENT_ENDPOINT }}
43-
OSS_CLIENT_BUCKET: ${{ secrets.OSS_CLIENT_BUCKET }}
44-
45-
- name: Code Coverage
46-
uses: codecov/codecov-action@v3
47-
with:
48-
token: ${{ secrets.CODECOV_TOKEN }}
25+
- name: Checkout Git Source
26+
uses: actions/checkout@v4
27+
28+
- name: Use Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
33+
- name: Install Dependencies
34+
run: npm i
35+
36+
- name: Continuous Integration
37+
run: npm run ci
38+
env:
39+
OSS_CLIENT_ID: ${{ secrets.OSS_CLIENT_ID }}
40+
OSS_CLIENT_SECRET: ${{ secrets.OSS_CLIENT_SECRET }}
41+
OSS_CLIENT_REGION: ${{ secrets.OSS_CLIENT_REGION }}
42+
OSS_CLIENT_ENDPOINT: ${{ secrets.OSS_CLIENT_ENDPOINT }}
43+
OSS_CLIENT_BUCKET: ${{ secrets.OSS_CLIENT_BUCKET }}
44+
45+
- name: Code Coverage
46+
uses: codecov/codecov-action@v5
47+
with:
48+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
release:

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.oxlintrc.json

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"env": {
4+
"node": true,
5+
"mocha": true
6+
},
7+
"categories": {
8+
"correctness": "error",
9+
"perf": "error",
10+
"nursery": "error",
11+
"restriction": "error",
12+
"style": "error",
13+
"pedantic": "error",
14+
"suspicious": "error"
15+
},
16+
"plugins": [
17+
"import",
18+
"typescript",
19+
"unicorn",
20+
"jsdoc",
21+
"node",
22+
"promise",
23+
"oxc"
24+
],
25+
"rules": {
26+
// eslint
27+
"constructor-super": "error",
28+
"getter-return": "error",
29+
"no-undef": "error",
30+
"no-unreachable": "error",
31+
"no-var": "error",
32+
"no-eq-null": "error",
33+
"no-await-in-loop": "allow",
34+
"eqeqeq": ["error", "smart"],
35+
"init-declarations": "allow",
36+
"curly": "allow",
37+
"no-ternary": "allow",
38+
"max-params": ["error", 5],
39+
"no-await-expression-member": "error",
40+
"no-continue": "allow",
41+
"guard-for-in": "allow",
42+
"func-style": "allow",
43+
"sort-imports": "allow",
44+
"yoda": "allow",
45+
"sort-keys": "allow",
46+
"no-magic-numbers": "allow",
47+
"no-duplicate-imports": "error",
48+
"no-multi-assign": "error",
49+
"func-names": "error",
50+
"default-param-last": "error",
51+
"prefer-object-spread": "error",
52+
"no-undefined": "allow",
53+
"no-plusplus": "allow",
54+
// maybe warn
55+
"no-console": "warn",
56+
"no-extraneous-class": "allow",
57+
"no-empty-function": "allow",
58+
"max-depth": ["error", 6],
59+
"max-lines-per-function": "allow",
60+
"no-lonely-if": "error",
61+
"max-lines": "allow",
62+
"require-await": "allow",
63+
"max-nested-callbacks": ["error", 5],
64+
"max-classes-per-file": "allow",
65+
"radix": "allow",
66+
"no-negated-condition": "error",
67+
"no-else-return": "error",
68+
"no-throw-literal": "error",
69+
70+
// import
71+
"import/exports-last": "allow",
72+
"import/max-dependencies": "allow",
73+
"import/no-cycle": "error",
74+
"import/no-anonymous-default-export": "allow",
75+
"import/no-namespace": "error",
76+
"import/named": "error",
77+
"import/export": "error",
78+
"import/no-default-export": "allow",
79+
"import/unambiguous": "error",
80+
"import/group-exports": "allow",
81+
82+
// promise
83+
"promise/no-return-wrap": "error",
84+
"promise/param-names": "error",
85+
"promise/prefer-await-to-callbacks": "error",
86+
"promise/prefer-await-to-then": "error",
87+
"promise/prefer-catch": "error",
88+
"promise/no-return-in-finally": "error",
89+
"promise/avoid-new": "error",
90+
91+
// unicorn
92+
"unicorn/error-message": "error",
93+
"unicorn/no-null": "allow",
94+
"unicorn/filename-case": "allow",
95+
"unicorn/prefer-structured-clone": "error",
96+
"unicorn/prefer-logical-operator-over-ternary": "error",
97+
"unicorn/prefer-number-properties": "error",
98+
"unicorn/prefer-array-some": "error",
99+
"unicorn/prefer-string-slice": "error",
100+
// "unicorn/no-null": "error",
101+
"unicorn/throw-new-error": "error",
102+
"unicorn/catch-error-name": "allow",
103+
"unicorn/prefer-spread": "allow",
104+
"unicorn/numeric-separators-style": "error",
105+
"unicorn/prefer-string-raw": "error",
106+
"unicorn/text-encoding-identifier-case": "error",
107+
"unicorn/no-array-for-each": "error",
108+
"unicorn/explicit-length-check": "error",
109+
"unicorn/no-lonely-if": "error",
110+
"unicorn/no-useless-undefined": "allow",
111+
"unicorn/prefer-date-now": "error",
112+
"unicorn/no-static-only-class": "allow",
113+
"unicorn/no-typeof-undefined": "error",
114+
"unicorn/prefer-negative-index": "error",
115+
"unicorn/no-anonymous-default-export": "allow",
116+
117+
// oxc
118+
"oxc/no-map-spread": "error",
119+
"oxc/no-rest-spread-properties": "allow",
120+
"oxc/no-optional-chaining": "allow",
121+
"oxc/no-async-await": "allow",
122+
123+
// typescript
124+
"typescript/explicit-function-return-type": "allow",
125+
"typescript/consistent-type-imports": "error",
126+
"typescript/consistent-type-definitions": "error",
127+
"typescript/consistent-indexed-object-style": "allow",
128+
"typescript/no-inferrable-types": "error",
129+
"typescript/array-type": "error",
130+
"typescript/no-non-null-assertion": "error",
131+
"typescript/no-explicit-any": "error",
132+
"typescript/no-import-type-side-effects": "error",
133+
"typescript/no-dynamic-delete": "error",
134+
"typescript/prefer-ts-expect-error": "error",
135+
"typescript/ban-ts-comment": "error",
136+
"typescript/prefer-enum-initializers": "error",
137+
138+
// jsdoc
139+
"jsdoc/require-returns": "allow",
140+
"jsdoc/require-param": "allow"
141+
},
142+
"ignorePatterns": ["index.d.ts", "test/fixtures/**", "__snapshots__"]
143+
}

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHANGELOG.md
2+
__snapshots__

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"arrowParens": "avoid"
6+
}

0 commit comments

Comments
 (0)