@talkpilot/eslint-config 0.0.0-stage → 1.0.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
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @talkpilot/eslint-config
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Company-wide ESLint rules for TalkPilot TypeScript repos.
4
+
5
+ ```bash
6
+ npm install -D @talkpilot/eslint-config eslint@10 typescript
7
+ ```
8
+
9
+ ```javascript
10
+ // eslint.config.mjs
11
+ import talkpilot from '@talkpilot/eslint-config';
12
+
13
+ export default [...talkpilot /* , repo rules */];
14
+ ```
15
+
16
+ ```json
17
+ "lint": "talkpilot-lint",
18
+ "lint:all": "talkpilot-lint --all"
19
+ ```
20
+
21
+ Written in TypeScript (`src/`), compiled to `dist/` on `npm pack` / `npm publish`.
22
+
23
+ Repos also run lint before every push (`.husky/pre-push` → `npm run lint`):
24
+
25
+ - `git push --dry-run` - runs the hook without sending anything (good for testing it).
26
+ - `git push --no-verify` - skips the hook; CI on the PR still checks.
27
+
28
+ Full setup, building, the PR workflow and publishing steps: see the `release-management` README.
29
+ Rules and decisions: Notion → DEV / Architecture & Design / Maintainments / ESLint.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ // Usage:
3
+ // talkpilot-lint lint files changed vs. main (whole files) + block new .js files
4
+ // talkpilot-lint --all lint the whole repo
5
+ // talkpilot-lint --all --summary print only {"errors","warnings","files"} as JSON (for the PR comment)
6
+ // In CI, set LINT_BASE to the PR base commit.
7
+ import fs from 'node:fs';
8
+ import { ESLint } from 'eslint';
9
+ import { LINTABLE_FILE, NEW_JS_FILE } from '../lib/cli.constants.js';
10
+ import { changedFiles } from '../lib/git.utils.js';
11
+ const args = new Set(process.argv.slice(2));
12
+ /** Adds up errors and warnings across all linted files. */
13
+ function summarize(results) {
14
+ return {
15
+ errors: results.reduce((sum, result) => sum + result.errorCount, 0),
16
+ warnings: results.reduce((sum, result) => sum + result.warningCount, 0),
17
+ files: results.filter((result) => result.errorCount + result.warningCount > 0).length,
18
+ };
19
+ }
20
+ /** Prints lint results in ESLint's standard readable format. */
21
+ async function printResults(eslint, results) {
22
+ const formatter = await eslint.loadFormatter('stylish');
23
+ const output = await formatter.format(results);
24
+ if (output)
25
+ process.stdout.write(`${output}\n`);
26
+ }
27
+ /** `--all`: lints the whole repo. With `--summary` prints only the counts as JSON (used by the PR comment). */
28
+ async function lintAll(eslint) {
29
+ const results = await eslint.lintFiles(['.']);
30
+ const summary = summarize(results);
31
+ if (args.has('--summary')) {
32
+ process.stdout.write(`${JSON.stringify(summary)}\n`);
33
+ return 0;
34
+ }
35
+ await printResults(eslint, results);
36
+ process.stdout.write(`Lint violations in repo: ${summary.errors} errors, ${summary.warnings} warnings in ${summary.files} files\n`);
37
+ return summary.errors > 0 ? 1 : 0;
38
+ }
39
+ /** Fails when the branch adds a `.js` file under `src/` (new code must be TypeScript). */
40
+ function hasNoNewJsFiles() {
41
+ const newJsFiles = changedFiles('AR').filter((file) => NEW_JS_FILE.test(file));
42
+ if (newJsFiles.length === 0)
43
+ return true;
44
+ process.stderr.write('New .js files are not allowed - new code must be TypeScript:\n');
45
+ for (const file of newJsFiles)
46
+ process.stderr.write(` ${file}\n`);
47
+ return false;
48
+ }
49
+ /** Changed TypeScript files that still exist and aren't ignored by the config (tests, dist, ...). */
50
+ async function findLintableChangedFiles(eslint) {
51
+ const candidates = changedFiles('ACMR').filter((file) => LINTABLE_FILE.test(file) && fs.existsSync(file));
52
+ const files = [];
53
+ for (const file of candidates) {
54
+ if (!(await eslint.isPathIgnored(file)))
55
+ files.push(file);
56
+ }
57
+ return files;
58
+ }
59
+ /** Lints the changed files - the whole file, not only the changed lines. */
60
+ async function isChangedCodeClean(eslint) {
61
+ const files = await findLintableChangedFiles(eslint);
62
+ if (files.length === 0) {
63
+ process.stdout.write('No changed files to lint.\n');
64
+ return true;
65
+ }
66
+ const results = await eslint.lintFiles(files);
67
+ await printResults(eslint, results);
68
+ return summarize(results).errors === 0;
69
+ }
70
+ /** Entry point: `--all` mode, or the default PR mode (new-.js check + lint changed files). */
71
+ async function main() {
72
+ const eslint = new ESLint();
73
+ if (args.has('--all'))
74
+ return lintAll(eslint);
75
+ const isJsCheckPassing = hasNoNewJsFiles();
76
+ const isLintPassing = await isChangedCodeClean(eslint);
77
+ return isJsCheckPassing && isLintPassing ? 0 : 1;
78
+ }
79
+ main()
80
+ .then((exitCode) => process.exit(exitCode))
81
+ .catch((error) => {
82
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
83
+ process.exit(2);
84
+ });
@@ -0,0 +1,14 @@
1
+ import type { Linter } from 'eslint';
2
+ import { talkpilotPlugin } from './rules/index.js';
3
+ /**
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.
9
+ */
10
+ declare const _default: Linter.Config[];
11
+ export default _default;
12
+ export { talkpilotPlugin as plugin };
13
+ export { buildFileNamingRules } from './lib/fileNaming.utils.js';
14
+ export { EXEMPT_FILE_NAMES, LIMITS, ROLE_SUFFIXES } from './lib/defaults.constants.js';
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
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';
6
+ import { assertSupportedEslintVersion } from './lib/versionCheck.utils.js';
7
+ import { talkpilotPlugin } from './rules/index.js';
8
+ assertSupportedEslintVersion();
9
+ /**
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.
15
+ */
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';
43
+ export { EXEMPT_FILE_NAMES, LIMITS, ROLE_SUFFIXES } from './lib/defaults.constants.js';
@@ -0,0 +1,4 @@
1
+ export declare const UPPER_CASE_NAME: RegExp;
2
+ export declare const FUNCTION_NODE_TYPES: Set<string>;
3
+ export declare const TS_WRAPPER_NODE_TYPES: Set<string>;
4
+ export declare const DATA_NODE_TYPES: Set<string>;
@@ -0,0 +1,17 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ export const UPPER_CASE_NAME = /^[A-Z][A-Z0-9_]*$/;
3
+ export const FUNCTION_NODE_TYPES = new Set([
4
+ AST_NODE_TYPES.ArrowFunctionExpression,
5
+ AST_NODE_TYPES.FunctionExpression,
6
+ AST_NODE_TYPES.ClassExpression,
7
+ ]);
8
+ export const TS_WRAPPER_NODE_TYPES = new Set([
9
+ AST_NODE_TYPES.TSAsExpression,
10
+ AST_NODE_TYPES.TSSatisfiesExpression,
11
+ AST_NODE_TYPES.TSTypeAssertion,
12
+ AST_NODE_TYPES.TSNonNullExpression,
13
+ ]);
14
+ export const DATA_NODE_TYPES = new Set([
15
+ AST_NODE_TYPES.ArrayExpression,
16
+ AST_NODE_TYPES.ObjectExpression,
17
+ ]);
@@ -0,0 +1,13 @@
1
+ import { type TSESTree } from '@typescript-eslint/utils';
2
+ import type { DataSize, Scope } from './lint.types.js';
3
+ /**
4
+ * True when a top-level `const` is a constant by our standard:
5
+ * its value is fixed, or its name is UPPER_CASE. Functions and classes never count.
6
+ */
7
+ export declare function isModuleConstant(declarator: TSESTree.VariableDeclarator, scope: Scope): boolean;
8
+ /** Returns the name and line count of a top-level fixed array/object, or null if it isn't one. */
9
+ export declare function getDataSize(declarator: TSESTree.VariableDeclarator, scope: Scope): DataSize | null;
10
+ /** Collects every top-level `const x = ...` in a file (exported or not). Inner scopes are ignored. */
11
+ export declare function getTopLevelConstDeclarators(program: TSESTree.Program): TSESTree.VariableDeclarator[];
12
+ /** True when the file name ends with one of the given suffixes, e.g. `.types.ts`. */
13
+ export declare function hasSuffix(filename: string, suffixes: string[]): boolean;
@@ -0,0 +1,62 @@
1
+ import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';
2
+ import { DATA_NODE_TYPES, FUNCTION_NODE_TYPES, TS_WRAPPER_NODE_TYPES, UPPER_CASE_NAME, } from './ast.constants.js';
3
+ /** Strips TypeScript-only wrappers (`as`, `satisfies`, `<T>x`, `x!`) and returns the real value node underneath. */
4
+ function unwrap(node) {
5
+ let current = node ?? null;
6
+ while (current && TS_WRAPPER_NODE_TYPES.has(current.type)) {
7
+ current = current.expression;
8
+ }
9
+ return current;
10
+ }
11
+ /**
12
+ * True when the value is fixed when the code is written (not computed at runtime).
13
+ * Uses ESLint's own `getStaticValue`, which also follows references to other constants.
14
+ */
15
+ function isStaticValue(node, scope) {
16
+ return ASTUtils.getStaticValue(node, scope) !== null;
17
+ }
18
+ /**
19
+ * True when a top-level `const` is a constant by our standard:
20
+ * its value is fixed, or its name is UPPER_CASE. Functions and classes never count.
21
+ */
22
+ export function isModuleConstant(declarator, scope) {
23
+ if (declarator.id.type !== AST_NODE_TYPES.Identifier)
24
+ return false;
25
+ const init = unwrap(declarator.init);
26
+ if (!init || FUNCTION_NODE_TYPES.has(init.type))
27
+ return false;
28
+ return UPPER_CASE_NAME.test(declarator.id.name) || isStaticValue(init, scope);
29
+ }
30
+ /** True for a fixed array or object, i.e. something that could live in a *.data.ts file. */
31
+ function isDataLiteral(node, scope) {
32
+ const value = unwrap(node);
33
+ return value !== null && DATA_NODE_TYPES.has(value.type) && isStaticValue(value, scope);
34
+ }
35
+ /** Returns the name and line count of a top-level fixed array/object, or null if it isn't one. */
36
+ export function getDataSize(declarator, scope) {
37
+ const { id, init } = declarator;
38
+ if (id.type !== AST_NODE_TYPES.Identifier || !init || !isDataLiteral(init, scope))
39
+ return null;
40
+ return { name: id.name, lines: init.loc.end.line - init.loc.start.line + 1 };
41
+ }
42
+ /** Gets the declaration out of `export const ...`, or returns the statement as-is. */
43
+ function toDeclaration(statement) {
44
+ if (statement.type === AST_NODE_TYPES.ExportNamedDeclaration)
45
+ return statement.declaration;
46
+ return statement;
47
+ }
48
+ /** Collects every top-level `const x = ...` in a file (exported or not). Inner scopes are ignored. */
49
+ export function getTopLevelConstDeclarators(program) {
50
+ const declarators = [];
51
+ for (const statement of program.body) {
52
+ const declaration = toDeclaration(statement);
53
+ if (declaration?.type === AST_NODE_TYPES.VariableDeclaration && declaration.kind === 'const') {
54
+ declarators.push(...declaration.declarations);
55
+ }
56
+ }
57
+ return declarators;
58
+ }
59
+ /** True when the file name ends with one of the given suffixes, e.g. `.types.ts`. */
60
+ export function hasSuffix(filename, suffixes) {
61
+ return suffixes.some((suffix) => filename.endsWith(suffix));
62
+ }
@@ -0,0 +1,3 @@
1
+ export declare const LINTABLE_FILE: RegExp;
2
+ export declare const NEW_JS_FILE: RegExp;
3
+ export declare const DEFAULT_BRANCHES: string[];
@@ -0,0 +1,3 @@
1
+ export const LINTABLE_FILE = /\.(ts|tsx)$/;
2
+ export const NEW_JS_FILE = /^src\/.*\.(js|jsx)$/;
3
+ export const DEFAULT_BRANCHES = ['origin/main', 'main'];
@@ -0,0 +1,12 @@
1
+ import type { LintLimits } from './lint.types.js';
2
+ export declare const SUPPORTED_ESLINT_MAJOR = 10;
3
+ export declare const LINTED_FILES: string[];
4
+ export declare const IGNORED_PATHS: string[];
5
+ export declare const ROLE_SUFFIXES: string[];
6
+ export declare const EXEMPT_FILE_NAMES: string[];
7
+ export declare const IGNORED_FOLDER_NAMES: string[];
8
+ export declare const LIMITS: LintLimits;
9
+ export declare const BOOLEAN_PREFIXES: string[];
10
+ export declare const TYPE_FILE_SUFFIXES: string[];
11
+ export declare const CONSTANT_FILE_SUFFIXES: string[];
12
+ export declare const DATA_FILE_SUFFIX = ".data.ts";
@@ -0,0 +1,42 @@
1
+ export const SUPPORTED_ESLINT_MAJOR = 10;
2
+ export const LINTED_FILES = ['**/*.ts', '**/*.tsx'];
3
+ export const IGNORED_PATHS = [
4
+ '**/node_modules/**',
5
+ '**/dist/**',
6
+ '**/build/**',
7
+ '**/coverage/**',
8
+ '**/*.d.ts',
9
+ '**/*.spec.ts',
10
+ '**/*.test.ts',
11
+ '**/__tests__/**',
12
+ ];
13
+ export const ROLE_SUFFIXES = [
14
+ 'types',
15
+ 'constants',
16
+ 'data',
17
+ 'utils',
18
+ 'service',
19
+ 'routes',
20
+ 'controllers',
21
+ 'schema',
22
+ 'spec',
23
+ 'client',
24
+ 'errors',
25
+ 'api',
26
+ 'resolvers',
27
+ ];
28
+ export const EXEMPT_FILE_NAMES = ['index.ts', 'app.ts'];
29
+ export const IGNORED_FOLDER_NAMES = ['__tests__', '__mocks__'];
30
+ export const LIMITS = {
31
+ FUNCTION_LINES: 40,
32
+ FILE_LINES: 200,
33
+ DATA_FILE_LINES: 5000,
34
+ NESTING_DEPTH: 3,
35
+ FUNCTION_PARAMS: 5,
36
+ COMPLEXITY: 5,
37
+ INLINE_DATA_LINES: 50,
38
+ };
39
+ export const BOOLEAN_PREFIXES = ['is', 'has', 'should', 'can'];
40
+ export const TYPE_FILE_SUFFIXES = ['.types.ts', '.d.ts'];
41
+ export const CONSTANT_FILE_SUFFIXES = ['.constants.ts', '.data.ts'];
42
+ export const DATA_FILE_SUFFIX = '.data.ts';
@@ -0,0 +1,25 @@
1
+ import type { FileNamingOptions } from './lint.types.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 declare function buildFileNamingRules(options?: FileNamingOptions): {
10
+ 'check-file/filename-naming-convention': (string | {
11
+ [x: string]: string;
12
+ errorMessage?: undefined;
13
+ } | {
14
+ errorMessage: string;
15
+ })[];
16
+ 'check-file/folder-naming-convention': (string | {
17
+ '**/': string;
18
+ ignoreWords?: undefined;
19
+ errorMessage?: undefined;
20
+ } | {
21
+ ignoreWords: string[];
22
+ errorMessage: string;
23
+ '**/'?: undefined;
24
+ })[];
25
+ };
@@ -0,0 +1,31 @@
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])';
14
+ return {
15
+ 'check-file/filename-naming-convention': [
16
+ 'error',
17
+ { [`**/!(${exemptNames}).ts`]: `${namePart}*(.${namePart}).@(${roles.join('|')})` },
18
+ {
19
+ errorMessage: `File name '{{ target }}' must be camelCase plus a role suffix: <name>.<role>.ts (roles: ${roles.join(', ')}).`,
20
+ },
21
+ ],
22
+ 'check-file/folder-naming-convention': [
23
+ 'error',
24
+ { '**/': 'CAMEL_CASE' },
25
+ {
26
+ ignoreWords: options.ignoredFolders ?? IGNORED_FOLDER_NAMES,
27
+ errorMessage: "Folder '{{ target }}' must be camelCase.",
28
+ },
29
+ ],
30
+ };
31
+ }
@@ -0,0 +1,8 @@
1
+ /** Runs a git command and returns its output as a list of lines (empty list on error). */
2
+ export declare function git(gitArgs: string[]): string[];
3
+ /**
4
+ * Lists files changed vs the base, relative to the current folder.
5
+ * `diffFilter` is git's filter: A = added, C = copied, M = modified, R = renamed.
6
+ * Locally it also includes uncommitted, staged and new untracked files; in CI only commits count.
7
+ */
8
+ export declare function changedFiles(diffFilter: string): string[];
@@ -0,0 +1,42 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { DEFAULT_BRANCHES } from './cli.constants.js';
3
+ /** Runs a git command and returns its output as a list of lines (empty list on error). */
4
+ export function git(gitArgs) {
5
+ try {
6
+ return execFileSync('git', gitArgs, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
7
+ .split('\n')
8
+ .map((line) => line.trim())
9
+ .filter(Boolean);
10
+ }
11
+ catch {
12
+ return [];
13
+ }
14
+ }
15
+ /**
16
+ * Finds the commit to compare against: `LINT_BASE` in CI (the PR base), otherwise
17
+ * where this branch split from `origin/main` / `main`.
18
+ */
19
+ function findBase() {
20
+ if (process.env.LINT_BASE)
21
+ return process.env.LINT_BASE;
22
+ for (const branch of DEFAULT_BRANCHES) {
23
+ const [base] = git(['merge-base', 'HEAD', branch]);
24
+ if (base)
25
+ return base;
26
+ }
27
+ return '';
28
+ }
29
+ /**
30
+ * Lists files changed vs the base, relative to the current folder.
31
+ * `diffFilter` is git's filter: A = added, C = copied, M = modified, R = renamed.
32
+ * Locally it also includes uncommitted, staged and new untracked files; in CI only commits count.
33
+ */
34
+ export function changedFiles(diffFilter) {
35
+ const base = findBase();
36
+ const diff = (extra) => git(['diff', '--name-only', '--relative', `--diff-filter=${diffFilter}`, ...extra]);
37
+ const committed = base ? diff([`${base}...HEAD`]) : [];
38
+ const local = process.env.CI
39
+ ? []
40
+ : [...diff([]), ...diff(['--cached']), ...git(['ls-files', '--others', '--exclude-standard'])];
41
+ return [...new Set([...committed, ...local])];
42
+ }
@@ -0,0 +1,29 @@
1
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ export type LintSummary = {
3
+ errors: number;
4
+ warnings: number;
5
+ files: number;
6
+ };
7
+ export type LintLimits = {
8
+ FUNCTION_LINES: number;
9
+ FILE_LINES: number;
10
+ DATA_FILE_LINES: number;
11
+ NESTING_DEPTH: number;
12
+ FUNCTION_PARAMS: number;
13
+ COMPLEXITY: number;
14
+ INLINE_DATA_LINES: number;
15
+ };
16
+ export type FileNamingOptions = {
17
+ roles?: string[];
18
+ exemptFiles?: string[];
19
+ ignoredFolders?: string[];
20
+ };
21
+ export type DataInDataFileOptions = {
22
+ maxLines?: number;
23
+ };
24
+ export type WrappedExpression = TSESTree.TSAsExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression;
25
+ export type DataSize = {
26
+ name: string;
27
+ lines: number;
28
+ };
29
+ export type Scope = TSESLint.Scope.Scope;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,125 @@
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-console': string;
122
+ 'no-empty': (string | {
123
+ allowEmptyCatch: boolean;
124
+ })[];
125
+ };
@@ -0,0 +1,69 @@
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-console': 'error',
68
+ 'no-empty': ['error', { allowEmptyCatch: false }],
69
+ };
@@ -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,12 @@
1
+ import { constantsInConstantsFile } from './constantsInConstantsFile.rule.js';
2
+ import { dataInDataFile } from './dataInDataFile.rule.js';
3
+ import { typesInTypesFile } from './typesInTypesFile.rule.js';
4
+ /** Our custom rules as an ESLint plugin. In configs, they're used with the `talkpilot/` prefix. */
5
+ export const talkpilotPlugin = {
6
+ meta: { name: '@talkpilot/eslint-plugin' },
7
+ rules: {
8
+ 'types-in-types-file': typesInTypesFile,
9
+ 'constants-in-constants-file': constantsInConstantsFile,
10
+ 'data-in-data-file': dataInDataFile,
11
+ },
12
+ };
@@ -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,46 @@
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.0.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
+ "typescript-eslint": "^8.73.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.0.0",
35
+ "eslint": "^10.13.0",
36
+ "typescript": "^5.9.0"
37
+ },
38
+ "peerDependencies": {
39
+ "eslint": "^10.0.0",
40
+ "typescript": ">=5.0.0"
41
+ },
42
+ "license": "UNLICENSED",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }