@aiready/doc-drift 0.11.17 → 0.11.21
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/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-lint.log +2 -1
- package/.turbo/turbo-test.log +8 -6
- package/coverage/analyzer.ts.html +559 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +84 -0
- package/coverage/coverage-final.json +4 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +146 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/provider.ts.html +307 -0
- package/coverage/scoring.ts.html +253 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +53 -4
- package/dist/index.mjs +49 -1
- package/package.json +2 -2
- package/src/__tests__/provider.test.ts +45 -0
- package/src/__tests__/scoring.test.ts +51 -0
- package/src/index.ts +1 -0
- package/src/scoring.ts +61 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
+
|
|
31
|
+
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
|
32
|
+
// it will be treated as a plain text search
|
|
33
|
+
let searchRegex;
|
|
34
|
+
try {
|
|
35
|
+
searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
|
|
36
|
+
} catch (error) {
|
|
37
|
+
searchRegex = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < rows.length; i++) {
|
|
41
|
+
const row = rows[i];
|
|
42
|
+
let isMatch = false;
|
|
43
|
+
|
|
44
|
+
if (searchRegex) {
|
|
45
|
+
// If a valid regex was created, use it for matching
|
|
46
|
+
isMatch = searchRegex.test(row.textContent);
|
|
47
|
+
} else {
|
|
48
|
+
// Otherwise, fall back to the original plain text search
|
|
49
|
+
isMatch = row.textContent
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.includes(searchValue.toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
row.style.display = isMatch ? '' : 'none';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// loads the search box
|
|
59
|
+
function addSearchBox() {
|
|
60
|
+
var template = document.getElementById('filterTemplate');
|
|
61
|
+
var templateClone = template.content.cloneNode(true);
|
|
62
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
63
|
+
template.parentElement.appendChild(templateClone);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// loads all columns
|
|
67
|
+
function loadColumns() {
|
|
68
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
69
|
+
colNode,
|
|
70
|
+
cols = [],
|
|
71
|
+
col,
|
|
72
|
+
i;
|
|
73
|
+
|
|
74
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
75
|
+
colNode = colNodes[i];
|
|
76
|
+
col = {
|
|
77
|
+
key: colNode.getAttribute('data-col'),
|
|
78
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
79
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
80
|
+
};
|
|
81
|
+
cols.push(col);
|
|
82
|
+
if (col.sortable) {
|
|
83
|
+
col.defaultDescSort = col.type === 'number';
|
|
84
|
+
colNode.innerHTML =
|
|
85
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return cols;
|
|
89
|
+
}
|
|
90
|
+
// attaches a data attribute to every tr element with an object
|
|
91
|
+
// of data values keyed by column name
|
|
92
|
+
function loadRowData(tableRow) {
|
|
93
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
94
|
+
colNode,
|
|
95
|
+
col,
|
|
96
|
+
data = {},
|
|
97
|
+
i,
|
|
98
|
+
val;
|
|
99
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
100
|
+
colNode = tableCols[i];
|
|
101
|
+
col = cols[i];
|
|
102
|
+
val = colNode.getAttribute('data-value');
|
|
103
|
+
if (col.type === 'number') {
|
|
104
|
+
val = Number(val);
|
|
105
|
+
}
|
|
106
|
+
data[col.key] = val;
|
|
107
|
+
}
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
// loads all row data
|
|
111
|
+
function loadData() {
|
|
112
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
113
|
+
i;
|
|
114
|
+
|
|
115
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
116
|
+
rows[i].data = loadRowData(rows[i]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// sorts the table using the data for the ith column
|
|
120
|
+
function sortByIndex(index, desc) {
|
|
121
|
+
var key = cols[index].key,
|
|
122
|
+
sorter = function(a, b) {
|
|
123
|
+
a = a.data[key];
|
|
124
|
+
b = b.data[key];
|
|
125
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
126
|
+
},
|
|
127
|
+
finalSorter = sorter,
|
|
128
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
129
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
130
|
+
rows = [],
|
|
131
|
+
i;
|
|
132
|
+
|
|
133
|
+
if (desc) {
|
|
134
|
+
finalSorter = function(a, b) {
|
|
135
|
+
return -1 * sorter(a, b);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
140
|
+
rows.push(rowNodes[i]);
|
|
141
|
+
tableBody.removeChild(rowNodes[i]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
rows.sort(finalSorter);
|
|
145
|
+
|
|
146
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
147
|
+
tableBody.appendChild(rows[i]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// removes sort indicators for current column being sorted
|
|
151
|
+
function removeSortIndicators() {
|
|
152
|
+
var col = getNthColumn(currentSort.index),
|
|
153
|
+
cls = col.className;
|
|
154
|
+
|
|
155
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
156
|
+
col.className = cls;
|
|
157
|
+
}
|
|
158
|
+
// adds sort indicators for current column being sorted
|
|
159
|
+
function addSortIndicators() {
|
|
160
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
161
|
+
? ' sorted-desc'
|
|
162
|
+
: ' sorted';
|
|
163
|
+
}
|
|
164
|
+
// adds event listeners for all sorter widgets
|
|
165
|
+
function enableUI() {
|
|
166
|
+
var i,
|
|
167
|
+
el,
|
|
168
|
+
ithSorter = function ithSorter(i) {
|
|
169
|
+
var col = cols[i];
|
|
170
|
+
|
|
171
|
+
return function() {
|
|
172
|
+
var desc = col.defaultDescSort;
|
|
173
|
+
|
|
174
|
+
if (currentSort.index === i) {
|
|
175
|
+
desc = !currentSort.desc;
|
|
176
|
+
}
|
|
177
|
+
sortByIndex(i, desc);
|
|
178
|
+
removeSortIndicators();
|
|
179
|
+
currentSort.index = i;
|
|
180
|
+
currentSort.desc = desc;
|
|
181
|
+
addSortIndicators();
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
185
|
+
if (cols[i].sortable) {
|
|
186
|
+
// add the click event handler on the th so users
|
|
187
|
+
// dont have to click on those tiny arrows
|
|
188
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
189
|
+
if (el.addEventListener) {
|
|
190
|
+
el.addEventListener('click', ithSorter(i));
|
|
191
|
+
} else {
|
|
192
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// adds sorting functionality to the UI
|
|
198
|
+
return function() {
|
|
199
|
+
if (!getTable()) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
cols = loadColumns();
|
|
203
|
+
loadData();
|
|
204
|
+
addSearchBox();
|
|
205
|
+
addSortIndicators();
|
|
206
|
+
enableUI();
|
|
207
|
+
};
|
|
208
|
+
})();
|
|
209
|
+
|
|
210
|
+
window.addEventListener('load', addSorting);
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolProvider, Issue, IssueType, ScanOptions } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Issue, IssueType, ScanOptions, ToolScoringOutput } from '@aiready/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Documentation Drift Tool Provider
|
|
@@ -33,4 +33,9 @@ interface DocDriftReport {
|
|
|
33
33
|
|
|
34
34
|
declare function analyzeDocDrift(options: DocDriftOptions): Promise<DocDriftReport>;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Convert doc-drift report into a ToolScoringOutput.
|
|
38
|
+
*/
|
|
39
|
+
declare function calculateDocDriftScore(report: DocDriftReport): ToolScoringOutput;
|
|
40
|
+
|
|
41
|
+
export { type DocDriftIssue, type DocDriftOptions, DocDriftProvider, type DocDriftReport, analyzeDocDrift, calculateDocDriftScore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolProvider, Issue, IssueType, ScanOptions } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Issue, IssueType, ScanOptions, ToolScoringOutput } from '@aiready/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Documentation Drift Tool Provider
|
|
@@ -33,4 +33,9 @@ interface DocDriftReport {
|
|
|
33
33
|
|
|
34
34
|
declare function analyzeDocDrift(options: DocDriftOptions): Promise<DocDriftReport>;
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Convert doc-drift report into a ToolScoringOutput.
|
|
38
|
+
*/
|
|
39
|
+
declare function calculateDocDriftScore(report: DocDriftReport): ToolScoringOutput;
|
|
40
|
+
|
|
41
|
+
export { type DocDriftIssue, type DocDriftOptions, DocDriftProvider, type DocDriftReport, analyzeDocDrift, calculateDocDriftScore };
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
DocDriftProvider: () => DocDriftProvider,
|
|
24
|
-
analyzeDocDrift: () => analyzeDocDrift
|
|
24
|
+
analyzeDocDrift: () => analyzeDocDrift,
|
|
25
|
+
calculateDocDriftScore: () => calculateDocDriftScore
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
var
|
|
28
|
+
var import_core4 = require("@aiready/core");
|
|
28
29
|
|
|
29
30
|
// src/provider.ts
|
|
30
31
|
var import_core2 = require("@aiready/core");
|
|
@@ -192,10 +193,58 @@ var DocDriftProvider = {
|
|
|
192
193
|
defaultWeight: 8
|
|
193
194
|
};
|
|
194
195
|
|
|
196
|
+
// src/scoring.ts
|
|
197
|
+
var import_core3 = require("@aiready/core");
|
|
198
|
+
function calculateDocDriftScore(report) {
|
|
199
|
+
const { rawData, summary } = report;
|
|
200
|
+
const riskResult = (0, import_core3.calculateDocDrift)({
|
|
201
|
+
uncommentedExports: rawData.uncommentedExports,
|
|
202
|
+
totalExports: rawData.totalExports,
|
|
203
|
+
outdatedComments: rawData.outdatedComments,
|
|
204
|
+
undocumentedComplexity: rawData.undocumentedComplexity
|
|
205
|
+
});
|
|
206
|
+
const factors = [
|
|
207
|
+
{
|
|
208
|
+
name: "Uncommented Exports",
|
|
209
|
+
impact: -Math.min(
|
|
210
|
+
20,
|
|
211
|
+
rawData.uncommentedExports / Math.max(1, rawData.totalExports) * 100 * 0.2
|
|
212
|
+
),
|
|
213
|
+
description: `${rawData.uncommentedExports} uncommented exports`
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "Outdated Comments",
|
|
217
|
+
impact: -Math.min(60, rawData.outdatedComments * 15 * 0.6),
|
|
218
|
+
description: `${rawData.outdatedComments} outdated comments`
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: "Undocumented Complexity",
|
|
222
|
+
impact: -Math.min(20, rawData.undocumentedComplexity * 10 * 0.2),
|
|
223
|
+
description: `${rawData.undocumentedComplexity} complex functions lack docs`
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
const recommendations = riskResult.recommendations.map((rec) => ({
|
|
227
|
+
action: rec,
|
|
228
|
+
estimatedImpact: 8,
|
|
229
|
+
priority: summary.score < 50 ? "high" : "medium"
|
|
230
|
+
}));
|
|
231
|
+
return {
|
|
232
|
+
toolName: import_core3.ToolName.DocDrift,
|
|
233
|
+
score: summary.score,
|
|
234
|
+
rawMetrics: {
|
|
235
|
+
...rawData,
|
|
236
|
+
rating: summary.rating
|
|
237
|
+
},
|
|
238
|
+
factors,
|
|
239
|
+
recommendations
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
195
243
|
// src/index.ts
|
|
196
|
-
|
|
244
|
+
import_core4.ToolRegistry.register(DocDriftProvider);
|
|
197
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
246
|
0 && (module.exports = {
|
|
199
247
|
DocDriftProvider,
|
|
200
|
-
analyzeDocDrift
|
|
248
|
+
analyzeDocDrift,
|
|
249
|
+
calculateDocDriftScore
|
|
201
250
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -62,9 +62,57 @@ var DocDriftProvider = {
|
|
|
62
62
|
defaultWeight: 8
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
// src/scoring.ts
|
|
66
|
+
import { calculateDocDrift, ToolName as ToolName2 } from "@aiready/core";
|
|
67
|
+
function calculateDocDriftScore(report) {
|
|
68
|
+
const { rawData, summary } = report;
|
|
69
|
+
const riskResult = calculateDocDrift({
|
|
70
|
+
uncommentedExports: rawData.uncommentedExports,
|
|
71
|
+
totalExports: rawData.totalExports,
|
|
72
|
+
outdatedComments: rawData.outdatedComments,
|
|
73
|
+
undocumentedComplexity: rawData.undocumentedComplexity
|
|
74
|
+
});
|
|
75
|
+
const factors = [
|
|
76
|
+
{
|
|
77
|
+
name: "Uncommented Exports",
|
|
78
|
+
impact: -Math.min(
|
|
79
|
+
20,
|
|
80
|
+
rawData.uncommentedExports / Math.max(1, rawData.totalExports) * 100 * 0.2
|
|
81
|
+
),
|
|
82
|
+
description: `${rawData.uncommentedExports} uncommented exports`
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "Outdated Comments",
|
|
86
|
+
impact: -Math.min(60, rawData.outdatedComments * 15 * 0.6),
|
|
87
|
+
description: `${rawData.outdatedComments} outdated comments`
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "Undocumented Complexity",
|
|
91
|
+
impact: -Math.min(20, rawData.undocumentedComplexity * 10 * 0.2),
|
|
92
|
+
description: `${rawData.undocumentedComplexity} complex functions lack docs`
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
const recommendations = riskResult.recommendations.map((rec) => ({
|
|
96
|
+
action: rec,
|
|
97
|
+
estimatedImpact: 8,
|
|
98
|
+
priority: summary.score < 50 ? "high" : "medium"
|
|
99
|
+
}));
|
|
100
|
+
return {
|
|
101
|
+
toolName: ToolName2.DocDrift,
|
|
102
|
+
score: summary.score,
|
|
103
|
+
rawMetrics: {
|
|
104
|
+
...rawData,
|
|
105
|
+
rating: summary.rating
|
|
106
|
+
},
|
|
107
|
+
factors,
|
|
108
|
+
recommendations
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
65
112
|
// src/index.ts
|
|
66
113
|
ToolRegistry.register(DocDriftProvider);
|
|
67
114
|
export {
|
|
68
115
|
DocDriftProvider,
|
|
69
|
-
analyzeDocDrift
|
|
116
|
+
analyzeDocDrift,
|
|
117
|
+
calculateDocDriftScore
|
|
70
118
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/doc-drift",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.21",
|
|
4
4
|
"description": "AI-Readiness: Documentation Drift Detection",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"commander": "^14.0.0",
|
|
11
11
|
"glob": "^13.0.0",
|
|
12
12
|
"picocolors": "^1.0.0",
|
|
13
|
-
"@aiready/core": "0.21.
|
|
13
|
+
"@aiready/core": "0.21.21"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^24.0.0",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { DocDriftProvider } from '../provider';
|
|
3
|
+
import * as analyzer from '../analyzer';
|
|
4
|
+
|
|
5
|
+
vi.mock('../analyzer', () => ({
|
|
6
|
+
analyzeDocDrift: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe('Doc Drift Provider', () => {
|
|
10
|
+
it('should analyze and return SpokeOutput', async () => {
|
|
11
|
+
vi.mocked(analyzer.analyzeDocDrift).mockResolvedValue({
|
|
12
|
+
summary: {
|
|
13
|
+
filesAnalyzed: 1,
|
|
14
|
+
functionsAnalyzed: 5,
|
|
15
|
+
score: 90,
|
|
16
|
+
rating: 'minimal',
|
|
17
|
+
},
|
|
18
|
+
issues: [],
|
|
19
|
+
rawData: {
|
|
20
|
+
uncommentedExports: 0,
|
|
21
|
+
totalExports: 5,
|
|
22
|
+
outdatedComments: 0,
|
|
23
|
+
undocumentedComplexity: 0,
|
|
24
|
+
},
|
|
25
|
+
recommendations: [],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const output = await DocDriftProvider.analyze({ rootDir: '.' });
|
|
29
|
+
|
|
30
|
+
expect(output.summary.filesAnalyzed).toBe(1);
|
|
31
|
+
expect(output.metadata.toolName).toBe('doc-drift');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should score an output', () => {
|
|
35
|
+
const mockOutput = {
|
|
36
|
+
summary: { score: 80, recommendations: ['Fix it'] } as any,
|
|
37
|
+
metadata: { rawData: {} },
|
|
38
|
+
results: [],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const scoring = DocDriftProvider.score(mockOutput as any, { rootDir: '.' });
|
|
42
|
+
expect(scoring.score).toBe(80);
|
|
43
|
+
expect(scoring.recommendations[0].action).toBe('Fix it');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { calculateDocDriftScore } from '../scoring';
|
|
3
|
+
import { DocDriftReport } from '../types';
|
|
4
|
+
import { ToolName } from '@aiready/core';
|
|
5
|
+
|
|
6
|
+
describe('Doc Drift Scoring', () => {
|
|
7
|
+
const mockReport: DocDriftReport = {
|
|
8
|
+
summary: {
|
|
9
|
+
filesAnalyzed: 10,
|
|
10
|
+
functionsAnalyzed: 50,
|
|
11
|
+
score: 70,
|
|
12
|
+
rating: 'good',
|
|
13
|
+
},
|
|
14
|
+
issues: [],
|
|
15
|
+
rawData: {
|
|
16
|
+
uncommentedExports: 20,
|
|
17
|
+
totalExports: 50,
|
|
18
|
+
outdatedComments: 2,
|
|
19
|
+
undocumentedComplexity: 1,
|
|
20
|
+
},
|
|
21
|
+
recommendations: [
|
|
22
|
+
'Update or remove 2 outdated comments that contradict the code.',
|
|
23
|
+
'Add JSDoc to 20 uncommented exports.',
|
|
24
|
+
'Explain the business logic for 1 highly complex functions.',
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
it('should map report to ToolScoringOutput correctly', () => {
|
|
29
|
+
const scoring = calculateDocDriftScore(mockReport);
|
|
30
|
+
|
|
31
|
+
expect(scoring.toolName).toBe(ToolName.DocDrift);
|
|
32
|
+
expect(scoring.score).toBe(70);
|
|
33
|
+
expect(scoring.factors.length).toBeGreaterThan(0);
|
|
34
|
+
expect(scoring.recommendations[0].action).toBe(
|
|
35
|
+
'Update or remove 2 outdated comments that contradict the code.'
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should set high priority for low scores', () => {
|
|
40
|
+
const lowScoreReport: DocDriftReport = {
|
|
41
|
+
...mockReport,
|
|
42
|
+
summary: {
|
|
43
|
+
...mockReport.summary,
|
|
44
|
+
score: 40,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const scoring = calculateDocDriftScore(lowScoreReport);
|
|
49
|
+
expect(scoring.recommendations[0].priority).toBe('high');
|
|
50
|
+
});
|
|
51
|
+
});
|
package/src/index.ts
CHANGED
package/src/scoring.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { calculateDocDrift, ToolName } from '@aiready/core';
|
|
2
|
+
import type { ToolScoringOutput } from '@aiready/core';
|
|
3
|
+
import type { DocDriftReport } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert doc-drift report into a ToolScoringOutput.
|
|
7
|
+
*/
|
|
8
|
+
export function calculateDocDriftScore(
|
|
9
|
+
report: DocDriftReport
|
|
10
|
+
): ToolScoringOutput {
|
|
11
|
+
const { rawData, summary } = report;
|
|
12
|
+
|
|
13
|
+
// Recalculate using core math to get risk contribution breakdown
|
|
14
|
+
const riskResult = calculateDocDrift({
|
|
15
|
+
uncommentedExports: rawData.uncommentedExports,
|
|
16
|
+
totalExports: rawData.totalExports,
|
|
17
|
+
outdatedComments: rawData.outdatedComments,
|
|
18
|
+
undocumentedComplexity: rawData.undocumentedComplexity,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const factors: ToolScoringOutput['factors'] = [
|
|
22
|
+
{
|
|
23
|
+
name: 'Uncommented Exports',
|
|
24
|
+
impact: -Math.min(
|
|
25
|
+
20,
|
|
26
|
+
(rawData.uncommentedExports / Math.max(1, rawData.totalExports)) *
|
|
27
|
+
100 *
|
|
28
|
+
0.2
|
|
29
|
+
),
|
|
30
|
+
description: `${rawData.uncommentedExports} uncommented exports`,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Outdated Comments',
|
|
34
|
+
impact: -Math.min(60, rawData.outdatedComments * 15 * 0.6),
|
|
35
|
+
description: `${rawData.outdatedComments} outdated comments`,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Undocumented Complexity',
|
|
39
|
+
impact: -Math.min(20, rawData.undocumentedComplexity * 10 * 0.2),
|
|
40
|
+
description: `${rawData.undocumentedComplexity} complex functions lack docs`,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const recommendations: ToolScoringOutput['recommendations'] =
|
|
45
|
+
riskResult.recommendations.map((rec) => ({
|
|
46
|
+
action: rec,
|
|
47
|
+
estimatedImpact: 8,
|
|
48
|
+
priority: summary.score < 50 ? 'high' : 'medium',
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
toolName: ToolName.DocDrift,
|
|
53
|
+
score: summary.score,
|
|
54
|
+
rawMetrics: {
|
|
55
|
+
...rawData,
|
|
56
|
+
rating: summary.rating,
|
|
57
|
+
},
|
|
58
|
+
factors,
|
|
59
|
+
recommendations,
|
|
60
|
+
};
|
|
61
|
+
}
|