@mathonsunday/dead-code-toolkit 0.1.0
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 +356 -0
- package/dist/analyzer.d.ts +23 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +173 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/checkers/knipChecker.d.ts +11 -0
- package/dist/checkers/knipChecker.d.ts.map +1 -0
- package/dist/checkers/knipChecker.js +226 -0
- package/dist/checkers/knipChecker.js.map +1 -0
- package/dist/checkers/typescriptChecker.d.ts +10 -0
- package/dist/checkers/typescriptChecker.d.ts.map +1 -0
- package/dist/checkers/typescriptChecker.js +174 -0
- package/dist/checkers/typescriptChecker.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +204 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config/detectors.d.ts +29 -0
- package/dist/config/detectors.d.ts.map +1 -0
- package/dist/config/detectors.js +159 -0
- package/dist/config/detectors.js.map +1 -0
- package/dist/config/templates.d.ts +76 -0
- package/dist/config/templates.d.ts.map +1 -0
- package/dist/config/templates.js +191 -0
- package/dist/config/templates.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/reporters/jsonReporter.d.ts +68 -0
- package/dist/reporters/jsonReporter.d.ts.map +1 -0
- package/dist/reporters/jsonReporter.js +161 -0
- package/dist/reporters/jsonReporter.js.map +1 -0
- package/dist/setup/hookInstaller.d.ts +36 -0
- package/dist/setup/hookInstaller.d.ts.map +1 -0
- package/dist/setup/hookInstaller.js +196 -0
- package/dist/setup/hookInstaller.js.map +1 -0
- package/dist/setup/installer.d.ts +10 -0
- package/dist/setup/installer.d.ts.map +1 -0
- package/dist/setup/installer.js +156 -0
- package/dist/setup/installer.js.map +1 -0
- package/dist/setup/packageJsonUpdater.d.ts +54 -0
- package/dist/setup/packageJsonUpdater.d.ts.map +1 -0
- package/dist/setup/packageJsonUpdater.js +129 -0
- package/dist/setup/packageJsonUpdater.js.map +1 -0
- package/dist/src/analyzer.d.ts +23 -0
- package/dist/src/analyzer.d.ts.map +1 -0
- package/dist/src/analyzer.js +173 -0
- package/dist/src/analyzer.js.map +1 -0
- package/dist/src/checkers/knipChecker.d.ts +11 -0
- package/dist/src/checkers/knipChecker.d.ts.map +1 -0
- package/dist/src/checkers/knipChecker.js +226 -0
- package/dist/src/checkers/knipChecker.js.map +1 -0
- package/dist/src/checkers/typescriptChecker.d.ts +10 -0
- package/dist/src/checkers/typescriptChecker.d.ts.map +1 -0
- package/dist/src/checkers/typescriptChecker.js +174 -0
- package/dist/src/checkers/typescriptChecker.js.map +1 -0
- package/dist/src/config/detectors.d.ts +29 -0
- package/dist/src/config/detectors.d.ts.map +1 -0
- package/dist/src/config/detectors.js +159 -0
- package/dist/src/config/detectors.js.map +1 -0
- package/dist/src/config/templates.d.ts +76 -0
- package/dist/src/config/templates.d.ts.map +1 -0
- package/dist/src/config/templates.js +191 -0
- package/dist/src/config/templates.js.map +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/reporters/jsonReporter.d.ts +68 -0
- package/dist/src/reporters/jsonReporter.d.ts.map +1 -0
- package/dist/src/reporters/jsonReporter.js +161 -0
- package/dist/src/reporters/jsonReporter.js.map +1 -0
- package/dist/src/setup/hookInstaller.d.ts +36 -0
- package/dist/src/setup/hookInstaller.d.ts.map +1 -0
- package/dist/src/setup/hookInstaller.js +196 -0
- package/dist/src/setup/hookInstaller.js.map +1 -0
- package/dist/src/setup/installer.d.ts +10 -0
- package/dist/src/setup/installer.d.ts.map +1 -0
- package/dist/src/setup/installer.js +156 -0
- package/dist/src/setup/installer.js.map +1 -0
- package/dist/src/setup/packageJsonUpdater.d.ts +54 -0
- package/dist/src/setup/packageJsonUpdater.d.ts.map +1 -0
- package/dist/src/setup/packageJsonUpdater.js +129 -0
- package/dist/src/setup/packageJsonUpdater.js.map +1 -0
- package/dist/src/types.d.ts +177 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript compiler integration for detecting type errors
|
|
3
|
+
* Uses tsc to compile and collect diagnostics
|
|
4
|
+
*/
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
/**
|
|
7
|
+
* Run TypeScript type checking on a project
|
|
8
|
+
*/
|
|
9
|
+
export async function runTypeScriptCheck(projectRoot) {
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
try {
|
|
12
|
+
// Check if TypeScript is available
|
|
13
|
+
if (!isTypeScriptInstalled()) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'typescript',
|
|
16
|
+
status: 'skipped',
|
|
17
|
+
findings: [],
|
|
18
|
+
executionTime: Date.now() - startTime,
|
|
19
|
+
error: 'TypeScript not installed. Install with: npm install --save-dev typescript',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Run tsc and capture diagnostics
|
|
23
|
+
const errors = await executeTypeScriptCheck(projectRoot);
|
|
24
|
+
// Convert to findings
|
|
25
|
+
const findings = parseTypeScriptErrors(errors);
|
|
26
|
+
return {
|
|
27
|
+
type: 'typescript',
|
|
28
|
+
status: findings.length > 0 ? 'success' : 'success',
|
|
29
|
+
findings,
|
|
30
|
+
executionTime: Date.now() - startTime,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
35
|
+
return {
|
|
36
|
+
type: 'typescript',
|
|
37
|
+
status: 'failure',
|
|
38
|
+
findings: [],
|
|
39
|
+
executionTime: Date.now() - startTime,
|
|
40
|
+
error: `TypeScript check failed: ${message}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if TypeScript is installed
|
|
46
|
+
*/
|
|
47
|
+
function isTypeScriptInstalled() {
|
|
48
|
+
try {
|
|
49
|
+
execSync('npm list typescript 2>/dev/null', { stdio: 'ignore' });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Execute TypeScript compiler and capture errors
|
|
58
|
+
*/
|
|
59
|
+
async function executeTypeScriptCheck(projectRoot) {
|
|
60
|
+
try {
|
|
61
|
+
// Run tsc with noEmit to check types without emitting
|
|
62
|
+
// The command may exit with non-zero code if errors found
|
|
63
|
+
execSync('npx tsc --noEmit 2>&1', {
|
|
64
|
+
cwd: projectRoot,
|
|
65
|
+
stdio: 'pipe',
|
|
66
|
+
});
|
|
67
|
+
// If we got here, no errors
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// Parse the error output
|
|
72
|
+
const output = error instanceof Error && 'stdout' in error
|
|
73
|
+
? error.stdout?.toString() ||
|
|
74
|
+
error.message
|
|
75
|
+
: String(error);
|
|
76
|
+
return parseTypeScriptOutput(output);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse TypeScript compiler output into structured errors
|
|
81
|
+
* Format: file.ts:line:col - error TS1234: message
|
|
82
|
+
*/
|
|
83
|
+
function parseTypeScriptOutput(output) {
|
|
84
|
+
const errors = [];
|
|
85
|
+
const lines = output.split('\n');
|
|
86
|
+
for (const line of lines) {
|
|
87
|
+
if (!line.trim())
|
|
88
|
+
continue;
|
|
89
|
+
// Match TypeScript error format: file:line:col - error TSxxxx: message
|
|
90
|
+
const match = line.match(/^(.+):(\d+):(\d+)\s*-\s*(error|warning)\s*TS(\d+):\s*(.+)$/);
|
|
91
|
+
if (match) {
|
|
92
|
+
const [, file, lineStr, colStr, severity, code, message] = match;
|
|
93
|
+
errors.push({
|
|
94
|
+
file,
|
|
95
|
+
line: parseInt(lineStr, 10),
|
|
96
|
+
column: parseInt(colStr, 10),
|
|
97
|
+
code: parseInt(code, 10),
|
|
98
|
+
message,
|
|
99
|
+
severity: severity || 'error',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return errors;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Convert TypeScript errors to standardized Finding format
|
|
107
|
+
*/
|
|
108
|
+
function parseTypeScriptErrors(errors) {
|
|
109
|
+
return errors
|
|
110
|
+
.map((error) => {
|
|
111
|
+
// Map common TypeScript error codes
|
|
112
|
+
const category = mapTypeScriptErrorCode(error.code);
|
|
113
|
+
return {
|
|
114
|
+
category,
|
|
115
|
+
severity: error.severity === 'error' ? 'error' : 'warning',
|
|
116
|
+
file: error.file,
|
|
117
|
+
line: error.line,
|
|
118
|
+
column: error.column,
|
|
119
|
+
message: error.message,
|
|
120
|
+
fixable: isTypeScriptFixable(),
|
|
121
|
+
suggestion: getTypeScriptSuggestion(error.code),
|
|
122
|
+
source: 'typescript',
|
|
123
|
+
rule: `TS${error.code}`,
|
|
124
|
+
};
|
|
125
|
+
})
|
|
126
|
+
.filter((f) =>
|
|
127
|
+
// Filter to only type-related errors that are relevant to dead code
|
|
128
|
+
f.rule !== 'TS6133' && // "is declared but never used" - covered by other tools
|
|
129
|
+
f.rule !== 'TS6138' // "are declared but never used" - covered by other tools
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Map TypeScript error code to dead code category
|
|
134
|
+
*/
|
|
135
|
+
function mapTypeScriptErrorCode(code) {
|
|
136
|
+
// 6133: variable declared but never used
|
|
137
|
+
// 6138: variables never used
|
|
138
|
+
// 7006: parameter never used
|
|
139
|
+
// 18004: type never used
|
|
140
|
+
// 2304: name not found
|
|
141
|
+
// 2307: cannot find module
|
|
142
|
+
if (code === 6133 || code === 6138)
|
|
143
|
+
return 'unused-var';
|
|
144
|
+
if (code === 7006)
|
|
145
|
+
return 'unused-param';
|
|
146
|
+
if (code === 18004)
|
|
147
|
+
return 'unused-export';
|
|
148
|
+
if (code === 2304 || code === 2307)
|
|
149
|
+
return 'type-error';
|
|
150
|
+
return 'type-error';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check if TypeScript error can be auto-fixed
|
|
154
|
+
*/
|
|
155
|
+
function isTypeScriptFixable() {
|
|
156
|
+
// Some TypeScript errors could theoretically be fixed
|
|
157
|
+
// but we'll be conservative and only mark known fixable ones
|
|
158
|
+
return false; // Default: not fixable via automation
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get suggestion for fixing TypeScript error
|
|
162
|
+
*/
|
|
163
|
+
function getTypeScriptSuggestion(code) {
|
|
164
|
+
const suggestions = {
|
|
165
|
+
6133: 'Remove the variable or use it in your code',
|
|
166
|
+
6138: 'Remove unused variables or use them',
|
|
167
|
+
7006: 'Remove the parameter or use it in the function',
|
|
168
|
+
18004: 'Remove the type definition or use it',
|
|
169
|
+
2304: 'Check that this name is defined and imported correctly',
|
|
170
|
+
2307: 'Verify the module path and that the package is installed',
|
|
171
|
+
};
|
|
172
|
+
return suggestions[code] || 'Fix this TypeScript error';
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=typescriptChecker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescriptChecker.js","sourceRoot":"","sources":["../../../src/checkers/typescriptChecker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAYzC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,W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CAAC;IACxD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC;IACzC,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,eAAe,CAAC;IAC3C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC;IAExD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB;IAC1B,sDAAsD;IACtD,6DAA6D;IAC7D,OAAO,KAAK,CAAC,CAAC,sCAAsC;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,IAAY;IAC3C,MAAM,WAAW,GAA2B;QAC1C,IAAI,EAAE,4CAA4C;QAClD,IAAI,EAAE,qCAAqC;QAC3C,IAAI,EAAE,gDAAgD;QACtD,KAAK,EAAE,sCAAsC;QAC7C,IAAI,EAAE,wDAAwD;QAC9D,IAAI,EAAE,0DAA0D;KACjE,CAAC;IAEF,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,2BAA2B,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project structure detection
|
|
3
|
+
* Auto-detects project type and configuration
|
|
4
|
+
*/
|
|
5
|
+
import type { ProjectConfig } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Detect project configuration and type
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectProjectConfig(projectRoot: string): ProjectConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Get entry points for a project based on its type
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEntryPoints(config: ProjectConfig): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Get project source patterns for Knip
|
|
16
|
+
*/
|
|
17
|
+
export declare function getProjectPatterns(config: ProjectConfig): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Get ignore patterns for Knip
|
|
20
|
+
*/
|
|
21
|
+
export declare function getIgnorePatterns(): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Get ESLint paths configuration
|
|
24
|
+
*/
|
|
25
|
+
export declare function getESLintPaths(config: ProjectConfig): {
|
|
26
|
+
include: string[];
|
|
27
|
+
exclude: string[];
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=detectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectors.d.ts","sourceRoot":"","sources":["../../../src/config/detectors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CA8EtE;AASD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAiC9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAqBlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAY5C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAK9F"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project structure detection
|
|
3
|
+
* Auto-detects project type and configuration
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync } from 'fs';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
/**
|
|
8
|
+
* Detect project configuration and type
|
|
9
|
+
*/
|
|
10
|
+
export function detectProjectConfig(projectRoot) {
|
|
11
|
+
const config = {
|
|
12
|
+
root: projectRoot,
|
|
13
|
+
hasPackageJson: false,
|
|
14
|
+
hasTypeScript: false,
|
|
15
|
+
type: 'unknown',
|
|
16
|
+
existingConfigs: {},
|
|
17
|
+
};
|
|
18
|
+
// Check for package.json
|
|
19
|
+
const packageJsonPath = resolve(projectRoot, 'package.json');
|
|
20
|
+
if (existsSync(packageJsonPath)) {
|
|
21
|
+
config.hasPackageJson = true;
|
|
22
|
+
try {
|
|
23
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
24
|
+
// Check for React
|
|
25
|
+
if (packageJson.dependencies?.react || packageJson.devDependencies?.react) {
|
|
26
|
+
config.type = 'react';
|
|
27
|
+
}
|
|
28
|
+
// Check for Node.js frameworks
|
|
29
|
+
else if (packageJson.dependencies?.express ||
|
|
30
|
+
packageJson.dependencies?.fastify ||
|
|
31
|
+
packageJson.dependencies?.['next.js'] ||
|
|
32
|
+
packageJson.dependencies?.nest ||
|
|
33
|
+
packageJson.devDependencies?.['@nestjs/core']) {
|
|
34
|
+
config.type = 'node';
|
|
35
|
+
}
|
|
36
|
+
// Default to Node for backend-only projects
|
|
37
|
+
else if (packageJson.type === 'module' && !packageJson.dependencies?.react) {
|
|
38
|
+
config.type = 'node';
|
|
39
|
+
}
|
|
40
|
+
// Check if it's a monorepo
|
|
41
|
+
if (packageJson.workspaces) {
|
|
42
|
+
config.type = 'fullstack';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (_error) {
|
|
46
|
+
// Ignore parsing errors
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Check for TypeScript
|
|
50
|
+
const tsconfigPath = resolve(projectRoot, 'tsconfig.json');
|
|
51
|
+
if (existsSync(tsconfigPath)) {
|
|
52
|
+
config.hasTypeScript = true;
|
|
53
|
+
config.tsconfigPath = tsconfigPath;
|
|
54
|
+
}
|
|
55
|
+
// Detect existing configs
|
|
56
|
+
const configFiles = [
|
|
57
|
+
{ key: 'eslint', names: ['.eslintrc.js', '.eslintrc.json', 'eslint.config.js'] },
|
|
58
|
+
{ key: 'prettier', names: ['.prettierrc', '.prettierrc.js', 'prettier.config.js'] },
|
|
59
|
+
{ key: 'knip', names: ['knip.json'] },
|
|
60
|
+
{ key: 'husky', names: ['.husky'] },
|
|
61
|
+
];
|
|
62
|
+
for (const { key, names } of configFiles) {
|
|
63
|
+
for (const name of names) {
|
|
64
|
+
const path = resolve(projectRoot, name);
|
|
65
|
+
if (existsSync(path)) {
|
|
66
|
+
config.existingConfigs[key] = path;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// If no type detected, infer from structure
|
|
72
|
+
if (config.type === 'unknown') {
|
|
73
|
+
if (hasSrcDirectory(projectRoot)) {
|
|
74
|
+
config.type = config.hasPackageJson ? 'node' : 'unknown';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return config;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if project has a src directory
|
|
81
|
+
*/
|
|
82
|
+
function hasSrcDirectory(projectRoot) {
|
|
83
|
+
return existsSync(resolve(projectRoot, 'src'));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get entry points for a project based on its type
|
|
87
|
+
*/
|
|
88
|
+
export function getEntryPoints(config) {
|
|
89
|
+
const entry = [];
|
|
90
|
+
const root = config.root;
|
|
91
|
+
switch (config.type) {
|
|
92
|
+
case 'react':
|
|
93
|
+
entry.push('src/main.ts', 'src/main.tsx', 'src/index.ts', 'src/index.tsx');
|
|
94
|
+
break;
|
|
95
|
+
case 'node':
|
|
96
|
+
// Common Node.js entry points
|
|
97
|
+
entry.push('src/index.ts', 'src/main.ts', 'dist/index.js', 'index.ts', 'api/index.ts');
|
|
98
|
+
break;
|
|
99
|
+
case 'fullstack':
|
|
100
|
+
// Monorepo: pick sensible defaults
|
|
101
|
+
entry.push('src/main.ts', 'src/index.ts', 'api/index.ts', 'backend/src/index.ts');
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
// Fallback
|
|
105
|
+
entry.push('src/index.ts', 'index.ts');
|
|
106
|
+
}
|
|
107
|
+
// Filter to entries that exist
|
|
108
|
+
const existingEntries = entry.filter((e) => existsSync(resolve(root, e)));
|
|
109
|
+
// If nothing found, add default globs
|
|
110
|
+
if (existingEntries.length === 0) {
|
|
111
|
+
existingEntries.push('src/index.ts');
|
|
112
|
+
}
|
|
113
|
+
return existingEntries;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get project source patterns for Knip
|
|
117
|
+
*/
|
|
118
|
+
export function getProjectPatterns(config) {
|
|
119
|
+
const patterns = [];
|
|
120
|
+
switch (config.type) {
|
|
121
|
+
case 'react':
|
|
122
|
+
patterns.push('src/**/*.{ts,tsx}');
|
|
123
|
+
break;
|
|
124
|
+
case 'node':
|
|
125
|
+
patterns.push('src/**/*.ts', 'api/**/*.ts', 'lib/**/*.ts');
|
|
126
|
+
break;
|
|
127
|
+
case 'fullstack':
|
|
128
|
+
patterns.push('src/**/*.{ts,tsx}', 'api/**/*.ts', 'backend/**/*.ts');
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
patterns.push('**/*.ts', '**/*.tsx');
|
|
132
|
+
}
|
|
133
|
+
return patterns;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get ignore patterns for Knip
|
|
137
|
+
*/
|
|
138
|
+
export function getIgnorePatterns() {
|
|
139
|
+
return [
|
|
140
|
+
'dist/**',
|
|
141
|
+
'build/**',
|
|
142
|
+
'node_modules/**',
|
|
143
|
+
'**/*.d.ts',
|
|
144
|
+
'**/node_modules/**',
|
|
145
|
+
'.next/**',
|
|
146
|
+
'out/**',
|
|
147
|
+
'coverage/**',
|
|
148
|
+
'.git/**',
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get ESLint paths configuration
|
|
153
|
+
*/
|
|
154
|
+
export function getESLintPaths(config) {
|
|
155
|
+
const include = getProjectPatterns(config);
|
|
156
|
+
const exclude = getIgnorePatterns();
|
|
157
|
+
return { include, exclude };
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=detectors.js.map
|
|
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
+
*/
|
|
5
|
+
import type { ProjectConfig } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate knip.json configuration
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateKnipConfig(config: ProjectConfig): Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Generate knip.json as JSON string
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateKnipConfigJSON(config: ProjectConfig): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate ESLint configuration partial (rules to add)
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateESLintRules(): Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Generate ESLint configuration as JavaScript code
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateESLintConfigCode(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Generate typecoveragerc.json configuration
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateTypeCoverageConfig(config: ProjectConfig): Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Generate typecoveragerc.json as JSON string
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateTypeCoverageConfigJSON(config: ProjectConfig): string;
|
|
30
|
+
/**
|
|
31
|
+
* Generate .lintstagedrc.json configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateLintStagedConfig(): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate .lintstagedrc.json as JSON string
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateLintStagedConfigJSON(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Generate pre-commit hook script
|
|
40
|
+
*/
|
|
41
|
+
export declare function generatePreCommitHook(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Generate package.json scripts to add
|
|
44
|
+
*/
|
|
45
|
+
export declare function generatePackageJsonScripts(): Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Configuration templates metadata
|
|
48
|
+
*/
|
|
49
|
+
export declare const CONFIG_TEMPLATES: {
|
|
50
|
+
readonly knip: {
|
|
51
|
+
readonly filename: "knip.json";
|
|
52
|
+
readonly description: "Knip configuration for dead code detection";
|
|
53
|
+
readonly generator: typeof generateKnipConfigJSON;
|
|
54
|
+
};
|
|
55
|
+
readonly eslint: {
|
|
56
|
+
readonly filename: "eslint.config.js (partial - add to existing config)";
|
|
57
|
+
readonly description: "ESLint rules for dead code detection";
|
|
58
|
+
readonly generator: typeof generateESLintConfigCode;
|
|
59
|
+
};
|
|
60
|
+
readonly typeCoverage: {
|
|
61
|
+
readonly filename: "typecoveragerc.json";
|
|
62
|
+
readonly description: "Type coverage measurement configuration";
|
|
63
|
+
readonly generator: typeof generateTypeCoverageConfigJSON;
|
|
64
|
+
};
|
|
65
|
+
readonly lintStaged: {
|
|
66
|
+
readonly filename: ".lintstagedrc.json";
|
|
67
|
+
readonly description: "Lint-staged configuration for staged files";
|
|
68
|
+
readonly generator: typeof generateLintStagedConfigJSON;
|
|
69
|
+
};
|
|
70
|
+
readonly preCommit: {
|
|
71
|
+
readonly filename: ".husky/pre-commit";
|
|
72
|
+
readonly description: "Pre-commit hook script";
|
|
73
|
+
readonly generator: typeof generatePreCommitHook;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAcjF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAY7D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAmBjD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazF;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAKlE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAuC9C;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASnE;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BnB,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration file templates
|
|
3
|
+
* Generates default configs for Knip, ESLint, etc.
|
|
4
|
+
*/
|
|
5
|
+
import { getEntryPoints, getProjectPatterns, getIgnorePatterns } from './detectors.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate knip.json configuration
|
|
8
|
+
*/
|
|
9
|
+
export function generateKnipConfig(config) {
|
|
10
|
+
const entryPoints = getEntryPoints(config);
|
|
11
|
+
const patterns = getProjectPatterns(config);
|
|
12
|
+
const ignorePatterns = getIgnorePatterns();
|
|
13
|
+
return {
|
|
14
|
+
entry: entryPoints,
|
|
15
|
+
project: patterns,
|
|
16
|
+
ignore: ignorePatterns,
|
|
17
|
+
ignoreDependencies: [
|
|
18
|
+
'@types/node', // Type definitions are not "used"
|
|
19
|
+
'typescript', // Compiler is not "used" in code
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate knip.json as JSON string
|
|
25
|
+
*/
|
|
26
|
+
export function generateKnipConfigJSON(config) {
|
|
27
|
+
return JSON.stringify(generateKnipConfig(config), null, 2);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generate ESLint configuration partial (rules to add)
|
|
31
|
+
*/
|
|
32
|
+
export function generateESLintRules() {
|
|
33
|
+
return {
|
|
34
|
+
'@typescript-eslint/no-redundant-type-constituents': 'warn',
|
|
35
|
+
'@typescript-eslint/no-unused-vars': [
|
|
36
|
+
'warn',
|
|
37
|
+
{
|
|
38
|
+
argsIgnorePattern: '^_',
|
|
39
|
+
varsIgnorePattern: '^_',
|
|
40
|
+
caughtErrorsIgnorePattern: '^_',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate ESLint configuration as JavaScript code
|
|
47
|
+
*/
|
|
48
|
+
export function generateESLintConfigCode() {
|
|
49
|
+
return `// Add to eslint.config.js or update your existing config
|
|
50
|
+
export default [
|
|
51
|
+
// ... existing configs ...
|
|
52
|
+
{
|
|
53
|
+
files: ['src/**/*.{ts,tsx}', 'api/**/*.ts'],
|
|
54
|
+
rules: {
|
|
55
|
+
'@typescript-eslint/no-redundant-type-constituents': 'warn',
|
|
56
|
+
'@typescript-eslint/no-unused-vars': [
|
|
57
|
+
'warn',
|
|
58
|
+
{
|
|
59
|
+
argsIgnorePattern: '^_',
|
|
60
|
+
varsIgnorePattern: '^_',
|
|
61
|
+
caughtErrorsIgnorePattern: '^_',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate typecoveragerc.json configuration
|
|
70
|
+
*/
|
|
71
|
+
export function generateTypeCoverageConfig(config) {
|
|
72
|
+
const patterns = getProjectPatterns(config);
|
|
73
|
+
return {
|
|
74
|
+
files: patterns,
|
|
75
|
+
ignore: getIgnorePatterns(),
|
|
76
|
+
ignoreFiles: ['**/*.d.ts', '**/node_modules/**'],
|
|
77
|
+
ignoreCatch: true,
|
|
78
|
+
skipLibCheck: true,
|
|
79
|
+
checkPropertyAccess: true,
|
|
80
|
+
strict: true,
|
|
81
|
+
suppressError: false,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate typecoveragerc.json as JSON string
|
|
86
|
+
*/
|
|
87
|
+
export function generateTypeCoverageConfigJSON(config) {
|
|
88
|
+
return JSON.stringify(generateTypeCoverageConfig(config), null, 2);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate .lintstagedrc.json configuration
|
|
92
|
+
*/
|
|
93
|
+
export function generateLintStagedConfig() {
|
|
94
|
+
return {
|
|
95
|
+
'*.{ts,tsx}': ['eslint --fix'],
|
|
96
|
+
'*.{json,md}': ['prettier --write'],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generate .lintstagedrc.json as JSON string
|
|
101
|
+
*/
|
|
102
|
+
export function generateLintStagedConfigJSON() {
|
|
103
|
+
return JSON.stringify(generateLintStagedConfig(), null, 2);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generate pre-commit hook script
|
|
107
|
+
*/
|
|
108
|
+
export function generatePreCommitHook() {
|
|
109
|
+
return `#!/bin/sh
|
|
110
|
+
# Pre-commit hook for dead code and quality checks
|
|
111
|
+
# Generated by @mathonsunday/dead-code-toolkit
|
|
112
|
+
|
|
113
|
+
set -e
|
|
114
|
+
|
|
115
|
+
echo "[Dead Code Toolkit] Running pre-commit checks..."
|
|
116
|
+
|
|
117
|
+
# Stage 1: lint-staged (on staged files only)
|
|
118
|
+
echo "[Stage 1/4] Running lint-staged (ESLint + Prettier)..."
|
|
119
|
+
npx lint-staged || {
|
|
120
|
+
echo "❌ Lint-staged failed"
|
|
121
|
+
exit 1
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
# Stage 2: Full type check
|
|
125
|
+
echo "[Stage 2/4] Running TypeScript type check..."
|
|
126
|
+
npm run type-check || {
|
|
127
|
+
echo "❌ Type check failed"
|
|
128
|
+
exit 1
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# Stage 3: Dead code detection (optional - doesn't block on failure)
|
|
132
|
+
echo "[Stage 3/4] Checking for dead code..."
|
|
133
|
+
npm run dead-code || {
|
|
134
|
+
echo "⚠️ Dead code detected. Consider running: npm run dead-code:fix"
|
|
135
|
+
# Don't exit - just warn
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Stage 4: Run tests
|
|
139
|
+
echo "[Stage 4/4] Running tests..."
|
|
140
|
+
npm test -- --run || {
|
|
141
|
+
echo "❌ Tests failed"
|
|
142
|
+
exit 1
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
echo "✅ All pre-commit checks passed!"
|
|
146
|
+
exit 0`;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Generate package.json scripts to add
|
|
150
|
+
*/
|
|
151
|
+
export function generatePackageJsonScripts() {
|
|
152
|
+
return {
|
|
153
|
+
'dead-code': 'knip',
|
|
154
|
+
'dead-code:fix': 'knip --fix',
|
|
155
|
+
'dead-code:analyze': 'dead-code-toolkit analyze',
|
|
156
|
+
'type:coverage': 'type-coverage --detail --strict',
|
|
157
|
+
'type:report': 'typescript-coverage-report',
|
|
158
|
+
verify: 'npm run type-check && npm run lint && npm run dead-code && npm test',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Configuration templates metadata
|
|
163
|
+
*/
|
|
164
|
+
export const CONFIG_TEMPLATES = {
|
|
165
|
+
knip: {
|
|
166
|
+
filename: 'knip.json',
|
|
167
|
+
description: 'Knip configuration for dead code detection',
|
|
168
|
+
generator: generateKnipConfigJSON,
|
|
169
|
+
},
|
|
170
|
+
eslint: {
|
|
171
|
+
filename: 'eslint.config.js (partial - add to existing config)',
|
|
172
|
+
description: 'ESLint rules for dead code detection',
|
|
173
|
+
generator: generateESLintConfigCode,
|
|
174
|
+
},
|
|
175
|
+
typeCoverage: {
|
|
176
|
+
filename: 'typecoveragerc.json',
|
|
177
|
+
description: 'Type coverage measurement configuration',
|
|
178
|
+
generator: generateTypeCoverageConfigJSON,
|
|
179
|
+
},
|
|
180
|
+
lintStaged: {
|
|
181
|
+
filename: '.lintstagedrc.json',
|
|
182
|
+
description: 'Lint-staged configuration for staged files',
|
|
183
|
+
generator: generateLintStagedConfigJSON,
|
|
184
|
+
},
|
|
185
|
+
preCommit: {
|
|
186
|
+
filename: '.husky/pre-commit',
|
|
187
|
+
description: 'Pre-commit hook script',
|
|
188
|
+
generator: generatePreCommitHook,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/config/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvF;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAqB;IACtD,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAE3C,OAAO;QACL,KAAK,EAAE,WAAW;QAClB,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE,cAAc;QACtB,kBAAkB,EAAE;YAClB,aAAa,EAAE,kCAAkC;YACjD,YAAY,EAAE,iCAAiC;SAChD;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAqB;IAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC7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;;;;;;;;;;;;;OAqCF,CAAC;AACR,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,WAAW,EAAE,MAAM;QACnB,eAAe,EAAE,YAAY;QAC7B,mBAAmB,EAAE,2BAA2B;QAChD,eAAe,EAAE,iCAAiC;QAClD,aAAa,EAAE,4BAA4B;QAC3C,MAAM,EAAE,qEAAqE;KAC9E,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE;QACJ,QAAQ,EAAE,WAAW;QACrB,WAAW,EAAE,4CAA4C;QACzD,SAAS,EAAE,sBAAsB;KAClC;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,qDAAqD;QAC/D,WAAW,EAAE,sCAAsC;QACnD,SAAS,EAAE,wBAAwB;KACpC;IACD,YAAY,EAAE;QACZ,QAAQ,EAAE,qBAAqB;QAC/B,WAAW,EAAE,yCAAyC;QACtD,SAAS,EAAE,8BAA8B;KAC1C;IACD,UAAU,EAAE;QACV,QAAQ,EAAE,oBAAoB;QAC9B,WAAW,EAAE,4CAA4C;QACzD,SAAS,EAAE,4BAA4B;KACxC;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,mBAAmB;QAC7B,WAAW,EAAE,wBAAwB;QACrC,SAAS,EAAE,qBAAqB;KACjC;CACO,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for dead code toolkit
|
|
3
|
+
* Exports public API for programmatic usage
|
|
4
|
+
*/
|
|
5
|
+
export { analyzeDeadCode, fixFindings } from './analyzer.js';
|
|
6
|
+
export type { AnalysisOptions, AnalysisResult, AnalysisSummary, CheckResult, CheckType, Finding, FixResult, FixDetail, SetupOptions, SetupResult, ProjectConfig, } from './types.js';
|
|
7
|
+
export { createJSONReport, formatJSONReport, formatJSONReportCompact, createLLMSummary, type JSONReport, type JSONFinding, type LLMSummaryReport, } from './reporters/jsonReporter.js';
|
|
8
|
+
export { runKnipCheck } from './checkers/knipChecker.js';
|
|
9
|
+
export { runTypeScriptCheck } from './checkers/typescriptChecker.js';
|
|
10
|
+
export { setupProject } from './setup/installer.js';
|
|
11
|
+
export { detectProjectConfig, getEntryPoints, getProjectPatterns } from './config/detectors.js';
|
|
12
|
+
export { generateKnipConfig, generateESLintRules, generateTypeCoverageConfig, generateLintStagedConfig, generatePackageJsonScripts, } from './config/templates.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|