Skip to content

Commit 91f813e

Browse files
deshartmanclaude
andcommitted
chore: add ESLint configuration to catch code quality issues
Adds comprehensive ESLint setup to proactively catch common code quality issues flagged by GitHub Copilot during PR reviews, including: - Implicit any types and unsafe type operations - Floating promises and misused promises - Unused variables - Jest best practices The configuration is tuned for this TypeScript monorepo and includes lenient rules for test files where stricter typing is less critical. This change helps prevent issues like those caught in twilio-labs#546 where Copilot identified type safety and promise handling concerns. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4c1b5e2 commit 91f813e

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

.eslintrc.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
es6: true,
6+
},
7+
plugins: ['@typescript-eslint', 'jest'],
8+
extends: ['eslint:recommended', 'plugin:jest/recommended'],
9+
rules: {
10+
// Best practices
11+
'no-console': 'off', // CLI tool, console is expected
12+
'prefer-const': 'error',
13+
'no-var': 'error',
14+
15+
// Jest best practices
16+
'jest/expect-expect': 'warn',
17+
'jest/no-disabled-tests': 'warn',
18+
'jest/no-focused-tests': 'error',
19+
},
20+
overrides: [
21+
{
22+
// TypeScript files with type checking
23+
files: ['**/*.ts', '**/*.tsx'],
24+
parser: '@typescript-eslint/parser',
25+
parserOptions: {
26+
ecmaVersion: 2018,
27+
sourceType: 'module',
28+
project: ['./tsconfig.base.json', './packages/*/tsconfig.json'],
29+
tsconfigRootDir: __dirname,
30+
},
31+
extends: [
32+
'eslint:recommended',
33+
'plugin:@typescript-eslint/recommended',
34+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
35+
'plugin:jest/recommended',
36+
],
37+
rules: {
38+
// Catch implicit any (would catch Issue #1)
39+
'@typescript-eslint/no-explicit-any': 'warn', // Warn, not error (any is sometimes needed)
40+
'@typescript-eslint/no-unsafe-assignment': 'warn',
41+
'@typescript-eslint/no-unsafe-member-access': 'warn',
42+
'@typescript-eslint/no-unsafe-call': 'warn',
43+
44+
// Catch promise issues
45+
'@typescript-eslint/no-floating-promises': 'error',
46+
'@typescript-eslint/no-misused-promises': 'error',
47+
48+
// General code quality
49+
'@typescript-eslint/no-unused-vars': [
50+
'error',
51+
{
52+
argsIgnorePattern: '^_',
53+
varsIgnorePattern: '^_',
54+
},
55+
],
56+
57+
// Best practices
58+
'no-console': 'off',
59+
'prefer-const': 'error',
60+
'no-var': 'error',
61+
62+
// Jest best practices
63+
'jest/expect-expect': 'warn',
64+
'jest/no-disabled-tests': 'warn',
65+
'jest/no-focused-tests': 'error',
66+
},
67+
},
68+
{
69+
// More lenient rules for test files
70+
files: ['**/__tests__/**', '**/*.test.ts', '**/*.test.js'],
71+
env: {
72+
jest: true,
73+
},
74+
rules: {
75+
'@typescript-eslint/no-explicit-any': 'off',
76+
'@typescript-eslint/no-unsafe-assignment': 'off',
77+
'@typescript-eslint/no-unsafe-member-access': 'off',
78+
'@typescript-eslint/no-unsafe-call': 'off',
79+
},
80+
},
81+
],
82+
ignorePatterns: [
83+
'node_modules/',
84+
'dist/',
85+
'build/',
86+
'coverage/',
87+
'*.config.js',
88+
'.eslintrc.js',
89+
'jest.config.js',
90+
'jest.config.base.js',
91+
'.changeset/',
92+
],
93+
};

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"docs": "npm run docs --workspaces --if-present",
2020
"prepare": "husky install",
2121
"pre-commit": "lint-staged",
22-
"reset": "npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules"
22+
"reset": "npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules",
23+
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",
24+
"lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix"
2325
},
2426
"devDependencies": {
2527
"@changesets/changelog-github": "^0.4.8",
@@ -28,11 +30,15 @@
2830
"@commitlint/config-conventional": "^19.1.0",
2931
"@twilio/test-dep": "npm:twilio@4.22.0",
3032
"@types/jest": "^29.2.4",
33+
"@typescript-eslint/eslint-plugin": "^6.21.0",
34+
"@typescript-eslint/parser": "^6.21.0",
3135
"all-contributors-cli": "^6.1.2",
3236
"commitizen": "^4.2.4",
3337
"commitlint-plugin-workspace-scopes": "^1.1.0",
3438
"conventional-changelog-cli": "^2.1.0",
3539
"cz-conventional-changelog": "^2.1.0",
40+
"eslint": "^8.57.1",
41+
"eslint-plugin-jest": "^27.9.0",
3642
"husky": "^8.0.2",
3743
"jest": "^29.7.0",
3844
"jest-express": "^1.10.1",
@@ -47,6 +53,7 @@
4753
},
4854
"lint-staged": {
4955
"*.{js,jsx,ts,tsx}": [
56+
"eslint --fix",
5057
"prettier --write",
5158
"git add"
5259
]

0 commit comments

Comments
 (0)