Skip to content

Commit 742dbee

Browse files
committed
style: add ESLint and Prettier configuration files
- Add .eslintrc.js with TypeScript support and comprehensive linting rules - Configure ESLint to enforce code style including indentation, quotes, and semicolons - Add .prettierrc with formatting standards for consistent code formatting - Set print width to 120 characters and use 2-space indentation - Establish consistent code style across the TypeScript project to improve code quality and maintainability
1 parent 61e0c36 commit 742dbee

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

.eslintrc.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
plugins: ['@typescript-eslint'],
4+
extends: [
5+
'eslint:recommended',
6+
'@typescript-eslint/recommended',
7+
],
8+
parserOptions: {
9+
ecmaVersion: 2020,
10+
sourceType: 'module',
11+
},
12+
env: {
13+
node: true,
14+
es6: true,
15+
},
16+
rules: {
17+
// TypeScript specific rules
18+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
19+
'@typescript-eslint/no-explicit-any': 'warn',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-non-null-assertion': 'warn',
23+
24+
// General rules
25+
'no-console': 'off', // Allow console in examples and tests
26+
'prefer-const': 'error',
27+
'no-var': 'error',
28+
'object-shorthand': 'error',
29+
'prefer-template': 'error',
30+
31+
// Code style
32+
'indent': ['error', 2],
33+
'quotes': ['error', 'single'],
34+
'semi': ['error', 'always'],
35+
'comma-dangle': ['error', 'never'],
36+
'no-trailing-spaces': 'error',
37+
'eol-last': 'error',
38+
},
39+
ignorePatterns: [
40+
'dist/',
41+
'build/',
42+
'node_modules/',
43+
'deps/',
44+
'Release/',
45+
'coverage/',
46+
'*.js' // Ignore JS files in root (like this config file)
47+
],
48+
};

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "none",
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"bracketSpacing": true,
9+
"arrowParens": "avoid",
10+
"endOfLine": "lf"
11+
}

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"test:dev": "npm run build:dev && node --expose-gc --max-old-space-size=4096 vitest",
3939
"test:coverage": "npm run build:test && npm run vitest:coverage",
4040
"test:watch": "npm run build:ts && vitest --watch",
41-
"clean:ts": "tsc -b --clean"
41+
"clean:ts": "tsc -b --clean",
42+
"lint": "eslint src/**/*.ts --fix",
43+
"format": "prettier --write src/**/*.ts example/**/*.ts",
44+
"validate": "npm run lint && npm run test:dryrun"
4245
},
4346
"dependencies": {
4447
"bindings": "^1.5.0"
@@ -50,6 +53,11 @@
5053
"cmake-js": "^7.4.0",
5154
"node-addon-api": "^8.5.0",
5255
"typescript": "^5.7.2",
53-
"vitest": "^4.0.18"
56+
"vitest": "^4.0.18",
57+
"eslint": "^9.0.0",
58+
"@typescript-eslint/eslint-plugin": "^8.0.0",
59+
"@typescript-eslint/parser": "^8.0.0",
60+
"prettier": "^3.0.0",
61+
"ts-node": "^10.9.0"
5462
}
5563
}

0 commit comments

Comments
 (0)