Skip to content

Commit 69b31da

Browse files
authored
Merge pull request microsoft#235 from Microsoft/pgonzal/api-extractor-cleanups
Disallow @summary tag
2 parents ea49d3d + b79f274 commit 69b31da

8 files changed

Lines changed: 78 additions & 29 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "The unsupported @summary tag is now reported as an error",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

‎libraries/api-extractor/src/ApiDefinitionReference.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ export default class ApiDefinitionReference {
103103
public static createFromString(apiReferenceExpr: string,
104104
reportError: (message: string) => void): ApiDefinitionReference {
105105
if (!apiReferenceExpr || apiReferenceExpr.split(' ').length > 1) {
106-
reportError('API reference expression must be of the form: ' +
107-
'\'scopeName/packageName:exportName.memberName | display text\'' +
108-
'where the \'|\' is required if a display text is provided');
106+
reportError('An API item reference must use the notation: "@scopeName/packageName:exportName.memberName"');
109107
return;
110108
}
111109

‎libraries/api-extractor/src/Tokenizer.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export default class Tokenizer {
2727
/**
2828
* Converts a doc comment string into an array of Tokens. This processing is done so that docs
2929
* can be processed more strictly.
30-
* Example: "This is a JsDoc description with a {@link URL} and more text. \@summary example \@public"
30+
* Example: "This is a JsDoc description with a {@link URL} and more text. \@remarks example \@public"
3131
* => [
3232
* {tokenType: 'text', parameter: 'This is a JsDoc description with a'},
3333
* {tokenType: '@link', parameter: 'URL'},
34-
* {tokenType: '\@summary', parameter: ''},
34+
* {tokenType: '\@remarks', parameter: ''},
3535
* {tokenType: 'text', parameter: 'example'},
3636
* {tokenType: '\@public', parameter: ''}
3737
* ]

‎libraries/api-extractor/src/definitions/ApiDocumentation.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export default class ApiDocumentation {
8585
'@public',
8686
'@returns',
8787
'@see',
88-
'@summary',
8988
'@deprecated',
9089
'@readonly',
9190
'@remarks'

‎libraries/api-extractor/src/definitions/test/ApiDocumentation.test.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,19 @@ describe('ApiDocumentation tests', function (): void {
6565
* - testInputs/example2/folder/MyDocumentedClass (10 errors)
6666
*/
6767

68-
assert.equal(capturedErrors.length, 10);
68+
assert.equal(capturedErrors.length, 8);
6969
assert.equal(capturedErrors[0].message, 'Cannot provide summary in JsDoc if @inheritdoc tag is given');
70-
assert.equal(capturedErrors[1].message, 'The JSDoc tag "@summary" is not supported in this context');
70+
assert.equal(capturedErrors[1].message, 'Unknown JSDoc tag "@badJsDocTag"');
71+
assert.equal(capturedErrors[2].message, 'Unknown tag name for inline tag.');
72+
assert.equal(capturedErrors[3].message, 'Too few parameters for @link inline tag.');
73+
assert.equal(capturedErrors[4].message, 'Unexpected text in JSDoc comment: "can not contain a tag"');
74+
assert.equal(capturedErrors[5].message, 'More than one API Tag was specified');
7175
assert.equal(
72-
capturedErrors[2].message, 'Unexpected text in JSDoc comment: "Mock class for testing JsDoc parser"'
76+
capturedErrors[6].message,
77+
'An API item reference must use the notation: "@scopeName/packageName:exportName.memberName"'
7378
);
74-
assert.equal(capturedErrors[3].message, 'Unknown JSDoc tag "@badJsDocTag"');
75-
assert.equal(capturedErrors[4].message, 'Unknown tag name for inline tag.');
76-
assert.equal(capturedErrors[5].message, 'Too few parameters for @link inline tag.');
77-
assert.equal(capturedErrors[6].message, 'Unexpected text in JSDoc comment: "can not contain a tag"');
78-
assert.equal(capturedErrors[7].message, 'More than one API Tag was specified');
7979
assert.equal(
80-
capturedErrors[8].message,
81-
'API reference expression must be of the form: \'scopeName/packageName:exportName.memberName ' +
82-
'| display text\'where the \'|\' is required if a display text is provided'
83-
);
84-
assert.equal(
85-
capturedErrors[9].message,
80+
capturedErrors[7].message,
8681
'inheritdoc source item is deprecated. Must provide @deprecated message or remove @inheritdoc inline tag.');
8782
});
8883

‎libraries/api-extractor/src/test/DocElementParser.test.ts‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ApiDocumentation from '../definitions/ApiDocumentation';
1212
import Extractor from './../Extractor';
1313
import Tokenizer from './../Tokenizer';
1414

15-
const capturedErrors: {
15+
let capturedErrors: {
1616
message: string;
1717
fileName: string;
1818
lineNumber: number;
@@ -22,6 +22,15 @@ function testErrorHandler(message: string, fileName: string, lineNumber: number)
2222
capturedErrors.push({ message, fileName, lineNumber });
2323
}
2424

25+
function clearCapturedErrors(): void {
26+
capturedErrors = [];
27+
}
28+
29+
function assertCapturedErrors(expectedMessages: string[]): void {
30+
assert.deepEqual(capturedErrors.map(x => x.message), expectedMessages,
31+
'The captured errors did not match the expected output.');
32+
}
33+
2534
const inputFolder: string = './testInputs/example2';
2635
let myDocumentedClass: ApiStructuredType;
2736

@@ -74,6 +83,7 @@ describe('DocElementParser tests', function (): void {
7483

7584
describe('Basic Tests', (): void => {
7685
it('Should parse basic doc comment stream', (): void => {
86+
clearCapturedErrors();
7787
const apiDoc: TestApiDocumentation = new TestApiDocumentation();
7888

7989
const docs: string = 'This function parses docTokens for the apiLint website ' +
@@ -129,9 +139,11 @@ describe('DocElementParser tests', function (): void {
129139
JsonFile.saveJsonFile('./lib/paramDocExpected.json', JSON.stringify(expectedParam));
130140
JsonFile.saveJsonFile('./lib/paramDocActual.json', JSON.stringify(actualParam));
131141
TestFileComparer.assertFileMatchesExpected('./lib/paramDocActual.json', './lib/paramDocExpected.json');
142+
assertCapturedErrors([]);
132143
});
133144

134145
it('Should parse @deprecated correctly', (): void => {
146+
clearCapturedErrors();
135147
const docs: string = '@deprecated - description of the deprecation';
136148
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
137149

@@ -144,9 +156,11 @@ describe('DocElementParser tests', function (): void {
144156
JsonFile.saveJsonFile('./lib/deprecatedDocExpected.json', JSON.stringify(expectedDeprecated));
145157
JsonFile.saveJsonFile('./lib/deprecatedDocActual.json', JSON.stringify(actualDeprecated));
146158
TestFileComparer.assertFileMatchesExpected('./lib/deprecatedDocActual.json', './lib/deprecatedDocExpected.json');
159+
assertCapturedErrors([]);
147160
});
148161

149162
it('Should parse @see with nested link and/or text', (): void => {
163+
clearCapturedErrors();
150164
const docs: string = 'Text describing the function’s purpose/nuances/context. \n' +
151165
'@see {@link https://github.com/OfficeDev/office-ui-fabric-react | The link will provide context}';
152166
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
@@ -170,9 +184,11 @@ describe('DocElementParser tests', function (): void {
170184
JsonFile.saveJsonFile('./lib/seeDocExpected.json', JSON.stringify(expectedSummary));
171185
JsonFile.saveJsonFile('./lib/seeDocActual.json', JSON.stringify(actualSummary));
172186
TestFileComparer.assertFileMatchesExpected('./lib/seeDocExpected.json', './lib/seeDocActual.json');
187+
assertCapturedErrors([]);
173188
});
174189

175190
it('Should parse @param with nested link and/or text', (): void => {
191+
clearCapturedErrors();
176192
const apiDoc: TestApiDocumentation = new TestApiDocumentation();
177193

178194
// Don't include the "@param" in the doc string, parseParam() expects this to be processed in a
@@ -202,9 +218,11 @@ describe('DocElementParser tests', function (): void {
202218
'./lib/nestedParamDocActual.json',
203219
'./lib/nestedParamDocExpected.json'
204220
);
221+
assertCapturedErrors([]);
205222
});
206223

207224
it('Should parse @link with url', (): void => {
225+
clearCapturedErrors();
208226
const docs: string = '{@link https://microsoft.com}';
209227
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
210228

@@ -222,11 +240,13 @@ describe('DocElementParser tests', function (): void {
222240
assert.equal(linkDocElement.referenceType, 'href');
223241
assert.equal(linkDocElement.targetUrl, 'https://microsoft.com');
224242
assert.equal(linkDocElement.value, '');
243+
assertCapturedErrors([]);
225244
});
226245

227246
it('Should parse @link with url and text', (): void => {
228-
const docs: string = '{@link https://microsoft.com | microsoft home}';
229-
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
247+
clearCapturedErrors();
248+
const docs: string = '{@link https://microsoft.com | microsoft home}';
249+
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
230250

231251
let docElements: IDocElement[];
232252
/* tslint:disable-next-line:no-any */
@@ -242,9 +262,29 @@ describe('DocElementParser tests', function (): void {
242262
assert.equal(linkDocElement.referenceType, 'href');
243263
assert.equal(linkDocElement.targetUrl, 'https://microsoft.com');
244264
assert.equal(linkDocElement.value, 'microsoft home');
265+
assertCapturedErrors([]);
266+
});
267+
268+
it('Should reject @link with missing pipe', (): void => {
269+
clearCapturedErrors();
270+
271+
const docs: string = '{@link https://microsoft.com microsoft home}';
272+
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
273+
274+
let docElements: IDocElement[];
275+
/* tslint:disable-next-line:no-any */
276+
let errorMessage: any;
277+
try {
278+
docElements = DocElementParser.parse(myDocumentedClass.documentation, tokenizer);
279+
} catch (error) {
280+
errorMessage = error;
281+
}
282+
assert.isUndefined(errorMessage);
283+
assertCapturedErrors(['Invalid @link parameter, url must be a single string.']);
245284
});
246285

247286
it('Should parse @link with API defintion reference', (): void => {
287+
clearCapturedErrors();
248288
const docs: string = '{@link @microsoft/sp-core-library:Guid.equals}';
249289
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
250290

@@ -264,9 +304,11 @@ describe('DocElementParser tests', function (): void {
264304
assert.equal(linkDocElement.packageName, 'sp-core-library');
265305
assert.equal(linkDocElement.exportName, 'Guid');
266306
assert.equal(linkDocElement.memberName, 'equals');
307+
assertCapturedErrors([]);
267308
});
268309

269310
it('Should parse @link with API defintion reference and text', (): void => {
311+
clearCapturedErrors();
270312
const docs: string = '{@link @microsoft/sp-core-library:Guid.equals | Guid equals}';
271313
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
272314

@@ -287,9 +329,11 @@ describe('DocElementParser tests', function (): void {
287329
assert.equal(linkDocElement.exportName, 'Guid');
288330
assert.equal(linkDocElement.memberName, 'equals');
289331
assert.equal(linkDocElement.value, 'Guid equals');
332+
assertCapturedErrors([]);
290333
});
291334

292335
it('Should report errors @link', (): void => {
336+
clearCapturedErrors();
293337
const docs: string = '{@link @microsoft/sp-core-library:Guid.equals | Guid equals | something}';
294338
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
295339

@@ -302,6 +346,7 @@ describe('DocElementParser tests', function (): void {
302346
errorMessage = error;
303347
}
304348
assert.isNotNull(errorMessage);
349+
assertCapturedErrors(['Invalid @link parameters, at most one pipe character allowed.']);
305350
});
306351
});
307352
});

‎libraries/api-extractor/testInputs/example2/example2-output.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@
142142
"value": ". This block is entirely valid and a correct documentation object should be built for this ApiItem."
143143
}
144144
],
145-
"remarks": [],
145+
"remarks": [
146+
{
147+
"kind": "textDocElement",
148+
"value": "Mock class for testing JsDoc parser"
149+
}
150+
],
146151
"isBeta": false,
147152
"members": {
148153
"__constructor": {

‎libraries/api-extractor/testInputs/example2/src/MyDocumentedClass.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ export function functionWithIncompleteParameterType(param1, param2: string): boo
7878
* correctly. It can contain a {@link https://bing.com/ | bing home}. This block is entirely
7979
* valid and a correct documentation object should be built for this ApiItem.
8080
*
81-
* @summary Mock class for testing JsDoc parser
8281
* @public
82+
* @remarks Mock class for testing JsDoc parser
8383
*/
84-
// (Error #2)
85-
// Error: The JSDoc tag "@summary" is not supported in this context
86-
// (Error #4)
87-
// Error: Unexpected text in JSDoc comment: "Mock class for testing JsDoc parser"
8884
export default class MyDocumentedClass {
8985

9086

0 commit comments

Comments
 (0)