@talkpilot/eslint-config 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,9 +8,9 @@ npm install -D @talkpilot/eslint-config eslint@10 typescript
8
8
 
9
9
  ```javascript
10
10
  // eslint.config.mjs
11
- import talkpilot from '@talkpilot/eslint-config';
11
+ import { backend } from '@talkpilot/eslint-config'; // React apps: { frontend }
12
12
 
13
- export default [...talkpilot /* , repo rules */];
13
+ export default [...backend /* , repo rules */];
14
14
  ```
15
15
 
16
16
  ```json
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import type { Linter } from 'eslint';
2
- import { talkpilotPlugin } from './rules/index.js';
1
+ import { BACKEND_CONFIG, FRONTEND_CONFIG } from './lib/presets.constants.js';
3
2
  /**
4
- * The company-wide ESLint config. Repos spread it first in their eslint.config.mjs and add repo rules after:
5
- * export default [...talkpilot, { rules: { ... } }];
6
- * - Lints *.ts / *.tsx only; tests, dist, and *.d.ts are ignored (IGNORED_PATHS).
7
- * - `noInlineConfig` turns off eslint-disable comments: exceptions go in the repo config instead.
8
- * - *.data.ts files get the bigger line limit.
3
+ * Company-wide ESLint rules, one set per type of code. Repos spread one set first and add repo rules after:
4
+ * import { backend } from '@talkpilot/eslint-config'; // Node services and packages
5
+ * import { frontend } from '@talkpilot/eslint-config'; // React apps
6
+ * export default [...backend, { files: ['**\/*.ts', '**\/*.tsx'], rules: { ... } }];
7
+ * The default export is the backend set (kept for repos set up with 1.0.x).
9
8
  */
10
- declare const _default: Linter.Config[];
11
- export default _default;
12
- export { talkpilotPlugin as plugin };
13
- export { buildFileNamingRules } from './lib/fileNaming.utils.js';
9
+ export default BACKEND_CONFIG;
10
+ export { BACKEND_CONFIG as backend, FRONTEND_CONFIG as frontend };
11
+ export { talkpilotPlugin as plugin } from './rules/index.js';
12
+ export { buildFileNamingRules, buildFrontendFileNamingRules } from './lib/fileNaming.utils.js';
14
13
  export { EXEMPT_FILE_NAMES, LIMITS, ROLE_SUFFIXES } from './lib/defaults.constants.js';
14
+ export { NO_MONGODB_IMPORT } from './lib/ruleSets.constants.js';
package/dist/index.js CHANGED
@@ -1,43 +1,16 @@
1
- import checkFile from 'eslint-plugin-check-file';
2
- import tseslint from 'typescript-eslint';
3
- import { IGNORED_PATHS, LINTED_FILES } from './lib/defaults.constants.js';
4
- import { DATA_FILE_RULES, LOGGING_RULES, NAMING_CONVENTION, SIZE_RULES, STRUCTURE_RULES, TYPESCRIPT_RULES, } from './lib/ruleSets.constants.js';
5
- import { buildFileNamingRules } from './lib/fileNaming.utils.js';
1
+ import { BACKEND_CONFIG, FRONTEND_CONFIG } from './lib/presets.constants.js';
6
2
  import { assertSupportedEslintVersion } from './lib/versionCheck.utils.js';
7
- import { talkpilotPlugin } from './rules/index.js';
8
3
  assertSupportedEslintVersion();
9
4
  /**
10
- * The company-wide ESLint config. Repos spread it first in their eslint.config.mjs and add repo rules after:
11
- * export default [...talkpilot, { rules: { ... } }];
12
- * - Lints *.ts / *.tsx only; tests, dist, and *.d.ts are ignored (IGNORED_PATHS).
13
- * - `noInlineConfig` turns off eslint-disable comments: exceptions go in the repo config instead.
14
- * - *.data.ts files get the bigger line limit.
5
+ * Company-wide ESLint rules, one set per type of code. Repos spread one set first and add repo rules after:
6
+ * import { backend } from '@talkpilot/eslint-config'; // Node services and packages
7
+ * import { frontend } from '@talkpilot/eslint-config'; // React apps
8
+ * export default [...backend, { files: ['**\/*.ts', '**\/*.tsx'], rules: { ... } }];
9
+ * The default export is the backend set (kept for repos set up with 1.0.x).
15
10
  */
16
- export default [
17
- { ignores: IGNORED_PATHS },
18
- {
19
- files: LINTED_FILES,
20
- languageOptions: {
21
- parser: tseslint.parser,
22
- parserOptions: { projectService: true, tsconfigRootDir: process.cwd() },
23
- },
24
- linterOptions: { noInlineConfig: true },
25
- plugins: {
26
- '@typescript-eslint': tseslint.plugin,
27
- 'check-file': checkFile,
28
- talkpilot: talkpilotPlugin,
29
- },
30
- rules: {
31
- ...SIZE_RULES,
32
- ...TYPESCRIPT_RULES,
33
- '@typescript-eslint/naming-convention': ['error', ...NAMING_CONVENTION],
34
- ...STRUCTURE_RULES,
35
- ...buildFileNamingRules(),
36
- ...LOGGING_RULES,
37
- },
38
- },
39
- { files: ['**/*.data.ts'], rules: DATA_FILE_RULES },
40
- ];
41
- export { talkpilotPlugin as plugin };
42
- export { buildFileNamingRules } from './lib/fileNaming.utils.js';
11
+ export default BACKEND_CONFIG;
12
+ export { BACKEND_CONFIG as backend, FRONTEND_CONFIG as frontend };
13
+ export { talkpilotPlugin as plugin } from './rules/index.js';
14
+ export { buildFileNamingRules, buildFrontendFileNamingRules } from './lib/fileNaming.utils.js';
43
15
  export { EXEMPT_FILE_NAMES, LIMITS, ROLE_SUFFIXES } from './lib/defaults.constants.js';
16
+ export { NO_MONGODB_IMPORT } from './lib/ruleSets.constants.js';
@@ -1,3 +1,3 @@
1
1
  export const LINTABLE_FILE = /\.(ts|tsx)$/;
2
- export const NEW_JS_FILE = /^src\/.*\.(js|jsx)$/;
2
+ export const NEW_JS_FILE = /(^|\/)src\/.*\.(js|jsx)$/;
3
3
  export const DEFAULT_BRANCHES = ['origin/main', 'main'];
@@ -4,6 +4,11 @@ export declare const LINTED_FILES: string[];
4
4
  export declare const IGNORED_PATHS: string[];
5
5
  export declare const ROLE_SUFFIXES: string[];
6
6
  export declare const EXEMPT_FILE_NAMES: string[];
7
+ export declare const FRONTEND_EXEMPT_FILE_NAMES: string[];
8
+ export declare const TSX_FILES: string[];
9
+ export declare const FRONTEND_IGNORED_PATHS: string[];
10
+ export declare const CAMEL_CASE_GLOB = "+([a-z])*([a-zA-Z0-9])";
11
+ export declare const PASCAL_CASE_GLOB = "+([A-Z])*([a-zA-Z0-9])";
7
12
  export declare const IGNORED_FOLDER_NAMES: string[];
8
13
  export declare const LIMITS: LintLimits;
9
14
  export declare const BOOLEAN_PREFIXES: string[];
@@ -7,8 +7,11 @@ export const IGNORED_PATHS = [
7
7
  '**/coverage/**',
8
8
  '**/*.d.ts',
9
9
  '**/*.spec.ts',
10
+ '**/*.spec.tsx',
10
11
  '**/*.test.ts',
12
+ '**/*.test.tsx',
11
13
  '**/__tests__/**',
14
+ '**/__mocks__/**',
12
15
  ];
13
16
  export const ROLE_SUFFIXES = [
14
17
  'types',
@@ -26,6 +29,11 @@ export const ROLE_SUFFIXES = [
26
29
  'resolvers',
27
30
  ];
28
31
  export const EXEMPT_FILE_NAMES = ['index.ts', 'app.ts'];
32
+ export const FRONTEND_EXEMPT_FILE_NAMES = ['index.ts', 'app.ts', 'use*.ts'];
33
+ export const TSX_FILES = ['**/*.tsx'];
34
+ export const FRONTEND_IGNORED_PATHS = ['**/*.stories.ts', '**/*.stories.tsx'];
35
+ export const CAMEL_CASE_GLOB = '+([a-z])*([a-zA-Z0-9])';
36
+ export const PASCAL_CASE_GLOB = '+([A-Z])*([a-zA-Z0-9])';
29
37
  export const IGNORED_FOLDER_NAMES = ['__tests__', '__mocks__'];
30
38
  export const LIMITS = {
31
39
  FUNCTION_LINES: 40,
@@ -35,6 +43,7 @@ export const LIMITS = {
35
43
  FUNCTION_PARAMS: 5,
36
44
  COMPLEXITY: 5,
37
45
  INLINE_DATA_LINES: 50,
46
+ TSX_FILE_LINES: 100,
38
47
  };
39
48
  export const BOOLEAN_PREFIXES = ['is', 'has', 'should', 'can'];
40
49
  export const TYPE_FILE_SUFFIXES = ['.types.ts', '.d.ts'];
@@ -1,18 +1,31 @@
1
1
  import type { FileNamingOptions } from './lint.types.js';
2
2
  /**
3
- * Builds the file/folder naming rules (from eslint-plugin-check-file):
4
- * - files: camelCase name parts and a role suffix, e.g. `phoneNumbers.routes.ts`
3
+ * Backend file/folder naming rules (eslint-plugin-check-file):
4
+ * - `.ts` files: camelCase name parts and a role suffix, e.g. `phoneNumbers.routes.ts`
5
5
  * - folders: camelCase
6
6
  * Repos that use extra roles call it again with their own list, e.g.
7
- * { rules: buildFileNamingRules({ roles: [...ROLE_SUFFIXES, 'getters'] }) }
7
+ * { files: ['**\/*.ts', '**\/*.tsx'], rules: buildFileNamingRules({ roles: [...ROLE_SUFFIXES, 'getters'] }) }
8
8
  */
9
9
  export declare function buildFileNamingRules(options?: FileNamingOptions): {
10
- 'check-file/filename-naming-convention': (string | {
11
- [x: string]: string;
10
+ 'check-file/filename-naming-convention': (string | Record<string, string>)[];
11
+ 'check-file/folder-naming-convention': (string | {
12
+ '**/': string;
13
+ ignoreWords?: undefined;
12
14
  errorMessage?: undefined;
13
15
  } | {
16
+ ignoreWords: string[];
14
17
  errorMessage: string;
18
+ '**/'?: undefined;
15
19
  })[];
20
+ };
21
+ /**
22
+ * Frontend (React) file/folder naming rules:
23
+ * - `.ts` files: same as backend; React hook files (`useX.ts`) are exempt
24
+ * - `.tsx` files: PascalCase or camelCase parts, e.g. `CallCard.tsx`, `Login.screen.tsx`, `useAuth.tsx`
25
+ * - folders: camelCase or PascalCase (component folders)
26
+ */
27
+ export declare function buildFrontendFileNamingRules(options?: FileNamingOptions): {
28
+ 'check-file/filename-naming-convention': (string | Record<string, string>)[];
16
29
  'check-file/folder-naming-convention': (string | {
17
30
  '**/': string;
18
31
  ignoreWords?: undefined;
@@ -1,31 +1,54 @@
1
- import { EXEMPT_FILE_NAMES, IGNORED_FOLDER_NAMES, ROLE_SUFFIXES } from './defaults.constants.js';
2
- /**
3
- * Builds the file/folder naming rules (from eslint-plugin-check-file):
4
- * - files: camelCase name parts and a role suffix, e.g. `phoneNumbers.routes.ts`
5
- * - folders: camelCase
6
- * Repos that use extra roles call it again with their own list, e.g.
7
- * { rules: buildFileNamingRules({ roles: [...ROLE_SUFFIXES, 'getters'] }) }
8
- */
9
- export function buildFileNamingRules(options = {}) {
10
- const roles = options.roles ?? ROLE_SUFFIXES;
11
- const exemptFiles = options.exemptFiles ?? EXEMPT_FILE_NAMES;
12
- const exemptNames = exemptFiles.map((file) => file.replace(/\.ts$/, '')).join('|');
13
- const namePart = '+([a-z])*([a-zA-Z0-9])';
1
+ import { CAMEL_CASE_GLOB, EXEMPT_FILE_NAMES, FRONTEND_EXEMPT_FILE_NAMES, IGNORED_FOLDER_NAMES, PASCAL_CASE_GLOB, ROLE_SUFFIXES, } from './defaults.constants.js';
2
+ /** Builds the check-file rules from the allowed `.ts` / `.tsx` name patterns and folder pattern. */
3
+ function buildCheckFileRules(filePatterns, folderPattern, options, fileMessage) {
14
4
  return {
15
5
  'check-file/filename-naming-convention': [
16
6
  'error',
17
- { [`**/!(${exemptNames}).ts`]: `${namePart}*(.${namePart}).@(${roles.join('|')})` },
7
+ filePatterns,
18
8
  {
19
- errorMessage: `File name '{{ target }}' must be camelCase plus a role suffix: <name>.<role>.ts (roles: ${roles.join(', ')}).`,
9
+ errorMessage: fileMessage,
20
10
  },
21
11
  ],
22
12
  'check-file/folder-naming-convention': [
23
13
  'error',
24
- { '**/': 'CAMEL_CASE' },
14
+ { '**/': folderPattern },
25
15
  {
26
16
  ignoreWords: options.ignoredFolders ?? IGNORED_FOLDER_NAMES,
27
- errorMessage: "Folder '{{ target }}' must be camelCase.",
17
+ errorMessage: `Folder '{{ target }}' must be ${folderPattern === 'CAMEL_CASE' ? 'camelCase' : 'camelCase or PascalCase'}.`,
28
18
  },
29
19
  ],
30
20
  };
31
21
  }
22
+ /** Pattern for `.ts` files: camelCase name parts and a role suffix, e.g. `phoneNumbers.routes`. */
23
+ function buildTsFilePattern(options, defaultExempt) {
24
+ const roles = options.roles ?? ROLE_SUFFIXES;
25
+ const exemptFiles = options.exemptFiles ?? defaultExempt;
26
+ const exemptNames = exemptFiles.map((file) => file.replace(/\.ts$/, '')).join('|');
27
+ const namePattern = `${CAMEL_CASE_GLOB}*(.${CAMEL_CASE_GLOB}).@(${roles.join('|')})`;
28
+ return { roles, patterns: { [`**/!(${exemptNames}).ts`]: namePattern } };
29
+ }
30
+ /**
31
+ * Backend file/folder naming rules (eslint-plugin-check-file):
32
+ * - `.ts` files: camelCase name parts and a role suffix, e.g. `phoneNumbers.routes.ts`
33
+ * - folders: camelCase
34
+ * Repos that use extra roles call it again with their own list, e.g.
35
+ * { files: ['**\/*.ts', '**\/*.tsx'], rules: buildFileNamingRules({ roles: [...ROLE_SUFFIXES, 'getters'] }) }
36
+ */
37
+ export function buildFileNamingRules(options = {}) {
38
+ const { roles, patterns } = buildTsFilePattern(options, EXEMPT_FILE_NAMES);
39
+ const message = `File name '{{ target }}' must be camelCase plus a role suffix: <name>.<role>.ts (roles: ${roles.join(', ')}).`;
40
+ return buildCheckFileRules(patterns, 'CAMEL_CASE', options, message);
41
+ }
42
+ /**
43
+ * Frontend (React) file/folder naming rules:
44
+ * - `.ts` files: same as backend; React hook files (`useX.ts`) are exempt
45
+ * - `.tsx` files: PascalCase or camelCase parts, e.g. `CallCard.tsx`, `Login.screen.tsx`, `useAuth.tsx`
46
+ * - folders: camelCase or PascalCase (component folders)
47
+ */
48
+ export function buildFrontendFileNamingRules(options = {}) {
49
+ const { roles, patterns } = buildTsFilePattern(options, FRONTEND_EXEMPT_FILE_NAMES);
50
+ const namePart = `@(${CAMEL_CASE_GLOB}|${PASCAL_CASE_GLOB})`;
51
+ const tsxPatterns = { ...patterns, '**/*.tsx': `${namePart}*(.${namePart})` };
52
+ const message = `File name '{{ target }}' breaks the naming rule. .ts: camelCase + role suffix (<name>.<role>.ts, roles: ${roles.join(', ')}). .tsx: PascalCase or camelCase parts.`;
53
+ return buildCheckFileRules(tsxPatterns, namePart, options, message);
54
+ }
@@ -12,6 +12,7 @@ export type LintLimits = {
12
12
  FUNCTION_PARAMS: number;
13
13
  COMPLEXITY: number;
14
14
  INLINE_DATA_LINES: number;
15
+ TSX_FILE_LINES: number;
15
16
  };
16
17
  export type FileNamingOptions = {
17
18
  roles?: string[];
@@ -0,0 +1,2 @@
1
+ export declare const BACKEND_CONFIG: import("eslint").Linter.Config<import("@eslint/core", { with: { "resolution-mode": "require" } }).RulesConfig>[];
2
+ export declare const FRONTEND_CONFIG: import("eslint").Linter.Config<import("@eslint/core", { with: { "resolution-mode": "require" } }).RulesConfig>[];
@@ -0,0 +1,3 @@
1
+ import { buildBackendConfig, buildFrontendConfig } from './presets.utils.js';
2
+ export const BACKEND_CONFIG = buildBackendConfig();
3
+ export const FRONTEND_CONFIG = buildFrontendConfig();
@@ -0,0 +1,8 @@
1
+ import type { Linter } from 'eslint';
2
+ /** Backend set: base + camelCase naming, camelCase files/folders, no console at all. */
3
+ export declare function buildBackendConfig(): Linter.Config[];
4
+ /**
5
+ * Frontend (React) set: base + PascalCase components, camelCase/PascalCase files and folders,
6
+ * React hooks rules, console allowed, and for .tsx files: one exported component, 100 lines max.
7
+ */
8
+ export declare function buildFrontendConfig(): Linter.Config[];
@@ -0,0 +1,67 @@
1
+ import checkFile from 'eslint-plugin-check-file';
2
+ import reactHooks from 'eslint-plugin-react-hooks';
3
+ import tseslint from 'typescript-eslint';
4
+ import { talkpilotPlugin } from '../rules/index.js';
5
+ import { FRONTEND_IGNORED_PATHS, IGNORED_PATHS, LINTED_FILES, TSX_FILES, } from './defaults.constants.js';
6
+ import { buildFileNamingRules, buildFrontendFileNamingRules } from './fileNaming.utils.js';
7
+ import { BACKEND_RULES, DATA_FILE_RULES, FRONTEND_NAMING_CONVENTION, FRONTEND_RULES, LOGGING_RULES, NAMING_CONVENTION, SIZE_RULES, STRUCTURE_RULES, TSX_RULES, TYPESCRIPT_RULES, } from './ruleSets.constants.js';
8
+ /**
9
+ * Rules shared by all TypeScript code (backend and frontend):
10
+ * - lints *.ts / *.tsx only; tests, dist and *.d.ts are ignored (IGNORED_PATHS)
11
+ * - `noInlineConfig` turns off eslint-disable comments: exceptions go in the repo config instead
12
+ * - *.data.ts files get the bigger line limit
13
+ */
14
+ function buildBaseConfig() {
15
+ return [
16
+ { ignores: IGNORED_PATHS },
17
+ {
18
+ files: LINTED_FILES,
19
+ languageOptions: {
20
+ parser: tseslint.parser,
21
+ parserOptions: { projectService: true, tsconfigRootDir: process.cwd() },
22
+ },
23
+ linterOptions: { noInlineConfig: true },
24
+ plugins: {
25
+ '@typescript-eslint': tseslint.plugin,
26
+ 'check-file': checkFile,
27
+ talkpilot: talkpilotPlugin,
28
+ },
29
+ rules: { ...SIZE_RULES, ...TYPESCRIPT_RULES, ...STRUCTURE_RULES, ...LOGGING_RULES },
30
+ },
31
+ { files: ['**/*.data.ts'], rules: DATA_FILE_RULES },
32
+ ];
33
+ }
34
+ /** Backend set: base + camelCase naming, camelCase files/folders, no console at all. */
35
+ export function buildBackendConfig() {
36
+ return [
37
+ ...buildBaseConfig(),
38
+ {
39
+ files: LINTED_FILES,
40
+ rules: {
41
+ '@typescript-eslint/naming-convention': ['error', ...NAMING_CONVENTION],
42
+ ...buildFileNamingRules(),
43
+ ...BACKEND_RULES,
44
+ },
45
+ },
46
+ ];
47
+ }
48
+ /**
49
+ * Frontend (React) set: base + PascalCase components, camelCase/PascalCase files and folders,
50
+ * React hooks rules, console allowed, and for .tsx files: one exported component, 100 lines max.
51
+ */
52
+ export function buildFrontendConfig() {
53
+ return [
54
+ { ignores: FRONTEND_IGNORED_PATHS },
55
+ ...buildBaseConfig(),
56
+ {
57
+ files: LINTED_FILES,
58
+ plugins: { 'react-hooks': reactHooks },
59
+ rules: {
60
+ '@typescript-eslint/naming-convention': ['error', ...FRONTEND_NAMING_CONVENTION],
61
+ ...buildFrontendFileNamingRules(),
62
+ ...FRONTEND_RULES,
63
+ },
64
+ },
65
+ { files: TSX_FILES, rules: TSX_RULES },
66
+ ];
67
+ }
@@ -0,0 +1,3 @@
1
+ export declare const COMPONENT_WRAPPERS: string[];
2
+ export declare const COMPONENT_TYPE_NAMES: string[];
3
+ export declare const DEFAULT_EXPORT_NAME = "*default*";
@@ -0,0 +1,3 @@
1
+ export const COMPONENT_WRAPPERS = ['memo', 'forwardRef'];
2
+ export const COMPONENT_TYPE_NAMES = ['FC', 'FunctionComponent'];
3
+ export const DEFAULT_EXPORT_NAME = '*default*';
@@ -118,8 +118,100 @@ export declare const STRUCTURE_RULES: {
118
118
  'talkpilot/data-in-data-file': string;
119
119
  };
120
120
  export declare const LOGGING_RULES: {
121
- 'no-console': string;
122
121
  'no-empty': (string | {
123
122
  allowEmptyCatch: boolean;
124
123
  })[];
125
124
  };
125
+ export declare const NO_MONGODB_IMPORT: {
126
+ name: string;
127
+ message: string;
128
+ };
129
+ export declare const BACKEND_RULES: {
130
+ 'no-console': string;
131
+ 'no-restricted-imports': (string | {
132
+ paths: {
133
+ name: string;
134
+ message: string;
135
+ }[];
136
+ })[];
137
+ };
138
+ export declare const FRONTEND_NAMING_CONVENTION: ({
139
+ selector: string;
140
+ format: string[];
141
+ leadingUnderscore: string;
142
+ modifiers?: undefined;
143
+ filter?: undefined;
144
+ types?: undefined;
145
+ prefix?: undefined;
146
+ } | {
147
+ selector: string;
148
+ format: null;
149
+ leadingUnderscore?: undefined;
150
+ modifiers?: undefined;
151
+ filter?: undefined;
152
+ types?: undefined;
153
+ prefix?: undefined;
154
+ } | {
155
+ selector: string;
156
+ modifiers: string[];
157
+ format: null;
158
+ leadingUnderscore?: undefined;
159
+ filter?: undefined;
160
+ types?: undefined;
161
+ prefix?: undefined;
162
+ } | {
163
+ selector: string;
164
+ filter: {
165
+ regex: string;
166
+ match: boolean;
167
+ };
168
+ format: string[];
169
+ leadingUnderscore?: undefined;
170
+ modifiers?: undefined;
171
+ types?: undefined;
172
+ prefix?: undefined;
173
+ } | {
174
+ selector: string;
175
+ modifiers: string[];
176
+ types: string[];
177
+ format: string[];
178
+ leadingUnderscore?: undefined;
179
+ filter?: undefined;
180
+ prefix?: undefined;
181
+ } | {
182
+ selector: string;
183
+ types: string[];
184
+ format: string[];
185
+ prefix: string[];
186
+ leadingUnderscore?: undefined;
187
+ modifiers?: undefined;
188
+ filter?: undefined;
189
+ } | {
190
+ selector: string;
191
+ format: string[];
192
+ leadingUnderscore?: undefined;
193
+ modifiers?: undefined;
194
+ filter?: undefined;
195
+ types?: undefined;
196
+ prefix?: undefined;
197
+ } | {
198
+ selector: string[];
199
+ format: null;
200
+ leadingUnderscore?: undefined;
201
+ modifiers?: undefined;
202
+ filter?: undefined;
203
+ types?: undefined;
204
+ prefix?: undefined;
205
+ })[];
206
+ export declare const FRONTEND_RULES: {
207
+ 'no-console': string;
208
+ 'react-hooks/rules-of-hooks': string;
209
+ };
210
+ export declare const TSX_RULES: {
211
+ 'max-lines': (string | {
212
+ max: number;
213
+ skipBlankLines: boolean;
214
+ skipComments: boolean;
215
+ })[];
216
+ 'talkpilot/one-exported-component': string;
217
+ };
@@ -64,6 +64,30 @@ export const STRUCTURE_RULES = {
64
64
  'talkpilot/data-in-data-file': 'error',
65
65
  };
66
66
  export const LOGGING_RULES = {
67
- 'no-console': 'error',
68
67
  'no-empty': ['error', { allowEmptyCatch: false }],
69
68
  };
69
+ export const NO_MONGODB_IMPORT = {
70
+ name: 'mongodb',
71
+ message: 'Use @talkpilot/core-db instead - all Mongo access goes through core-db.',
72
+ };
73
+ export const BACKEND_RULES = {
74
+ 'no-console': 'error',
75
+ 'no-restricted-imports': ['error', { paths: [NO_MONGODB_IMPORT] }],
76
+ };
77
+ export const FRONTEND_NAMING_CONVENTION = [
78
+ { selector: 'function', format: ['camelCase', 'PascalCase'] },
79
+ {
80
+ selector: 'variable',
81
+ format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
82
+ leadingUnderscore: 'allow',
83
+ },
84
+ ...NAMING_CONVENTION.filter((entry) => !(entry.selector === 'variable' && !('modifiers' in entry) && !('types' in entry) && !('filter' in entry))),
85
+ ];
86
+ export const FRONTEND_RULES = {
87
+ 'no-console': 'off',
88
+ 'react-hooks/rules-of-hooks': 'error',
89
+ };
90
+ export const TSX_RULES = {
91
+ 'max-lines': ['error', { max: LIMITS.TSX_FILE_LINES, skipBlankLines: true, skipComments: true }],
92
+ 'talkpilot/one-exported-component': 'error',
93
+ };
@@ -1,5 +1,6 @@
1
1
  import { constantsInConstantsFile } from './constantsInConstantsFile.rule.js';
2
2
  import { dataInDataFile } from './dataInDataFile.rule.js';
3
+ import { oneExportedComponent } from './oneExportedComponent.rule.js';
3
4
  import { typesInTypesFile } from './typesInTypesFile.rule.js';
4
5
  /** Our custom rules as an ESLint plugin. In configs, they're used with the `talkpilot/` prefix. */
5
6
  export const talkpilotPlugin = {
@@ -8,5 +9,6 @@ export const talkpilotPlugin = {
8
9
  'types-in-types-file': typesInTypesFile,
9
10
  'constants-in-constants-file': constantsInConstantsFile,
10
11
  'data-in-data-file': dataInDataFile,
12
+ 'one-exported-component': oneExportedComponent,
11
13
  },
12
14
  };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * talkpilot/one-exported-component: a .tsx file may export at most one React component.
3
+ * Ported from moked_dashboard's own rule.
4
+ */
5
+ export declare const oneExportedComponent: import("@typescript-eslint/utils/ts-eslint").RuleModule<"one", readonly unknown[], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,106 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import { COMPONENT_WRAPPERS, COMPONENT_TYPE_NAMES, DEFAULT_EXPORT_NAME } from '../lib/react.constants.js';
3
+ import { createRule } from './rule.utils.js';
4
+ /** True for PascalCase names - React components start with a capital letter. */
5
+ function isPascalCase(name) {
6
+ return /^[A-Z]/.test(name);
7
+ }
8
+ /** Name of a called function: `memo` in `memo(...)` and in `React.memo(...)`. */
9
+ function getCalleeName(callee) {
10
+ if (callee.type === AST_NODE_TYPES.Identifier)
11
+ return callee.name;
12
+ if (callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier) {
13
+ return callee.property.name;
14
+ }
15
+ return '';
16
+ }
17
+ /** True when a variable's value looks like a component: a function, `memo(...)` or `forwardRef(...)`. */
18
+ function isComponentValue(init) {
19
+ if (!init)
20
+ return false;
21
+ if (init.type === AST_NODE_TYPES.ArrowFunctionExpression || init.type === AST_NODE_TYPES.FunctionExpression) {
22
+ return true;
23
+ }
24
+ return init.type === AST_NODE_TYPES.CallExpression && COMPONENT_WRAPPERS.includes(getCalleeName(init.callee));
25
+ }
26
+ /** Name of a type reference: `FC` in `FC<Props>` and in `React.FC<Props>`. */
27
+ function getTypeName(typeName) {
28
+ if (typeName.type === AST_NODE_TYPES.TSQualifiedName)
29
+ return typeName.right.name;
30
+ return typeName.type === AST_NODE_TYPES.Identifier ? typeName.name : '';
31
+ }
32
+ /** True when a variable is typed as a component, e.g. `const Card: FC<Props> = ...`. */
33
+ function hasComponentType(id) {
34
+ const typeNode = id.typeAnnotation?.typeAnnotation;
35
+ if (typeNode?.type !== AST_NODE_TYPES.TSTypeReference)
36
+ return false;
37
+ return COMPONENT_TYPE_NAMES.includes(getTypeName(typeNode.typeName));
38
+ }
39
+ /** Names declared by `export function X` / `export const X = ...`. */
40
+ function getDeclaredNames(declaration) {
41
+ if (!declaration)
42
+ return [];
43
+ if (declaration.type === AST_NODE_TYPES.FunctionDeclaration)
44
+ return declaration.id ? [declaration.id.name] : [];
45
+ if (declaration.type !== AST_NODE_TYPES.VariableDeclaration)
46
+ return [];
47
+ return declaration.declarations.flatMap((declarator) => declarator.id.type === AST_NODE_TYPES.Identifier ? [declarator.id.name] : []);
48
+ }
49
+ /** Names exported by `export function X` / `export const X = ...` / `export { X }`. */
50
+ function getExportedNames(node) {
51
+ const specifierNames = node.specifiers.flatMap((specifier) => specifier.local.type === AST_NODE_TYPES.Identifier ? [specifier.local.name] : []);
52
+ return [...specifierNames, ...getDeclaredNames(node.declaration)];
53
+ }
54
+ /** True for `export default () => ...` and `export default function () {}` (no name). */
55
+ function isAnonymousFunction(declaration) {
56
+ if (declaration.type === AST_NODE_TYPES.ArrowFunctionExpression)
57
+ return true;
58
+ return declaration.type === AST_NODE_TYPES.FunctionDeclaration && !declaration.id;
59
+ }
60
+ /** Name exported by `export default ...`; anonymous default functions count as one component. */
61
+ function getDefaultExportName(declaration) {
62
+ if (declaration.type === AST_NODE_TYPES.Identifier)
63
+ return declaration.name;
64
+ if (declaration.type === AST_NODE_TYPES.FunctionDeclaration && declaration.id)
65
+ return declaration.id.name;
66
+ return isAnonymousFunction(declaration) ? DEFAULT_EXPORT_NAME : '';
67
+ }
68
+ /**
69
+ * talkpilot/one-exported-component: a .tsx file may export at most one React component.
70
+ * Ported from moked_dashboard's own rule.
71
+ */
72
+ export const oneExportedComponent = createRule({
73
+ meta: {
74
+ type: 'problem',
75
+ docs: { description: 'Export at most one React component per file.' },
76
+ schema: [],
77
+ messages: { one: 'Export one component from this file.' },
78
+ },
79
+ create(context) {
80
+ const components = new Set();
81
+ const exported = [];
82
+ return {
83
+ FunctionDeclaration(node) {
84
+ if (node.id && isPascalCase(node.id.name))
85
+ components.add(node.id.name);
86
+ },
87
+ VariableDeclarator(node) {
88
+ if (node.id.type !== AST_NODE_TYPES.Identifier || !isPascalCase(node.id.name))
89
+ return;
90
+ if (isComponentValue(node.init) || hasComponentType(node.id))
91
+ components.add(node.id.name);
92
+ },
93
+ ExportNamedDeclaration(node) {
94
+ exported.push(...getExportedNames(node));
95
+ },
96
+ ExportDefaultDeclaration(node) {
97
+ exported.push(getDefaultExportName(node.declaration));
98
+ },
99
+ 'Program:exit'(node) {
100
+ const isComponent = (name) => name === DEFAULT_EXPORT_NAME || components.has(name);
101
+ if (new Set(exported.filter(isComponent)).size > 1)
102
+ context.report({ node, messageId: 'one' });
103
+ },
104
+ };
105
+ },
106
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talkpilot/eslint-config",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Company-wide ESLint rules for TalkPilot repos.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,6 +28,7 @@
28
28
  "dependencies": {
29
29
  "@typescript-eslint/utils": "^8.73.0",
30
30
  "eslint-plugin-check-file": "^3.3.2",
31
+ "eslint-plugin-react-hooks": "^7.1.1",
31
32
  "typescript-eslint": "^8.73.0"
32
33
  },
33
34
  "devDependencies": {