eff-u-code 2.0.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/LICENSE +21 -0
- package/README.md +256 -0
- package/bin/fuck-u-code-mcp.js +2 -0
- package/bin/fuck-u-code.js +2 -0
- package/bin/postinstall.js +53 -0
- package/dist/ai/index.d.ts +34 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +227 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/prompts/code-review.d.ts +9 -0
- package/dist/ai/prompts/code-review.d.ts.map +1 -0
- package/dist/ai/prompts/code-review.js +61 -0
- package/dist/ai/prompts/code-review.js.map +1 -0
- package/dist/ai/providers/anthropic.d.ts +11 -0
- package/dist/ai/providers/anthropic.d.ts.map +1 -0
- package/dist/ai/providers/anthropic.js +60 -0
- package/dist/ai/providers/anthropic.js.map +1 -0
- package/dist/ai/providers/fetch.d.ts +10 -0
- package/dist/ai/providers/fetch.d.ts.map +1 -0
- package/dist/ai/providers/fetch.js +50 -0
- package/dist/ai/providers/fetch.js.map +1 -0
- package/dist/ai/providers/gemini.d.ts +12 -0
- package/dist/ai/providers/gemini.d.ts.map +1 -0
- package/dist/ai/providers/gemini.js +66 -0
- package/dist/ai/providers/gemini.js.map +1 -0
- package/dist/ai/providers/ollama.d.ts +11 -0
- package/dist/ai/providers/ollama.d.ts.map +1 -0
- package/dist/ai/providers/ollama.js +54 -0
- package/dist/ai/providers/ollama.js.map +1 -0
- package/dist/ai/providers/openai.d.ts +11 -0
- package/dist/ai/providers/openai.d.ts.map +1 -0
- package/dist/ai/providers/openai.js +52 -0
- package/dist/ai/providers/openai.js.map +1 -0
- package/dist/ai/selector.d.ts +19 -0
- package/dist/ai/selector.d.ts.map +1 -0
- package/dist/ai/selector.js +145 -0
- package/dist/ai/selector.js.map +1 -0
- package/dist/ai/types.d.ts +120 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +6 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/analyzer/concurrent-analyzer.d.ts +11 -0
- package/dist/analyzer/concurrent-analyzer.d.ts.map +1 -0
- package/dist/analyzer/concurrent-analyzer.js +67 -0
- package/dist/analyzer/concurrent-analyzer.js.map +1 -0
- package/dist/analyzer/file-discovery.d.ts +23 -0
- package/dist/analyzer/file-discovery.d.ts.map +1 -0
- package/dist/analyzer/file-discovery.js +64 -0
- package/dist/analyzer/file-discovery.js.map +1 -0
- package/dist/analyzer/index.d.ts +27 -0
- package/dist/analyzer/index.d.ts.map +1 -0
- package/dist/analyzer/index.js +64 -0
- package/dist/analyzer/index.js.map +1 -0
- package/dist/cli/commands/ai-review.d.ts +6 -0
- package/dist/cli/commands/ai-review.d.ts.map +1 -0
- package/dist/cli/commands/ai-review.js +213 -0
- package/dist/cli/commands/ai-review.js.map +1 -0
- package/dist/cli/commands/analyze.d.ts +6 -0
- package/dist/cli/commands/analyze.d.ts.map +1 -0
- package/dist/cli/commands/analyze.js +145 -0
- package/dist/cli/commands/analyze.js.map +1 -0
- package/dist/cli/commands/config.d.ts +6 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +147 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/mcp-install.d.ts +9 -0
- package/dist/cli/commands/mcp-install.d.ts.map +1 -0
- package/dist/cli/commands/mcp-install.js +102 -0
- package/dist/cli/commands/mcp-install.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 +69 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/output/ai-review-output.d.ts +20 -0
- package/dist/cli/output/ai-review-output.d.ts.map +1 -0
- package/dist/cli/output/ai-review-output.js +324 -0
- package/dist/cli/output/ai-review-output.js.map +1 -0
- package/dist/cli/output/console.d.ts +31 -0
- package/dist/cli/output/console.d.ts.map +1 -0
- package/dist/cli/output/console.js +571 -0
- package/dist/cli/output/console.js.map +1 -0
- package/dist/cli/output/html.d.ts +20 -0
- package/dist/cli/output/html.d.ts.map +1 -0
- package/dist/cli/output/html.js +339 -0
- package/dist/cli/output/html.js.map +1 -0
- package/dist/cli/output/json.d.ts +8 -0
- package/dist/cli/output/json.d.ts.map +1 -0
- package/dist/cli/output/json.js +46 -0
- package/dist/cli/output/json.js.map +1 -0
- package/dist/cli/output/markdown.d.ts +17 -0
- package/dist/cli/output/markdown.d.ts.map +1 -0
- package/dist/cli/output/markdown.js +323 -0
- package/dist/cli/output/markdown.js.map +1 -0
- package/dist/cli/output/stats.d.ts +35 -0
- package/dist/cli/output/stats.d.ts.map +1 -0
- package/dist/cli/output/stats.js +63 -0
- package/dist/cli/output/stats.js.map +1 -0
- package/dist/cli/output/terminal-markdown.d.ts +23 -0
- package/dist/cli/output/terminal-markdown.d.ts.map +1 -0
- package/dist/cli/output/terminal-markdown.js +159 -0
- package/dist/cli/output/terminal-markdown.js.map +1 -0
- package/dist/config/index.d.ts +27 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +266 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +179 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +85 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/gitignore/index.d.ts +5 -0
- package/dist/gitignore/index.d.ts.map +1 -0
- package/dist/gitignore/index.js +5 -0
- package/dist/gitignore/index.js.map +1 -0
- package/dist/gitignore/parser.d.ts +32 -0
- package/dist/gitignore/parser.d.ts.map +1 -0
- package/dist/gitignore/parser.js +110 -0
- package/dist/gitignore/parser.js.map +1 -0
- package/dist/gitignore/parser.test.d.ts +2 -0
- package/dist/gitignore/parser.test.d.ts.map +1 -0
- package/dist/gitignore/parser.test.js +217 -0
- package/dist/gitignore/parser.test.js.map +1 -0
- package/dist/i18n/index.d.ts +19 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +43 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/locales/en.json +320 -0
- package/dist/i18n/locales/ru.json +320 -0
- package/dist/i18n/locales/zh.json +320 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +156 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/metrics/complexity/cognitive.d.ts +25 -0
- package/dist/metrics/complexity/cognitive.d.ts.map +1 -0
- package/dist/metrics/complexity/cognitive.js +109 -0
- package/dist/metrics/complexity/cognitive.js.map +1 -0
- package/dist/metrics/complexity/cyclomatic.d.ts +21 -0
- package/dist/metrics/complexity/cyclomatic.d.ts.map +1 -0
- package/dist/metrics/complexity/cyclomatic.js +111 -0
- package/dist/metrics/complexity/cyclomatic.js.map +1 -0
- package/dist/metrics/complexity/nesting-depth.d.ts +19 -0
- package/dist/metrics/complexity/nesting-depth.d.ts.map +1 -0
- package/dist/metrics/complexity/nesting-depth.js +97 -0
- package/dist/metrics/complexity/nesting-depth.js.map +1 -0
- package/dist/metrics/documentation/comment-ratio.d.ts +21 -0
- package/dist/metrics/documentation/comment-ratio.d.ts.map +1 -0
- package/dist/metrics/documentation/comment-ratio.js +91 -0
- package/dist/metrics/documentation/comment-ratio.js.map +1 -0
- package/dist/metrics/duplication/code-duplication.d.ts +24 -0
- package/dist/metrics/duplication/code-duplication.d.ts.map +1 -0
- package/dist/metrics/duplication/code-duplication.js +167 -0
- package/dist/metrics/duplication/code-duplication.js.map +1 -0
- package/dist/metrics/duplication/code-duplication.test.d.ts +2 -0
- package/dist/metrics/duplication/code-duplication.test.d.ts.map +1 -0
- package/dist/metrics/duplication/code-duplication.test.js +612 -0
- package/dist/metrics/duplication/code-duplication.test.js.map +1 -0
- package/dist/metrics/error/error-handling.d.ts +23 -0
- package/dist/metrics/error/error-handling.d.ts.map +1 -0
- package/dist/metrics/error/error-handling.js +164 -0
- package/dist/metrics/error/error-handling.js.map +1 -0
- package/dist/metrics/error/error-handling.test.d.ts +2 -0
- package/dist/metrics/error/error-handling.test.d.ts.map +1 -0
- package/dist/metrics/error/error-handling.test.js +349 -0
- package/dist/metrics/error/error-handling.test.js.map +1 -0
- package/dist/metrics/index.d.ts +21 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +50 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/naming/convention.d.ts +22 -0
- package/dist/metrics/naming/convention.d.ts.map +1 -0
- package/dist/metrics/naming/convention.js +117 -0
- package/dist/metrics/naming/convention.js.map +1 -0
- package/dist/metrics/size/file-length.d.ts +19 -0
- package/dist/metrics/size/file-length.d.ts.map +1 -0
- package/dist/metrics/size/file-length.js +68 -0
- package/dist/metrics/size/file-length.js.map +1 -0
- package/dist/metrics/size/function-length.d.ts +20 -0
- package/dist/metrics/size/function-length.d.ts.map +1 -0
- package/dist/metrics/size/function-length.js +101 -0
- package/dist/metrics/size/function-length.js.map +1 -0
- package/dist/metrics/size/parameter-count.d.ts +19 -0
- package/dist/metrics/size/parameter-count.d.ts.map +1 -0
- package/dist/metrics/size/parameter-count.js +97 -0
- package/dist/metrics/size/parameter-count.js.map +1 -0
- package/dist/metrics/structure/structure-analysis.d.ts +24 -0
- package/dist/metrics/structure/structure-analysis.d.ts.map +1 -0
- package/dist/metrics/structure/structure-analysis.js +223 -0
- package/dist/metrics/structure/structure-analysis.js.map +1 -0
- package/dist/metrics/structure/structure-analysis.test.d.ts +2 -0
- package/dist/metrics/structure/structure-analysis.test.d.ts.map +1 -0
- package/dist/metrics/structure/structure-analysis.test.js +342 -0
- package/dist/metrics/structure/structure-analysis.test.js.map +1 -0
- package/dist/metrics/types.d.ts +71 -0
- package/dist/metrics/types.d.ts.map +1 -0
- package/dist/metrics/types.js +5 -0
- package/dist/metrics/types.js.map +1 -0
- package/dist/parser/generic-parser.d.ts +28 -0
- package/dist/parser/generic-parser.d.ts.map +1 -0
- package/dist/parser/generic-parser.js +218 -0
- package/dist/parser/generic-parser.js.map +1 -0
- package/dist/parser/index.d.ts +19 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +52 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/regex-parser.d.ts +46 -0
- package/dist/parser/regex-parser.d.ts.map +1 -0
- package/dist/parser/regex-parser.js +560 -0
- package/dist/parser/regex-parser.js.map +1 -0
- package/dist/parser/tree-sitter-parser.d.ts +50 -0
- package/dist/parser/tree-sitter-parser.d.ts.map +1 -0
- package/dist/parser/tree-sitter-parser.js +707 -0
- package/dist/parser/tree-sitter-parser.js.map +1 -0
- package/dist/parser/types.d.ts +52 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +49 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/scoring/index.d.ts +14 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +80 -0
- package/dist/scoring/index.js.map +1 -0
- package/dist/utils/fs.d.ts +24 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +61 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +43 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown.d.ts +16 -0
- package/dist/utils/markdown.d.ts.map +1 -0
- package/dist/utils/markdown.js +303 -0
- package/dist/utils/markdown.js.map +1 -0
- package/dist/utils/progress.d.ts +24 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +79 -0
- package/dist/utils/progress.js.map +1 -0
- package/dist/utils/terminal.d.ts +62 -0
- package/dist/utils/terminal.d.ts.map +1 -0
- package/dist/utils/terminal.js +207 -0
- package/dist/utils/terminal.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling metric
|
|
3
|
+
*
|
|
4
|
+
* Detects ignored errors and unhandled error-prone API calls.
|
|
5
|
+
*
|
|
6
|
+
* Industry thresholds (based on Go error handling, SonarQube):
|
|
7
|
+
* - 0-5%: Excellent, nearly all errors handled
|
|
8
|
+
* - 5-15%: Good, most errors handled
|
|
9
|
+
* - 15-30%: Moderate, many errors ignored
|
|
10
|
+
* - 30%+: Poor, critical errors likely missed
|
|
11
|
+
*/
|
|
12
|
+
import { t } from '../../i18n/index.js';
|
|
13
|
+
const THRESHOLDS = {
|
|
14
|
+
EXCELLENT: 5,
|
|
15
|
+
GOOD: 15,
|
|
16
|
+
ACCEPTABLE: 30,
|
|
17
|
+
POOR: 50,
|
|
18
|
+
};
|
|
19
|
+
const ERROR_PRONE_PATTERNS = [
|
|
20
|
+
/\b(open|read|write|close|create|remove|rename|mkdir|readFile|writeFile|readdir|stat|access)\s*\(/,
|
|
21
|
+
/\b(fetch|get|post|put|delete|request|send|connect|listen|accept)\s*\(/,
|
|
22
|
+
/\b(parse|stringify|marshal|unmarshal|decode|encode)\s*\(/,
|
|
23
|
+
/\b(query|exec|execute|prepare|transaction|commit|rollback)\s*\(/,
|
|
24
|
+
];
|
|
25
|
+
export class ErrorHandlingMetric {
|
|
26
|
+
name = 'error_handling';
|
|
27
|
+
category = 'error';
|
|
28
|
+
weight;
|
|
29
|
+
constructor(weight) {
|
|
30
|
+
this.weight = weight;
|
|
31
|
+
}
|
|
32
|
+
calculate(parseResult) {
|
|
33
|
+
const { functions, filePath, content } = parseResult;
|
|
34
|
+
if (functions.length === 0 || !content) {
|
|
35
|
+
return {
|
|
36
|
+
name: this.name,
|
|
37
|
+
category: this.category,
|
|
38
|
+
value: 0,
|
|
39
|
+
normalizedScore: 100,
|
|
40
|
+
severity: 'info',
|
|
41
|
+
details: t('detail_no_functions'),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const { errorProneCallCount, locations } = this.analyzeErrorHandling(content, filePath);
|
|
45
|
+
if (errorProneCallCount === 0) {
|
|
46
|
+
return {
|
|
47
|
+
name: this.name,
|
|
48
|
+
category: this.category,
|
|
49
|
+
value: 0,
|
|
50
|
+
normalizedScore: 100,
|
|
51
|
+
severity: 'info',
|
|
52
|
+
details: t('detail_no_error_prone_calls'),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const ignoredCount = locations.length;
|
|
56
|
+
const ignoredPercent = (ignoredCount / errorProneCallCount) * 100;
|
|
57
|
+
let normalizedScore;
|
|
58
|
+
if (ignoredPercent <= THRESHOLDS.EXCELLENT) {
|
|
59
|
+
normalizedScore = 100;
|
|
60
|
+
}
|
|
61
|
+
else if (ignoredPercent <= THRESHOLDS.GOOD) {
|
|
62
|
+
normalizedScore =
|
|
63
|
+
100 -
|
|
64
|
+
((ignoredPercent - THRESHOLDS.EXCELLENT) / (THRESHOLDS.GOOD - THRESHOLDS.EXCELLENT)) * 20;
|
|
65
|
+
}
|
|
66
|
+
else if (ignoredPercent <= THRESHOLDS.ACCEPTABLE) {
|
|
67
|
+
normalizedScore =
|
|
68
|
+
80 - ((ignoredPercent - THRESHOLDS.GOOD) / (THRESHOLDS.ACCEPTABLE - THRESHOLDS.GOOD)) * 35;
|
|
69
|
+
}
|
|
70
|
+
else if (ignoredPercent <= THRESHOLDS.POOR) {
|
|
71
|
+
normalizedScore =
|
|
72
|
+
45 -
|
|
73
|
+
((ignoredPercent - THRESHOLDS.ACCEPTABLE) / (THRESHOLDS.POOR - THRESHOLDS.ACCEPTABLE)) * 30;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
normalizedScore = Math.max(0, 15 * Math.exp(-(ignoredPercent - THRESHOLDS.POOR) / 20));
|
|
77
|
+
}
|
|
78
|
+
let severity;
|
|
79
|
+
if (ignoredPercent <= THRESHOLDS.EXCELLENT) {
|
|
80
|
+
severity = 'info';
|
|
81
|
+
}
|
|
82
|
+
else if (ignoredPercent <= THRESHOLDS.GOOD) {
|
|
83
|
+
severity = 'warning';
|
|
84
|
+
}
|
|
85
|
+
else if (ignoredPercent <= THRESHOLDS.ACCEPTABLE) {
|
|
86
|
+
severity = 'error';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
severity = 'critical';
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
name: this.name,
|
|
93
|
+
category: this.category,
|
|
94
|
+
value: ignoredPercent,
|
|
95
|
+
normalizedScore: Math.round(normalizedScore * 10) / 10,
|
|
96
|
+
severity,
|
|
97
|
+
details: t('detail_errors_ignored', {
|
|
98
|
+
ignored: ignoredCount,
|
|
99
|
+
total: errorProneCallCount,
|
|
100
|
+
percent: ignoredPercent.toFixed(1),
|
|
101
|
+
}),
|
|
102
|
+
locations: locations.length > 0 ? locations : undefined,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
analyzeErrorHandling(content, filePath) {
|
|
106
|
+
const lines = content.split('\n');
|
|
107
|
+
const locations = [];
|
|
108
|
+
let errorProneCallCount = 0;
|
|
109
|
+
let insideTryCatch = 0;
|
|
110
|
+
for (let i = 0; i < lines.length; i++) {
|
|
111
|
+
const line = lines[i];
|
|
112
|
+
if (!line)
|
|
113
|
+
continue;
|
|
114
|
+
const trimmed = line.trim();
|
|
115
|
+
// Track try-catch block depth
|
|
116
|
+
if (/\btry\s*\{/.test(trimmed)) {
|
|
117
|
+
insideTryCatch++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (/\bcatch\s*[({]/.test(trimmed)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (insideTryCatch > 0 && trimmed === '}') {
|
|
124
|
+
insideTryCatch--;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Skip lines that are error handling themselves
|
|
128
|
+
if (/\.(catch|then)\s*\(/.test(trimmed) || /\bthrow\b/.test(trimmed)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!this.isErrorProneCall(trimmed))
|
|
132
|
+
continue;
|
|
133
|
+
errorProneCallCount++;
|
|
134
|
+
// Inside try-catch: considered handled
|
|
135
|
+
if (insideTryCatch > 0)
|
|
136
|
+
continue;
|
|
137
|
+
const lineNum = i + 1;
|
|
138
|
+
// Ignored with underscore assignment: _ = readFile(...)
|
|
139
|
+
if (/\b_\s*[=:]/.test(trimmed)) {
|
|
140
|
+
locations.push({
|
|
141
|
+
filePath,
|
|
142
|
+
line: lineNum,
|
|
143
|
+
message: t('issue_ignored_error'),
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
// Unhandled: bare call without assignment or return
|
|
148
|
+
if (!/\b(const|let|var)\s+\w/.test(trimmed) &&
|
|
149
|
+
!/\breturn\b/.test(trimmed) &&
|
|
150
|
+
!trimmed.includes('=')) {
|
|
151
|
+
locations.push({
|
|
152
|
+
filePath,
|
|
153
|
+
line: lineNum,
|
|
154
|
+
message: t('issue_unhandled_error'),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { errorProneCallCount, locations };
|
|
159
|
+
}
|
|
160
|
+
isErrorProneCall(line) {
|
|
161
|
+
return ERROR_PRONE_PATTERNS.some((pattern) => pattern.test(line));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=error-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.js","sourceRoot":"","sources":["../../../src/metrics/error/error-handling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAExC,MAAM,UAAU,GAAG;IACjB,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,EAAE;IACR,UAAU,EAAE,EAAE;IACd,IAAI,EAAE,EAAE;CACA,CAAC;AAEX,MAAM,oBAAoB,GAAG;IAC3B,kGAAkG;IAClG,uEAAuE;IACvE,0DAA0D;IAC1D,iEAAiE;CAClE,CAAC;AAEF,MAAM,OAAO,mBAAmB;IACrB,IAAI,G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../../../src/metrics/error/error-handling.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { ErrorHandlingMetric } from './error-handling.js';
|
|
3
|
+
describe('ErrorHandlingMetric', () => {
|
|
4
|
+
const metric = new ErrorHandlingMetric(0.08);
|
|
5
|
+
const createParseResult = (content, functionCount = 1) => ({
|
|
6
|
+
filePath: '/test/file.ts',
|
|
7
|
+
language: 'typescript',
|
|
8
|
+
functions: Array.from({ length: functionCount }, (_, i) => ({
|
|
9
|
+
name: `func${i}`,
|
|
10
|
+
startLine: i * 10 + 1,
|
|
11
|
+
endLine: i * 10 + 5,
|
|
12
|
+
lineCount: 5,
|
|
13
|
+
complexity: 1,
|
|
14
|
+
parameterCount: 0,
|
|
15
|
+
nestingDepth: 1,
|
|
16
|
+
hasDocstring: false,
|
|
17
|
+
})),
|
|
18
|
+
totalLines: 100,
|
|
19
|
+
codeLines: 80,
|
|
20
|
+
commentLines: 10,
|
|
21
|
+
blankLines: 10,
|
|
22
|
+
classes: [],
|
|
23
|
+
imports: [],
|
|
24
|
+
errors: [],
|
|
25
|
+
content,
|
|
26
|
+
});
|
|
27
|
+
describe('calculate', () => {
|
|
28
|
+
it('should return info severity when no functions', () => {
|
|
29
|
+
const result = metric.calculate({
|
|
30
|
+
...createParseResult('', 0),
|
|
31
|
+
functions: [],
|
|
32
|
+
});
|
|
33
|
+
expect(result.severity).toBe('info');
|
|
34
|
+
expect(result.normalizedScore).toBe(100);
|
|
35
|
+
expect(result.value).toBe(0);
|
|
36
|
+
});
|
|
37
|
+
it('should return info severity when content not available', () => {
|
|
38
|
+
const parseResult = createParseResult('', 1);
|
|
39
|
+
delete parseResult.content;
|
|
40
|
+
const result = metric.calculate(parseResult);
|
|
41
|
+
expect(result.severity).toBe('info');
|
|
42
|
+
expect(result.normalizedScore).toBe(100);
|
|
43
|
+
});
|
|
44
|
+
it('should return info severity when no error-prone calls detected', () => {
|
|
45
|
+
const content = `
|
|
46
|
+
function test() {
|
|
47
|
+
const x = 1;
|
|
48
|
+
return x + 1;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
const result = metric.calculate(createParseResult(content));
|
|
52
|
+
expect(result.severity).toBe('info');
|
|
53
|
+
expect(result.normalizedScore).toBe(100);
|
|
54
|
+
expect(result.value).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
it('should detect ignored error with underscore assignment', () => {
|
|
57
|
+
const content = `
|
|
58
|
+
function test() {
|
|
59
|
+
_ = readFile('test.txt');
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
const result = metric.calculate(createParseResult(content));
|
|
63
|
+
expect(result.value).toBeGreaterThan(0);
|
|
64
|
+
expect(result.locations).toBeDefined();
|
|
65
|
+
expect(result.locations?.length).toBe(1);
|
|
66
|
+
expect(result.locations?.[0]?.message).toBe('Ignored error return value');
|
|
67
|
+
});
|
|
68
|
+
it('should detect unhandled error-prone call', () => {
|
|
69
|
+
const content = `
|
|
70
|
+
function test() {
|
|
71
|
+
readFile('test.txt');
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
const result = metric.calculate(createParseResult(content));
|
|
75
|
+
expect(result.value).toBeGreaterThan(0);
|
|
76
|
+
expect(result.locations).toBeDefined();
|
|
77
|
+
expect(result.locations?.length).toBe(1);
|
|
78
|
+
expect(result.locations?.[0]?.message).toBe('Unhandled error-prone call');
|
|
79
|
+
});
|
|
80
|
+
it('should not flag error-prone calls with proper handling', () => {
|
|
81
|
+
const content = `
|
|
82
|
+
function test() {
|
|
83
|
+
const data = readFile('test.txt');
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
const result = metric.calculate(createParseResult(content));
|
|
88
|
+
expect(result.value).toBe(0);
|
|
89
|
+
expect(result.normalizedScore).toBe(100);
|
|
90
|
+
expect(result.severity).toBe('info');
|
|
91
|
+
});
|
|
92
|
+
it('should not flag error-prone calls in try-catch blocks', () => {
|
|
93
|
+
const content = `
|
|
94
|
+
function test() {
|
|
95
|
+
try {
|
|
96
|
+
readFile('test.txt');
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
const result = metric.calculate(createParseResult(content));
|
|
103
|
+
expect(result.value).toBe(0);
|
|
104
|
+
expect(result.normalizedScore).toBe(100);
|
|
105
|
+
});
|
|
106
|
+
it('should not flag error-prone calls with .catch()', () => {
|
|
107
|
+
const content = `
|
|
108
|
+
function test() {
|
|
109
|
+
fetch('api.com')
|
|
110
|
+
.then(res => res.json())
|
|
111
|
+
.catch(err => console.error(err));
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
const result = metric.calculate(createParseResult(content));
|
|
115
|
+
expect(result.value).toBe(0);
|
|
116
|
+
expect(result.normalizedScore).toBe(100);
|
|
117
|
+
});
|
|
118
|
+
it('should calculate correct ignored ratio', () => {
|
|
119
|
+
const content = `
|
|
120
|
+
function test1() {
|
|
121
|
+
_ = readFile('test.txt');
|
|
122
|
+
}
|
|
123
|
+
function test2() {
|
|
124
|
+
const data = readFile('test.txt');
|
|
125
|
+
}
|
|
126
|
+
function test3() {
|
|
127
|
+
readFile('test.txt');
|
|
128
|
+
}
|
|
129
|
+
function test4() {
|
|
130
|
+
const data = readFile('test.txt');
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
const result = metric.calculate(createParseResult(content, 4));
|
|
134
|
+
expect(result.locations?.length).toBe(2);
|
|
135
|
+
expect(result.value).toBeCloseTo(0.5);
|
|
136
|
+
});
|
|
137
|
+
it('should apply correct scoring formula: 0.4 + (ignoredRatio * 10)', () => {
|
|
138
|
+
const content = `
|
|
139
|
+
function test1() {
|
|
140
|
+
_ = readFile('test.txt');
|
|
141
|
+
}
|
|
142
|
+
function test2() {
|
|
143
|
+
const data = readFile('test.txt');
|
|
144
|
+
}
|
|
145
|
+
`;
|
|
146
|
+
const result = metric.calculate(createParseResult(content, 2));
|
|
147
|
+
const ignoredRatio = 0.5;
|
|
148
|
+
const expectedRawScore = Math.min(1.0, 0.4 + ignoredRatio * 10.0);
|
|
149
|
+
const expectedNormalizedScore = Math.round((1.0 - expectedRawScore) * 100);
|
|
150
|
+
expect(result.normalizedScore).toBe(expectedNormalizedScore);
|
|
151
|
+
});
|
|
152
|
+
it('should assign info severity for rawScore <= 0.5', () => {
|
|
153
|
+
const content = `
|
|
154
|
+
function test1() {
|
|
155
|
+
const data = readFile('test.txt');
|
|
156
|
+
}
|
|
157
|
+
function test2() {
|
|
158
|
+
const data = readFile('test.txt');
|
|
159
|
+
}
|
|
160
|
+
function test3() {
|
|
161
|
+
const data = readFile('test.txt');
|
|
162
|
+
}
|
|
163
|
+
function test4() {
|
|
164
|
+
const data = readFile('test.txt');
|
|
165
|
+
}
|
|
166
|
+
function test5() {
|
|
167
|
+
const data = readFile('test.txt');
|
|
168
|
+
}
|
|
169
|
+
function test6() {
|
|
170
|
+
const data = readFile('test.txt');
|
|
171
|
+
}
|
|
172
|
+
function test7() {
|
|
173
|
+
const data = readFile('test.txt');
|
|
174
|
+
}
|
|
175
|
+
function test8() {
|
|
176
|
+
const data = readFile('test.txt');
|
|
177
|
+
}
|
|
178
|
+
function test9() {
|
|
179
|
+
const data = readFile('test.txt');
|
|
180
|
+
}
|
|
181
|
+
function test10() {
|
|
182
|
+
_ = readFile('test.txt');
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
const result = metric.calculate(createParseResult(content, 10));
|
|
186
|
+
expect(result.severity).toBe('info');
|
|
187
|
+
});
|
|
188
|
+
it('should assign warning severity for 0.5 < rawScore <= 0.7', () => {
|
|
189
|
+
const content = `
|
|
190
|
+
function test1() {
|
|
191
|
+
const data = readFile('test.txt');
|
|
192
|
+
}
|
|
193
|
+
function test2() {
|
|
194
|
+
_ = readFile('test.txt');
|
|
195
|
+
}
|
|
196
|
+
function test3() {
|
|
197
|
+
_ = readFile('test.txt');
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
200
|
+
const result = metric.calculate(createParseResult(content, 3));
|
|
201
|
+
expect(result.severity).toBe('warning');
|
|
202
|
+
});
|
|
203
|
+
it('should assign error severity for 0.7 < rawScore <= 0.9', () => {
|
|
204
|
+
const content = `
|
|
205
|
+
function test1() {
|
|
206
|
+
_ = readFile('test.txt');
|
|
207
|
+
}
|
|
208
|
+
function test2() {
|
|
209
|
+
_ = readFile('test.txt');
|
|
210
|
+
}
|
|
211
|
+
function test3() {
|
|
212
|
+
_ = readFile('test.txt');
|
|
213
|
+
}
|
|
214
|
+
function test4() {
|
|
215
|
+
const data = readFile('test.txt');
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
const result = metric.calculate(createParseResult(content, 4));
|
|
219
|
+
expect(result.severity).toBe('error');
|
|
220
|
+
});
|
|
221
|
+
it('should assign critical severity for rawScore > 0.9', () => {
|
|
222
|
+
const content = `
|
|
223
|
+
function test1() {
|
|
224
|
+
_ = readFile('test.txt');
|
|
225
|
+
}
|
|
226
|
+
function test2() {
|
|
227
|
+
_ = readFile('test.txt');
|
|
228
|
+
}
|
|
229
|
+
function test3() {
|
|
230
|
+
_ = readFile('test.txt');
|
|
231
|
+
}
|
|
232
|
+
function test4() {
|
|
233
|
+
_ = readFile('test.txt');
|
|
234
|
+
}
|
|
235
|
+
function test5() {
|
|
236
|
+
_ = readFile('test.txt');
|
|
237
|
+
}
|
|
238
|
+
function test6() {
|
|
239
|
+
_ = readFile('test.txt');
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
const result = metric.calculate(createParseResult(content, 6));
|
|
243
|
+
expect(result.severity).toBe('critical');
|
|
244
|
+
});
|
|
245
|
+
it('should detect file I/O operations', () => {
|
|
246
|
+
const content = `
|
|
247
|
+
function test() {
|
|
248
|
+
open('file.txt');
|
|
249
|
+
read('file.txt');
|
|
250
|
+
write('file.txt', 'data');
|
|
251
|
+
close(fd);
|
|
252
|
+
create('file.txt');
|
|
253
|
+
remove('file.txt');
|
|
254
|
+
rename('old.txt', 'new.txt');
|
|
255
|
+
mkdir('dir');
|
|
256
|
+
readFile('file.txt');
|
|
257
|
+
writeFile('file.txt', 'data');
|
|
258
|
+
readdir('dir');
|
|
259
|
+
stat('file.txt');
|
|
260
|
+
access('file.txt');
|
|
261
|
+
}
|
|
262
|
+
`;
|
|
263
|
+
const result = metric.calculate(createParseResult(content));
|
|
264
|
+
expect(result.locations?.length).toBeGreaterThan(0);
|
|
265
|
+
});
|
|
266
|
+
it('should detect network operations', () => {
|
|
267
|
+
const content = `
|
|
268
|
+
function test() {
|
|
269
|
+
fetch('api.com');
|
|
270
|
+
get('api.com');
|
|
271
|
+
post('api.com', data);
|
|
272
|
+
put('api.com', data);
|
|
273
|
+
delete('api.com');
|
|
274
|
+
request('api.com');
|
|
275
|
+
send(data);
|
|
276
|
+
connect('server');
|
|
277
|
+
listen(3000);
|
|
278
|
+
accept(socket);
|
|
279
|
+
}
|
|
280
|
+
`;
|
|
281
|
+
const result = metric.calculate(createParseResult(content));
|
|
282
|
+
expect(result.locations?.length).toBeGreaterThan(0);
|
|
283
|
+
});
|
|
284
|
+
it('should detect JSON operations', () => {
|
|
285
|
+
const content = `
|
|
286
|
+
function test() {
|
|
287
|
+
parse(jsonString);
|
|
288
|
+
stringify(obj);
|
|
289
|
+
marshal(obj);
|
|
290
|
+
unmarshal(data);
|
|
291
|
+
decode(data);
|
|
292
|
+
encode(obj);
|
|
293
|
+
}
|
|
294
|
+
`;
|
|
295
|
+
const result = metric.calculate(createParseResult(content));
|
|
296
|
+
expect(result.locations?.length).toBeGreaterThan(0);
|
|
297
|
+
});
|
|
298
|
+
it('should detect database operations', () => {
|
|
299
|
+
const content = `
|
|
300
|
+
function test() {
|
|
301
|
+
query('SELECT * FROM users');
|
|
302
|
+
exec('DELETE FROM users');
|
|
303
|
+
execute('UPDATE users SET name = ?');
|
|
304
|
+
prepare('INSERT INTO users VALUES (?)');
|
|
305
|
+
transaction();
|
|
306
|
+
commit();
|
|
307
|
+
rollback();
|
|
308
|
+
}
|
|
309
|
+
`;
|
|
310
|
+
const result = metric.calculate(createParseResult(content));
|
|
311
|
+
expect(result.locations?.length).toBeGreaterThan(0);
|
|
312
|
+
});
|
|
313
|
+
it('should handle empty lines', () => {
|
|
314
|
+
const content = `
|
|
315
|
+
function test() {
|
|
316
|
+
|
|
317
|
+
readFile('test.txt');
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
`;
|
|
321
|
+
const result = metric.calculate(createParseResult(content));
|
|
322
|
+
expect(result.locations?.length).toBe(1);
|
|
323
|
+
});
|
|
324
|
+
it('should handle malformed code', () => {
|
|
325
|
+
const content = `
|
|
326
|
+
function test() {
|
|
327
|
+
readFile(
|
|
328
|
+
}
|
|
329
|
+
`;
|
|
330
|
+
const result = metric.calculate(createParseResult(content));
|
|
331
|
+
expect(result).toBeDefined();
|
|
332
|
+
expect(result.value).toBeGreaterThanOrEqual(0);
|
|
333
|
+
});
|
|
334
|
+
it('should cap rawScore at 1.0', () => {
|
|
335
|
+
const content = `
|
|
336
|
+
function test1() {
|
|
337
|
+
_ = readFile('test.txt');
|
|
338
|
+
}
|
|
339
|
+
function test2() {
|
|
340
|
+
_ = readFile('test.txt');
|
|
341
|
+
}
|
|
342
|
+
`;
|
|
343
|
+
const result = metric.calculate(createParseResult(content, 2));
|
|
344
|
+
expect(result.normalizedScore).toBeGreaterThanOrEqual(0);
|
|
345
|
+
expect(result.normalizedScore).toBeLessThanOrEqual(100);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
//# sourceMappingURL=error-handling.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.test.js","sourceRoot":"","sources":["../../../src/metrics/error/error-handling.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,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C,eAAe,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YACzD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics factory and exports
|
|
3
|
+
*/
|
|
4
|
+
import type { Metric } from './types.js';
|
|
5
|
+
import type { RuntimeConfig } from '../config/schema.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create all metrics with configured weights
|
|
8
|
+
*
|
|
9
|
+
* Weight distribution based on industry standards (SonarQube, CodeClimate, NASA, Microsoft):
|
|
10
|
+
* - Complexity: 32% (3 metrics, each gets 32%/3 = 10.67%)
|
|
11
|
+
* - Duplication: 20% (1 metric)
|
|
12
|
+
* - Size: 18% (3 metrics, each gets 18%/3 = 6%)
|
|
13
|
+
* - Structure: 12% (1 metric)
|
|
14
|
+
* - Error: 8% (1 metric)
|
|
15
|
+
* - Documentation: 5% (1 metric)
|
|
16
|
+
* - Naming: 5% (1 metric)
|
|
17
|
+
* Total: 100%
|
|
18
|
+
*/
|
|
19
|
+
export declare function createMetrics(config: RuntimeConfig): Metric[];
|
|
20
|
+
export type { Metric, MetricResult, MetricCategory, Severity } from './types.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAwB7D;AAED,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics factory and exports
|
|
3
|
+
*/
|
|
4
|
+
import { CyclomaticComplexityMetric } from './complexity/cyclomatic.js';
|
|
5
|
+
import { CognitiveComplexityMetric } from './complexity/cognitive.js';
|
|
6
|
+
import { NestingDepthMetric } from './complexity/nesting-depth.js';
|
|
7
|
+
import { FunctionLengthMetric } from './size/function-length.js';
|
|
8
|
+
import { FileLengthMetric } from './size/file-length.js';
|
|
9
|
+
import { ParameterCountMetric } from './size/parameter-count.js';
|
|
10
|
+
import { CommentRatioMetric } from './documentation/comment-ratio.js';
|
|
11
|
+
import { NamingConventionMetric } from './naming/convention.js';
|
|
12
|
+
import { CodeDuplicationMetric } from './duplication/code-duplication.js';
|
|
13
|
+
import { ErrorHandlingMetric } from './error/error-handling.js';
|
|
14
|
+
import { StructureAnalysisMetric } from './structure/structure-analysis.js';
|
|
15
|
+
/**
|
|
16
|
+
* Create all metrics with configured weights
|
|
17
|
+
*
|
|
18
|
+
* Weight distribution based on industry standards (SonarQube, CodeClimate, NASA, Microsoft):
|
|
19
|
+
* - Complexity: 32% (3 metrics, each gets 32%/3 = 10.67%)
|
|
20
|
+
* - Duplication: 20% (1 metric)
|
|
21
|
+
* - Size: 18% (3 metrics, each gets 18%/3 = 6%)
|
|
22
|
+
* - Structure: 12% (1 metric)
|
|
23
|
+
* - Error: 8% (1 metric)
|
|
24
|
+
* - Documentation: 5% (1 metric)
|
|
25
|
+
* - Naming: 5% (1 metric)
|
|
26
|
+
* Total: 100%
|
|
27
|
+
*/
|
|
28
|
+
export function createMetrics(config) {
|
|
29
|
+
const weights = config.metrics.weights;
|
|
30
|
+
const complexityWeight = weights.complexity;
|
|
31
|
+
const complexityMetricsCount = 3;
|
|
32
|
+
const complexityPerMetric = complexityWeight / complexityMetricsCount;
|
|
33
|
+
const sizeWeight = weights.size;
|
|
34
|
+
const sizeMetricsCount = 3;
|
|
35
|
+
const sizePerMetric = sizeWeight / sizeMetricsCount;
|
|
36
|
+
return [
|
|
37
|
+
new CyclomaticComplexityMetric(complexityPerMetric),
|
|
38
|
+
new CognitiveComplexityMetric(complexityPerMetric),
|
|
39
|
+
new NestingDepthMetric(complexityPerMetric),
|
|
40
|
+
new FunctionLengthMetric(sizePerMetric),
|
|
41
|
+
new FileLengthMetric(sizePerMetric),
|
|
42
|
+
new ParameterCountMetric(sizePerMetric),
|
|
43
|
+
new CodeDuplicationMetric(weights.duplication),
|
|
44
|
+
new StructureAnalysisMetric(weights.structure),
|
|
45
|
+
new ErrorHandlingMetric(weights.error),
|
|
46
|
+
new CommentRatioMetric(weights.documentation),
|
|
47
|
+
new NamingConventionMetric(weights.naming),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAI5E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAEvC,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAC5C,MAAM,sBAAsB,GAAG,CAAC,CAAC;IACjC,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;IAEtE,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAChC,MAAM,gBAAgB,GAAG,CAAC,CAAC;IAC3B,MAAM,aAAa,GAAG,UAAU,GAAG,gBAAgB,CAAC;IAEpD,OAAO;QACL,IAAI,0BAA0B,CAAC,mBAAmB,CAAC;QACnD,IAAI,yBAAyB,CAAC,mBAAmB,CAAC;QAClD,IAAI,kBAAkB,CAAC,mBAAmB,CAAC;QAC3C,IAAI,oBAAoB,CAAC,aAAa,CAAC;QACvC,IAAI,gBAAgB,CAAC,aAAa,CAAC;QACnC,IAAI,oBAAoB,CAAC,aAAa,CAAC;QACvC,IAAI,qBAAqB,CAAC,OAAO,CAAC,WAAW,CAAC;QAC9C,IAAI,uBAAuB,CAAC,OAAO,CAAC,SAAS,CAAC;QAC9C,IAAI,mBAAmB,CAAC,OAAO,CAAC,KAAK,CAAC;QACtC,IAAI,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC;QAC7C,IAAI,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC;KAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming convention metric
|
|
3
|
+
*
|
|
4
|
+
* Checks if identifiers follow language-specific naming conventions.
|
|
5
|
+
* Based on official style guides:
|
|
6
|
+
* - Go: Effective Go
|
|
7
|
+
* - JavaScript/TypeScript: Airbnb Style Guide
|
|
8
|
+
* - Python: PEP 8
|
|
9
|
+
* - Java: Oracle Code Conventions
|
|
10
|
+
* - Rust: Rust API Guidelines
|
|
11
|
+
* - C#: Microsoft Naming Guidelines
|
|
12
|
+
*/
|
|
13
|
+
import type { Metric, MetricResult, MetricCategory } from '../types.js';
|
|
14
|
+
import type { ParseResult } from '../../parser/types.js';
|
|
15
|
+
export declare class NamingConventionMetric implements Metric {
|
|
16
|
+
readonly name = "naming_convention";
|
|
17
|
+
readonly category: MetricCategory;
|
|
18
|
+
readonly weight: number;
|
|
19
|
+
constructor(weight: number);
|
|
20
|
+
calculate(parseResult: ParseResult): MetricResult;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=convention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convention.d.ts","sourceRoot":"","sources":["../../../src/metrics/naming/convention.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAA4B,MAAM,aAAa,CAAC;AAClG,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,uBAAuB,CAAC;AA0BnE,qBAAa,sBAAuB,YAAW,MAAM;IACnD,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAY;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,YAAY;CA+ElD"}
|