Skip to content

Commit 0a6f118

Browse files
refactor: extract shared TypeScript rules in ESLint config
- Extract duplicated TypeScript rules into sharedTypeScriptRules constant - Replace inline rule objects in both base and test configs with shared constant - Maintains all original rules and configurations unchanged - Improves maintainability by eliminating code duplication - Follows DRY principle for better code organization
1 parent 646e976 commit 0a6f118

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

clients/typescript/eslint.config.js

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ import typescript from '@typescript-eslint/eslint-plugin';
33
import typescriptParser from '@typescript-eslint/parser';
44
import globals from 'globals';
55

6+
// Shared TypeScript rules used by both base and test configurations
7+
const sharedTypeScriptRules = {
8+
...typescript.configs.recommended.rules,
9+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
10+
'@typescript-eslint/explicit-function-return-type': ['error', {
11+
allowExpressions: true,
12+
allowTypedFunctionExpressions: true
13+
}],
14+
// Enforce explicit return types for exported/public APIs
15+
'@typescript-eslint/explicit-module-boundary-types': 'error',
16+
'@typescript-eslint/no-explicit-any': 'error',
17+
'@typescript-eslint/no-inferrable-types': 'off',
18+
'@typescript-eslint/strict-boolean-expressions': ['error', {
19+
allowNullableObject: true
20+
}],
21+
'prefer-const': 'error',
22+
'no-var': 'error',
23+
'no-unused-vars': 'off', // Turn off base rule as it can conflict with @typescript-eslint/no-unused-vars
24+
};
25+
626
export default [
727
js.configs.recommended,
828
{
@@ -29,24 +49,7 @@ export default [
2949
plugins: {
3050
'@typescript-eslint': typescript,
3151
},
32-
rules: {
33-
...typescript.configs.recommended.rules,
34-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
35-
'@typescript-eslint/explicit-function-return-type': ['error', {
36-
allowExpressions: true,
37-
allowTypedFunctionExpressions: true
38-
}],
39-
// Enforce explicit return types for exported/public APIs
40-
'@typescript-eslint/explicit-module-boundary-types': 'error',
41-
'@typescript-eslint/no-explicit-any': 'error',
42-
'@typescript-eslint/no-inferrable-types': 'off',
43-
'@typescript-eslint/strict-boolean-expressions': ['error', {
44-
allowNullableObject: true
45-
}],
46-
'prefer-const': 'error',
47-
'no-var': 'error',
48-
'no-unused-vars': 'off', // Turn off base rule as it can conflict with @typescript-eslint/no-unused-vars
49-
},
52+
rules: sharedTypeScriptRules,
5053
},
5154
{
5255
files: ['tests/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
@@ -75,23 +78,7 @@ export default [
7578
plugins: {
7679
'@typescript-eslint': typescript,
7780
},
78-
rules: {
79-
...typescript.configs.recommended.rules,
80-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
81-
'@typescript-eslint/explicit-function-return-type': ['error', {
82-
allowExpressions: true,
83-
allowTypedFunctionExpressions: true
84-
}],
85-
'@typescript-eslint/explicit-module-boundary-types': 'error',
86-
'@typescript-eslint/no-explicit-any': 'error',
87-
'@typescript-eslint/no-inferrable-types': 'off',
88-
'@typescript-eslint/strict-boolean-expressions': ['error', {
89-
allowNullableObject: true
90-
}],
91-
'prefer-const': 'error',
92-
'no-var': 'error',
93-
'no-unused-vars': 'off',
94-
},
81+
rules: sharedTypeScriptRules,
9582
},
9683
{
9784
ignores: [

0 commit comments

Comments
 (0)