Skip to content

Commit f2102eb

Browse files
committed
feat(plugin-jsdocs): include end line number
1 parent d347c0f commit f2102eb

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

e2e/plugin-jsdocs-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ exports[`PLUGIN collect report with jsdocs-plugin NPM package > should run JSDoc
201201
"coverage": 0,
202202
"missing": [
203203
{
204+
"endLine": 3,
204205
"kind": "function",
205206
"name": "notRealisticFunction",
206207
"startLine": 1,
@@ -221,6 +222,7 @@ exports[`PLUGIN collect report with jsdocs-plugin NPM package > should run JSDoc
221222
"coverage": 0.5,
222223
"missing": [
223224
{
225+
"endLine": 5,
224226
"kind": "function",
225227
"name": "mapEventToCustomEvent",
226228
"startLine": 3,
@@ -287,6 +289,7 @@ exports[`PLUGIN collect report with jsdocs-plugin NPM package > should run JSDoc
287289
"coverage": 0,
288290
"missing": [
289291
{
292+
"endLine": 1,
290293
"kind": "variable",
291294
"name": "someVariable",
292295
"startLine": 1,
@@ -406,6 +409,7 @@ exports[`PLUGIN collect report with jsdocs-plugin NPM package > should run JSDoc
406409
"coverage": 0.5,
407410
"missing": [
408411
{
412+
"endLine": 17,
409413
"kind": "method",
410414
"name": "sendEvent",
411415
"startLine": 15,
@@ -472,6 +476,7 @@ exports[`PLUGIN collect report with jsdocs-plugin NPM package > should run JSDoc
472476
"coverage": 0,
473477
"missing": [
474478
{
479+
"endLine": 5,
475480
"kind": "property",
476481
"name": "title",
477482
"startLine": 5,

packages/plugin-jsdocs/mocks/node.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function nodeMock(options: {
1212
getJsDocs: () => (options.isCommented ? ['Comment'] : []),
1313
getName: () => 'test',
1414
getStartLineNumber: () => options.line,
15+
getEndLineNumber: () => options.line,
1516
getDeclarations: () => [],
1617
// Only for classes
1718
getMethods: () => [],

packages/plugin-jsdocs/src/lib/runner/__snapshots__/doc-processor.unit.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ exports[`getDocumentationReport > should produce a full report 1`] = `
77
"covered": 1,
88
"missing": [
99
{
10+
"endLine": 4,
1011
"kind": "class",
1112
"name": "test",
1213
"startLine": 4,
1314
},
1415
{
16+
"endLine": 5,
1517
"kind": "class",
1618
"name": "test",
1719
"startLine": 5,
@@ -26,11 +28,13 @@ exports[`getDocumentationReport > should produce a full report 1`] = `
2628
"covered": 1,
2729
"missing": [
2830
{
31+
"endLine": 8,
2932
"kind": "enum",
3033
"name": "test",
3134
"startLine": 8,
3235
},
3336
{
37+
"endLine": 9,
3438
"kind": "enum",
3539
"name": "test",
3640
"startLine": 9,
@@ -53,6 +57,7 @@ exports[`getDocumentationReport > should produce a full report 1`] = `
5357
"covered": 2,
5458
"missing": [
5559
{
60+
"endLine": 15,
5661
"kind": "interface",
5762
"name": "test",
5863
"startLine": 15,
@@ -83,11 +88,13 @@ exports[`getDocumentationReport > should produce a full report 1`] = `
8388
"covered": 2,
8489
"missing": [
8590
{
91+
"endLine": 10,
8692
"kind": "type",
8793
"name": "test",
8894
"startLine": 10,
8995
},
9096
{
97+
"endLine": 11,
9198
"kind": "type",
9299
"name": "test",
93100
"startLine": 11,

packages/plugin-jsdocs/src/lib/runner/doc-processor.integration.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('processJsDocs', () => {
2525
kind: 'class',
2626
name: 'ExampleClass',
2727
startLine: 1,
28+
endLine: 1,
2829
},
2930
],
3031
},
@@ -63,6 +64,7 @@ describe('processJsDocs', () => {
6364
kind: 'method',
6465
name: 'exampleMethod',
6566
startLine: 5,
67+
endLine: 7,
6668
},
6769
],
6870
},
@@ -101,6 +103,7 @@ describe('processJsDocs', () => {
101103
kind: 'interface',
102104
name: 'ExampleInterface',
103105
startLine: 1,
106+
endLine: 1,
104107
},
105108
],
106109
},
@@ -139,6 +142,7 @@ describe('processJsDocs', () => {
139142
kind: 'variable',
140143
name: 'exampleVariable',
141144
startLine: 1,
145+
endLine: 1,
142146
},
143147
],
144148
},
@@ -177,6 +181,7 @@ describe('processJsDocs', () => {
177181
kind: 'property',
178182
name: 'exampleProperty',
179183
startLine: 5,
184+
endLine: 5,
180185
},
181186
],
182187
},
@@ -215,6 +220,7 @@ describe('processJsDocs', () => {
215220
kind: 'type',
216221
name: 'ExampleType',
217222
startLine: 1,
223+
endLine: 1,
218224
},
219225
],
220226
},
@@ -253,6 +259,7 @@ describe('processJsDocs', () => {
253259
kind: 'enum',
254260
name: 'ExampleEnum',
255261
startLine: 1,
262+
endLine: 1,
256263
},
257264
],
258265
},

packages/plugin-jsdocs/src/lib/runner/doc-processor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Node = {
2323
getKind: () => SyntaxKind;
2424
getName: () => string | undefined;
2525
getStartLineNumber: () => number;
26+
getEndLineNumber: () => number;
2627
getJsDocs: () => JSDoc[];
2728
};
2829

@@ -33,13 +34,14 @@ type Node = {
3334
*/
3435
export function getVariablesInformation(
3536
variableStatements: VariableStatement[],
36-
) {
37+
): Node[] {
3738
return variableStatements.flatMap(variable => {
3839
// Get parent-level information
3940
const parentInfo = {
4041
getKind: () => variable.getKind(),
4142
getJsDocs: () => variable.getJsDocs(),
4243
getStartLineNumber: () => variable.getStartLineNumber(),
44+
getEndLineNumber: () => variable.getEndLineNumber(),
4345
};
4446

4547
// Map each declaration to combine parent info with declaration-specific info
@@ -125,6 +127,7 @@ function getCoverageFromAllNodesOfFile(nodes: Node[], filePath: string) {
125127
kind: singularCoverageType(nodeType),
126128
name: node.getName(),
127129
startLine: node.getStartLineNumber(),
130+
endLine: node.getEndLineNumber(),
128131
},
129132
],
130133
}),

packages/plugin-jsdocs/src/lib/runner/doc-processor.unit.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('getDocumentationReport', () => {
6161
>([
6262
{
6363
startLine: 1,
64+
endLine: 1,
6465
kind: 'function',
6566
name: 'test',
6667
},
@@ -97,6 +98,7 @@ describe('getVariablesInformation', () => {
9798
getKind: () => 'const',
9899
getJsDocs: () => ['some docs'],
99100
getStartLineNumber: () => 42,
101+
getEndLineNumber: () => 44,
100102
getDeclarations: () => [mockDeclaration],
101103
};
102104

@@ -109,13 +111,15 @@ describe('getVariablesInformation', () => {
109111
getKind: expect.any(Function),
110112
getJsDocs: expect.any(Function),
111113
getStartLineNumber: expect.any(Function),
114+
getEndLineNumber: expect.any(Function),
112115
getName: expect.any(Function),
113116
});
114117
// It must be defined
115118
expect(result[0]!.getName()).toBe('testVariable');
116119
expect(result[0]!.getKind()).toBe('const');
117120
expect(result[0]!.getJsDocs()).toEqual(['some docs']);
118121
expect(result[0]!.getStartLineNumber()).toBe(42);
122+
expect(result[0]!.getEndLineNumber()).toBe(44);
119123
});
120124

121125
it('should handle multiple declarations in a single variable statement', () => {
@@ -128,6 +132,7 @@ describe('getVariablesInformation', () => {
128132
getKind: () => 'let',
129133
getJsDocs: () => [],
130134
getStartLineNumber: () => 10,
135+
getEndLineNumber: () => 10,
131136
getDeclarations: () => mockDeclarations,
132137
};
133138

@@ -153,6 +158,7 @@ describe('getVariablesInformation', () => {
153158
getKind: () => 'const',
154159
getJsDocs: () => [],
155160
getStartLineNumber: () => 1,
161+
getEndLineNumber: () => 1,
156162
getDeclarations: () => [],
157163
};
158164

0 commit comments

Comments
 (0)