Skip to content

Commit da27001

Browse files
chore: align ESLint rules with the monorepo's portable ruleset
Port the portable, non-custom, non-React rules from factory-mono-alpha's shared @factory/eslint-config into our ESLint 9 flat config, so the public SDK enforces the same standards as the internal source of truth. Added rules: no-empty-object-type (error), no-require-imports, no-barrel-files, import/no-default-export, import/named, import/no-extraneous-dependencies, import/extensions, eslint-comments/no-unused-disable, no-void, default-case, no-constant-condition, no-param-reassign, no-promise-executor-return, prefer-promise-reject-errors, prefer-arrow-callback, no-restricted-syntax (incl. ExportAllDeclaration ban), and vitest/expect-expect + valid-expect for tests. Excluded the monorepo's factory/* custom-plugin rules (not installable from npm) and React/Next rules (no React here). Refactored to comply: deleted the unused src/protocol/index.ts export* barrel and converted src/index.ts to explicit named re-exports. Public-API barrels are exempted from no-barrel-files (matching the monorepo's index.ts exemption). Fixed all resulting violations. New devDeps: eslint-plugin-no-barrel-files, eslint-plugin-eslint-comments, @vitest/eslint-plugin. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 60621c2 commit da27001

28 files changed

Lines changed: 1339 additions & 108 deletions

eslint.config.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import eslint from '@eslint/js';
2+
import vitest from '@vitest/eslint-plugin';
3+
import eslintComments from 'eslint-plugin-eslint-comments';
24
import importPlugin from 'eslint-plugin-import';
5+
import noBarrelFiles from 'eslint-plugin-no-barrel-files';
36
import unusedImports from 'eslint-plugin-unused-imports';
47
import tseslint from 'typescript-eslint';
58

@@ -11,6 +14,8 @@ export default tseslint.config(
1114
plugins: {
1215
'unused-imports': unusedImports,
1316
import: importPlugin,
17+
'no-barrel-files': noBarrelFiles,
18+
'eslint-comments': eslintComments,
1419
},
1520
languageOptions: {
1621
parserOptions: {
@@ -36,7 +41,43 @@ export default tseslint.config(
3641
],
3742
'@typescript-eslint/no-floating-promises': 'error',
3843
'@typescript-eslint/explicit-function-return-type': 'off',
39-
'@typescript-eslint/no-empty-object-type': 'off',
44+
'@typescript-eslint/no-empty-object-type': 'error',
45+
'@typescript-eslint/no-require-imports': 'error',
46+
'no-barrel-files/no-barrel-files': 'error',
47+
'import/no-default-export': 'error',
48+
'import/named': 'error',
49+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
50+
'eslint-comments/no-unused-disable': 'error',
51+
'no-void': ['error', { allowAsStatement: true }],
52+
'default-case': 'error',
53+
'no-constant-condition': ['error', { checkLoops: false }],
54+
'no-param-reassign': ['error', { props: false }],
55+
'no-promise-executor-return': 'error',
56+
'prefer-promise-reject-errors': 'error',
57+
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
58+
'no-restricted-syntax': [
59+
'error',
60+
{
61+
selector: 'ForInStatement',
62+
message:
63+
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
64+
},
65+
{
66+
selector: 'LabeledStatement',
67+
message:
68+
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
69+
},
70+
{
71+
selector: 'WithStatement',
72+
message:
73+
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
74+
},
75+
{
76+
selector: 'ExportAllDeclaration',
77+
message:
78+
"Export all doesn't work well if imported in ESM due to how they are transpiled, and they can also lead to unexpected exposure of internal methods.",
79+
},
80+
],
4081
'unused-imports/no-unused-imports': 'error',
4182
'import/order': [
4283
'error',
@@ -61,15 +102,24 @@ export default tseslint.config(
61102
},
62103
],
63104
'import/no-cycle': 'error',
105+
'import/extensions': ['error', 'ignorePackages', { js: 'always', ts: 'never' }],
64106
'no-console': 'error',
65107
},
66108
},
67109
{
68110
files: ['tests/**/*.ts'],
111+
plugins: {
112+
vitest,
113+
},
69114
rules: {
70115
'@typescript-eslint/no-explicit-any': 'off',
71116
'@typescript-eslint/consistent-type-assertions': 'off',
72117
'no-console': 'off',
118+
'vitest/expect-expect': [
119+
'error',
120+
{ assertFunctionNames: ['expect', 'expect*', 'assert*'] },
121+
],
122+
'vitest/valid-expect': ['error', { maxArgs: 2 }],
73123
},
74124
},
75125
{
@@ -79,6 +129,18 @@ export default tseslint.config(
79129
'no-console': 'off',
80130
},
81131
},
132+
{
133+
// Dedicated public-API barrels: their sole purpose is re-exporting the
134+
// package surface, so the no-barrel-files rule does not apply.
135+
files: [
136+
'src/index.ts',
137+
'src/schemas/index.ts',
138+
'src/daemon/index.ts',
139+
],
140+
rules: {
141+
'no-barrel-files/no-barrel-files': 'off',
142+
},
143+
},
82144
{
83145
ignores: ['dist/', 'node_modules/', '*.config.*'],
84146
}

examples/hook-execution.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ async function main(): Promise<void> {
5555
case DroidMessageType.Result:
5656
console.log('\n\n--- Turn complete ---');
5757
break;
58+
59+
default:
60+
break;
5861
}
5962
}
6063
} finally {

examples/session-stream.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ async function main(): Promise<void> {
4444
);
4545
}
4646
break;
47+
48+
default:
49+
break;
4750
}
4851
}
4952
} finally {

0 commit comments

Comments
 (0)