Skip to content

Commit a063aeb

Browse files
committed
feat: add ESLint with TypeScript support
1 parent 0814aa5 commit a063aeb

File tree

10 files changed

+881
-149
lines changed

10 files changed

+881
-149
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pnpm lint
12
pnpm test

eslint.config.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
4+
export default tseslint.config(
5+
{
6+
ignores: ['dist/**', 'node_modules/**', 'coverage/**'],
7+
},
8+
eslint.configs.recommended,
9+
...tseslint.configs.strictTypeChecked,
10+
...tseslint.configs.stylisticTypeChecked,
11+
{
12+
files: ['src/**/*.ts'],
13+
languageOptions: {
14+
parserOptions: {
15+
projectService: true,
16+
tsconfigRootDir: import.meta.dirname,
17+
},
18+
},
19+
rules: {
20+
// Style rules matching existing code
21+
'indent': ['error', 2],
22+
'quotes': ['error', 'single', { avoidEscape: true }],
23+
'semi': ['error', 'always'],
24+
25+
// TypeScript-specific adjustments
26+
'@typescript-eslint/no-unused-vars': ['error', {
27+
argsIgnorePattern: '^_',
28+
varsIgnorePattern: '^_',
29+
}],
30+
},
31+
},
32+
{
33+
// Test files are CommonJS - disable TypeScript checking
34+
files: ['test/**/*.cjs'],
35+
extends: [tseslint.configs.disableTypeChecked],
36+
languageOptions: {
37+
sourceType: 'commonjs',
38+
globals: {
39+
require: 'readonly',
40+
module: 'readonly',
41+
__dirname: 'readonly',
42+
__filename: 'readonly',
43+
process: 'readonly',
44+
console: 'readonly',
45+
},
46+
},
47+
rules: {
48+
'indent': ['error', 2],
49+
'quotes': ['error', 'single', { avoidEscape: true }],
50+
'semi': ['error', 'always'],
51+
'no-unused-vars': ['error', {
52+
argsIgnorePattern: '^_',
53+
varsIgnorePattern: '^_',
54+
}],
55+
// Disable TypeScript rules for JS files
56+
'@typescript-eslint/no-require-imports': 'off',
57+
},
58+
}
59+
);

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"test": "pnpm build && c8 node --test test/*.test.cjs",
3131
"coverage": "c8 report --reporter=text-lcov",
3232
"typecheck": "tsc --noEmit",
33+
"lint": "eslint src/ test/",
34+
"lint:fix": "eslint src/ test/ --fix",
3335
"prepublishOnly": "pnpm build",
3436
"prepare": "husky"
3537
},
@@ -50,13 +52,16 @@
5052
"devDependencies": {
5153
"@commitlint/cli": "^20.2.0",
5254
"@commitlint/config-conventional": "^20.2.0",
55+
"@eslint/js": "^9.39.1",
5356
"@types/node": "^25.0.0",
5457
"c8": "^10.1.3",
58+
"eslint": "^9.39.1",
5559
"husky": "^9.1.7",
5660
"mockdate": "^3.0.5",
5761
"safe-buffer": "^5.2.1",
5862
"seedrandom": "^3.0.5",
5963
"tsdown": "^0.17.2",
60-
"typescript": "^5.9.3"
64+
"typescript": "^5.9.3",
65+
"typescript-eslint": "^8.49.0"
6166
}
6267
}

0 commit comments

Comments
 (0)