@talkpilot/eslint-config 0.0.0-stage → 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.
Files changed (42) hide show
  1. package/README.md +28 -2
  2. package/dist/bin/index.d.ts +2 -0
  3. package/dist/bin/index.js +84 -0
  4. package/dist/index.d.ts +14 -0
  5. package/dist/index.js +16 -0
  6. package/dist/lib/ast.constants.d.ts +4 -0
  7. package/dist/lib/ast.constants.js +17 -0
  8. package/dist/lib/ast.utils.d.ts +13 -0
  9. package/dist/lib/ast.utils.js +62 -0
  10. package/dist/lib/cli.constants.d.ts +3 -0
  11. package/dist/lib/cli.constants.js +3 -0
  12. package/dist/lib/defaults.constants.d.ts +17 -0
  13. package/dist/lib/defaults.constants.js +51 -0
  14. package/dist/lib/fileNaming.utils.d.ts +38 -0
  15. package/dist/lib/fileNaming.utils.js +54 -0
  16. package/dist/lib/git.utils.d.ts +8 -0
  17. package/dist/lib/git.utils.js +42 -0
  18. package/dist/lib/lint.types.d.ts +30 -0
  19. package/dist/lib/lint.types.js +1 -0
  20. package/dist/lib/presets.constants.d.ts +2 -0
  21. package/dist/lib/presets.constants.js +3 -0
  22. package/dist/lib/presets.utils.d.ts +8 -0
  23. package/dist/lib/presets.utils.js +67 -0
  24. package/dist/lib/react.constants.d.ts +3 -0
  25. package/dist/lib/react.constants.js +3 -0
  26. package/dist/lib/ruleSets.constants.d.ts +217 -0
  27. package/dist/lib/ruleSets.constants.js +93 -0
  28. package/dist/lib/versionCheck.utils.d.ts +5 -0
  29. package/dist/lib/versionCheck.utils.js +13 -0
  30. package/dist/rules/constantsInConstantsFile.rule.d.ts +5 -0
  31. package/dist/rules/constantsInConstantsFile.rule.js +36 -0
  32. package/dist/rules/dataInDataFile.rule.d.ts +6 -0
  33. package/dist/rules/dataInDataFile.rule.js +44 -0
  34. package/dist/rules/index.d.ts +3 -0
  35. package/dist/rules/index.js +14 -0
  36. package/dist/rules/oneExportedComponent.rule.d.ts +5 -0
  37. package/dist/rules/oneExportedComponent.rule.js +106 -0
  38. package/dist/rules/rule.utils.d.ts +3 -0
  39. package/dist/rules/rule.utils.js +3 -0
  40. package/dist/rules/typesInTypesFile.rule.d.ts +2 -0
  41. package/dist/rules/typesInTypesFile.rule.js +23 -0
  42. package/package.json +45 -4
@@ -0,0 +1,217 @@
1
+ export declare const NAMING_CONVENTION: ({
2
+ selector: string;
3
+ format: string[];
4
+ leadingUnderscore: string;
5
+ modifiers?: undefined;
6
+ filter?: undefined;
7
+ types?: undefined;
8
+ prefix?: undefined;
9
+ } | {
10
+ selector: string;
11
+ format: null;
12
+ leadingUnderscore?: undefined;
13
+ modifiers?: undefined;
14
+ filter?: undefined;
15
+ types?: undefined;
16
+ prefix?: undefined;
17
+ } | {
18
+ selector: string;
19
+ modifiers: string[];
20
+ format: null;
21
+ leadingUnderscore?: undefined;
22
+ filter?: undefined;
23
+ types?: undefined;
24
+ prefix?: undefined;
25
+ } | {
26
+ selector: string;
27
+ filter: {
28
+ regex: string;
29
+ match: boolean;
30
+ };
31
+ format: string[];
32
+ leadingUnderscore?: undefined;
33
+ modifiers?: undefined;
34
+ types?: undefined;
35
+ prefix?: undefined;
36
+ } | {
37
+ selector: string;
38
+ modifiers: string[];
39
+ types: string[];
40
+ format: string[];
41
+ leadingUnderscore?: undefined;
42
+ filter?: undefined;
43
+ prefix?: undefined;
44
+ } | {
45
+ selector: string;
46
+ types: string[];
47
+ format: string[];
48
+ prefix: string[];
49
+ leadingUnderscore?: undefined;
50
+ modifiers?: undefined;
51
+ filter?: undefined;
52
+ } | {
53
+ selector: string;
54
+ format: string[];
55
+ leadingUnderscore?: undefined;
56
+ modifiers?: undefined;
57
+ filter?: undefined;
58
+ types?: undefined;
59
+ prefix?: undefined;
60
+ } | {
61
+ selector: string[];
62
+ format: null;
63
+ leadingUnderscore?: undefined;
64
+ modifiers?: undefined;
65
+ filter?: undefined;
66
+ types?: undefined;
67
+ prefix?: undefined;
68
+ })[];
69
+ export declare const SIZE_RULES: {
70
+ 'max-lines-per-function': (string | {
71
+ max: number;
72
+ skipBlankLines: boolean;
73
+ skipComments: boolean;
74
+ IIFEs: boolean;
75
+ })[];
76
+ 'max-lines': (string | {
77
+ max: number;
78
+ skipBlankLines: boolean;
79
+ skipComments: boolean;
80
+ })[];
81
+ 'max-depth': (string | number)[];
82
+ '@typescript-eslint/max-params': (string | {
83
+ max: number;
84
+ })[];
85
+ complexity: (string | number)[];
86
+ };
87
+ export declare const DATA_FILE_RULES: {
88
+ 'max-lines': (string | {
89
+ max: number;
90
+ skipBlankLines: boolean;
91
+ skipComments: boolean;
92
+ })[];
93
+ };
94
+ export declare const TYPESCRIPT_RULES: {
95
+ '@typescript-eslint/no-explicit-any': string;
96
+ '@typescript-eslint/no-floating-promises': string;
97
+ 'no-unused-vars': string;
98
+ '@typescript-eslint/no-unused-vars': (string | {
99
+ argsIgnorePattern: string;
100
+ varsIgnorePattern: string;
101
+ caughtErrorsIgnorePattern: string;
102
+ ignoreRestSiblings: boolean;
103
+ })[];
104
+ '@typescript-eslint/consistent-type-imports': (string | {
105
+ prefer: string;
106
+ })[];
107
+ '@typescript-eslint/no-non-null-assertion': string;
108
+ '@typescript-eslint/ban-ts-comment': (string | {
109
+ 'ts-ignore': boolean;
110
+ 'ts-nocheck': boolean;
111
+ 'ts-expect-error': string;
112
+ })[];
113
+ '@typescript-eslint/consistent-type-definitions': string[];
114
+ };
115
+ export declare const STRUCTURE_RULES: {
116
+ 'talkpilot/types-in-types-file': string;
117
+ 'talkpilot/constants-in-constants-file': string;
118
+ 'talkpilot/data-in-data-file': string;
119
+ };
120
+ export declare const LOGGING_RULES: {
121
+ 'no-empty': (string | {
122
+ allowEmptyCatch: boolean;
123
+ })[];
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
+ };
@@ -0,0 +1,93 @@
1
+ import { BOOLEAN_PREFIXES, LIMITS } from './defaults.constants.js';
2
+ export const NAMING_CONVENTION = [
3
+ { selector: 'default', format: ['camelCase'], leadingUnderscore: 'allow' },
4
+ { selector: 'import', format: null },
5
+ { selector: 'variable', format: ['camelCase', 'UPPER_CASE'], leadingUnderscore: 'allow' },
6
+ { selector: 'variable', modifiers: ['destructured'], format: null },
7
+ {
8
+ selector: 'variable',
9
+ filter: { regex: 'Schema$', match: true },
10
+ format: ['PascalCase', 'camelCase'],
11
+ },
12
+ { selector: 'parameter', modifiers: ['destructured'], format: null },
13
+ {
14
+ selector: 'variable',
15
+ modifiers: ['const', 'global'],
16
+ types: ['boolean', 'string', 'number', 'array'],
17
+ format: ['UPPER_CASE'],
18
+ },
19
+ { selector: 'variable', types: ['boolean'], format: ['PascalCase'], prefix: BOOLEAN_PREFIXES },
20
+ { selector: 'typeLike', format: ['PascalCase'] },
21
+ { selector: 'enumMember', format: ['UPPER_CASE', 'PascalCase'] },
22
+ {
23
+ selector: ['objectLiteralProperty', 'objectLiteralMethod', 'typeProperty'],
24
+ format: null,
25
+ },
26
+ ];
27
+ export const SIZE_RULES = {
28
+ 'max-lines-per-function': [
29
+ 'error',
30
+ { max: LIMITS.FUNCTION_LINES, skipBlankLines: true, skipComments: true, IIFEs: true },
31
+ ],
32
+ 'max-lines': ['error', { max: LIMITS.FILE_LINES, skipBlankLines: true, skipComments: true }],
33
+ 'max-depth': ['error', LIMITS.NESTING_DEPTH],
34
+ '@typescript-eslint/max-params': ['error', { max: LIMITS.FUNCTION_PARAMS }],
35
+ complexity: ['error', LIMITS.COMPLEXITY],
36
+ };
37
+ export const DATA_FILE_RULES = {
38
+ 'max-lines': ['error', { max: LIMITS.DATA_FILE_LINES, skipBlankLines: true, skipComments: true }],
39
+ };
40
+ export const TYPESCRIPT_RULES = {
41
+ '@typescript-eslint/no-explicit-any': 'error',
42
+ '@typescript-eslint/no-floating-promises': 'error',
43
+ 'no-unused-vars': 'off',
44
+ '@typescript-eslint/no-unused-vars': [
45
+ 'error',
46
+ {
47
+ argsIgnorePattern: '^_',
48
+ varsIgnorePattern: '^_',
49
+ caughtErrorsIgnorePattern: '^_',
50
+ ignoreRestSiblings: true,
51
+ },
52
+ ],
53
+ '@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
54
+ '@typescript-eslint/no-non-null-assertion': 'error',
55
+ '@typescript-eslint/ban-ts-comment': [
56
+ 'error',
57
+ { 'ts-ignore': true, 'ts-nocheck': true, 'ts-expect-error': 'allow-with-description' },
58
+ ],
59
+ '@typescript-eslint/consistent-type-definitions': ['error', 'type'],
60
+ };
61
+ export const STRUCTURE_RULES = {
62
+ 'talkpilot/types-in-types-file': 'error',
63
+ 'talkpilot/constants-in-constants-file': 'error',
64
+ 'talkpilot/data-in-data-file': 'error',
65
+ };
66
+ export const LOGGING_RULES = {
67
+ 'no-empty': ['error', { allowEmptyCatch: false }],
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
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Stops the lint run with a clear message when the repo has a different ESLint major
3
+ * version than this package supports. Runs once when the config is loaded.
4
+ */
5
+ export declare function assertSupportedEslintVersion(): void;
@@ -0,0 +1,13 @@
1
+ import { ESLint } from 'eslint';
2
+ import { SUPPORTED_ESLINT_MAJOR } from './defaults.constants.js';
3
+ /**
4
+ * Stops the lint run with a clear message when the repo has a different ESLint major
5
+ * version than this package supports. Runs once when the config is loaded.
6
+ */
7
+ export function assertSupportedEslintVersion() {
8
+ const installedMajor = Number(ESLint.version.split('.')[0]);
9
+ if (installedMajor !== SUPPORTED_ESLINT_MAJOR) {
10
+ throw new Error(`@talkpilot/eslint-config requires ESLint ${SUPPORTED_ESLINT_MAJOR}.x - found ${ESLint.version}. ` +
11
+ `Upgrade eslint in this repo: npm install -D eslint@${SUPPORTED_ESLINT_MAJOR}`);
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * talkpilot/constants-in-constants-file: reports top-level constants (see `isModuleConstant`)
3
+ * declared outside *.constants.ts / *.data.ts files.
4
+ */
5
+ export declare const constantsInConstantsFile: import("@typescript-eslint/utils/ts-eslint").RuleModule<"moveToConstantsFile", readonly unknown[], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,36 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import { CONSTANT_FILE_SUFFIXES } from '../lib/defaults.constants.js';
3
+ import { getTopLevelConstDeclarators, hasSuffix, isModuleConstant } from '../lib/ast.utils.js';
4
+ import { createRule } from './rule.utils.js';
5
+ /**
6
+ * talkpilot/constants-in-constants-file: reports top-level constants (see `isModuleConstant`)
7
+ * declared outside *.constants.ts / *.data.ts files.
8
+ */
9
+ export const constantsInConstantsFile = createRule({
10
+ meta: {
11
+ type: 'suggestion',
12
+ docs: { description: 'Module-level constants live only in *.constants.ts files.' },
13
+ schema: [],
14
+ messages: {
15
+ moveToConstantsFile: "'{{name}}' is a module-level constant. Move it to a *.constants.ts file (or *.data.ts for large static data).",
16
+ },
17
+ },
18
+ create(context) {
19
+ if (hasSuffix(context.filename, CONSTANT_FILE_SUFFIXES))
20
+ return {};
21
+ return {
22
+ Program(program) {
23
+ const scope = context.sourceCode.getScope(program);
24
+ for (const declarator of getTopLevelConstDeclarators(program)) {
25
+ if (declarator.id.type !== AST_NODE_TYPES.Identifier || !isModuleConstant(declarator, scope))
26
+ continue;
27
+ context.report({
28
+ node: declarator.id,
29
+ messageId: 'moveToConstantsFile',
30
+ data: { name: declarator.id.name },
31
+ });
32
+ }
33
+ },
34
+ };
35
+ },
36
+ });
@@ -0,0 +1,6 @@
1
+ import type { DataInDataFileOptions } from '../lib/lint.types.js';
2
+ /**
3
+ * talkpilot/data-in-data-file: reports top-level arrays/objects of fixed data longer than
4
+ * `maxLines` (default 50) that aren't in a *.data.ts file.
5
+ */
6
+ export declare const dataInDataFile: import("@typescript-eslint/utils/ts-eslint").RuleModule<"moveToDataFile", [DataInDataFileOptions], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,44 @@
1
+ import { DATA_FILE_SUFFIX, LIMITS } from '../lib/defaults.constants.js';
2
+ import { getDataSize, getTopLevelConstDeclarators } from '../lib/ast.utils.js';
3
+ import { createRule } from './rule.utils.js';
4
+ /**
5
+ * talkpilot/data-in-data-file: reports top-level arrays/objects of fixed data longer than
6
+ * `maxLines` (default 50) that aren't in a *.data.ts file.
7
+ */
8
+ export const dataInDataFile = createRule({
9
+ meta: {
10
+ type: 'suggestion',
11
+ defaultOptions: [{ maxLines: LIMITS.INLINE_DATA_LINES }],
12
+ docs: { description: 'Large static data lives in *.data.ts files.' },
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: { maxLines: { type: 'integer', minimum: 1 } },
17
+ additionalProperties: false,
18
+ },
19
+ ],
20
+ messages: {
21
+ moveToDataFile: "'{{name}}' is {{lines}} lines of static data (max {{maxLines}} outside data files). Move it to a *.data.ts file.",
22
+ },
23
+ },
24
+ create(context, [options]) {
25
+ if (context.filename.endsWith(DATA_FILE_SUFFIX))
26
+ return {};
27
+ const maxLines = options.maxLines ?? LIMITS.INLINE_DATA_LINES;
28
+ return {
29
+ Program(program) {
30
+ const scope = context.sourceCode.getScope(program);
31
+ for (const declarator of getTopLevelConstDeclarators(program)) {
32
+ const size = getDataSize(declarator, scope);
33
+ if (!size || size.lines <= maxLines)
34
+ continue;
35
+ context.report({
36
+ node: declarator.id,
37
+ messageId: 'moveToDataFile',
38
+ data: { name: size.name, lines: size.lines, maxLines },
39
+ });
40
+ }
41
+ },
42
+ };
43
+ },
44
+ });
@@ -0,0 +1,3 @@
1
+ import type { ESLint } from 'eslint';
2
+ /** Our custom rules as an ESLint plugin. In configs, they're used with the `talkpilot/` prefix. */
3
+ export declare const talkpilotPlugin: ESLint.Plugin;
@@ -0,0 +1,14 @@
1
+ import { constantsInConstantsFile } from './constantsInConstantsFile.rule.js';
2
+ import { dataInDataFile } from './dataInDataFile.rule.js';
3
+ import { oneExportedComponent } from './oneExportedComponent.rule.js';
4
+ import { typesInTypesFile } from './typesInTypesFile.rule.js';
5
+ /** Our custom rules as an ESLint plugin. In configs, they're used with the `talkpilot/` prefix. */
6
+ export const talkpilotPlugin = {
7
+ meta: { name: '@talkpilot/eslint-plugin' },
8
+ rules: {
9
+ 'types-in-types-file': typesInTypesFile,
10
+ 'constants-in-constants-file': constantsInConstantsFile,
11
+ 'data-in-data-file': dataInDataFile,
12
+ 'one-exported-component': oneExportedComponent,
13
+ },
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
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ /** Helper from typescript-eslint for writing typed rules (we don't publish rule docs pages). */
3
+ export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>(args: Readonly<ESLintUtils.RuleWithMeta<Options, MessageIds>>) => ESLintUtils.RuleModule<MessageIds, Options>;
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ /** Helper from typescript-eslint for writing typed rules (we don't publish rule docs pages). */
3
+ export const createRule = ESLintUtils.RuleCreator.withoutDocs;
@@ -0,0 +1,2 @@
1
+ /** talkpilot/types-in-types-file: reports every `type` / `interface` declared outside a *.types.ts (or *.d.ts) file. */
2
+ export declare const typesInTypesFile: import("@typescript-eslint/utils/ts-eslint").RuleModule<"moveToTypesFile", readonly unknown[], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,23 @@
1
+ import { TYPE_FILE_SUFFIXES } from '../lib/defaults.constants.js';
2
+ import { hasSuffix } from '../lib/ast.utils.js';
3
+ import { createRule } from './rule.utils.js';
4
+ /** talkpilot/types-in-types-file: reports every `type` / `interface` declared outside a *.types.ts (or *.d.ts) file. */
5
+ export const typesInTypesFile = createRule({
6
+ meta: {
7
+ type: 'suggestion',
8
+ docs: { description: 'Types live only in *.types.ts files.' },
9
+ schema: [],
10
+ messages: {
11
+ moveToTypesFile: "Type '{{name}}' must live in a *.types.ts file.",
12
+ },
13
+ },
14
+ create(context) {
15
+ if (hasSuffix(context.filename, TYPE_FILE_SUFFIXES))
16
+ return {};
17
+ const report = (node) => context.report({ node: node.id, messageId: 'moveToTypesFile', data: { name: node.id.name } });
18
+ return {
19
+ TSTypeAliasDeclaration: report,
20
+ TSInterfaceDeclaration: report,
21
+ };
22
+ },
23
+ });
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@talkpilot/eslint-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.1",
4
+ "description": "Company-wide ESLint rules for TalkPilot repos.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "bin": {
15
+ "talkpilot-lint": "dist/bin/index.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "prepack": "npm run build"
24
+ },
25
+ "engines": {
26
+ "node": ">=20"
27
+ },
28
+ "dependencies": {
29
+ "@typescript-eslint/utils": "^8.73.0",
30
+ "eslint-plugin-check-file": "^3.3.2",
31
+ "eslint-plugin-react-hooks": "^7.1.1",
32
+ "typescript-eslint": "^8.73.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^22.0.0",
36
+ "eslint": "^10.13.0",
37
+ "typescript": "^5.9.0"
38
+ },
39
+ "peerDependencies": {
40
+ "eslint": "^10.0.0",
41
+ "typescript": ">=5.0.0"
42
+ },
43
+ "license": "UNLICENSED",
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }