Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 7817f71

Browse files
committed
chore(api doc gen): reduce false positives
- Don't report ambiguous links for deprecated modules; instead resolve them by default to their respective modules. E.g., `{@link NgControl}` will resolve to the type in `@angular/common/src/forms-deprecated` when referenced from with `forms-deprecated` and to the type in `@angular/forms` when referenced within `forms`. - Missing API docs are now reported at log-level 'info' rather than 'warn'. - Don't warn about issues that are due to bug angular/dgeni-packages#192.
1 parent 510aae5 commit 7817f71

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

tools/api-builder/angular.io-package/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ module.exports = new Package('angular.io', [basePackage, targetPackage, cheatshe
8989

9090
.config(function(getLinkInfo) {
9191
getLinkInfo.useFirstAmbiguousLink = false;
92+
// TODO(chalin): remove once the deprecated angular modules are dropped.
93+
getLinkInfo.resolveAmbiguityForDeprecatedModules = true;
94+
// TODO(chalin): remove the following once this issue is fixed:
95+
// https://github.com/angular/dgeni-packages/issues/192
96+
getLinkInfo.isInvalidLinkOk = function (url, doc) {
97+
return (url === 'CanActivateAnnotation' || url === 'RouteConfigAnnotation') &&
98+
doc && doc.path.includes('router-deprecated');
99+
}
92100
})
93101

94102

tools/api-builder/docs-package/processors/addNotYetDocumentedProperty.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ module.exports = function addNotYetDocumentedProperty(EXPORT_DOC_TYPES, log, cre
2323
}
2424

2525
if (doc.notYetDocumented) {
26-
// TODO: (ericjim) should I remove this?
27-
log.warn(createDocMessage("Not yet documented", doc));
26+
log.info(createDocMessage("Not yet documented", doc));
2827
}
2928
});
3029

@@ -35,4 +34,4 @@ module.exports = function addNotYetDocumentedProperty(EXPORT_DOC_TYPES, log, cre
3534

3635
function notYetDocumented(doc) {
3736
return !doc.noDescription && doc.description.trim().length == 0;
38-
}
37+
}

tools/api-builder/links-package/services/getLinkInfo.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ var path = require('canonical-path');
1313
*/
1414
module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
1515

16+
var deprecatedModuleName, indexOfDepDoc = -1, indexOfOtherDoc = -1;
17+
18+
function isAmbiguityOk(docs) {
19+
if (docs.length != 2) return false;
20+
21+
// Tolerate deprecated modules having an ambiguity with its non-deprecated counterpart.
22+
docs.forEach(function (doc, index) {
23+
var matches = doc.fileInfo.relativePath.match(/\/(\w+)-deprecated\//);
24+
if (matches) {
25+
deprecatedModuleName = matches[1];
26+
indexOfDepDoc = index;
27+
} else {
28+
indexOfOtherDoc = index;
29+
}
30+
});
31+
return indexOfDepDoc >= 0 &&
32+
docs[indexOfOtherDoc].fileInfo.relativePath.match(new RegExp('\/'+deprecatedModuleName+'\/'));
33+
}
34+
35+
// Assumes that isAmbiguityOk(docs) has just been invoked.
36+
function ambiguityResolver(docs, url) {
37+
return url.indexOf('-deprecated') < 0 ? indexOfOtherDoc : indexOfDepDoc;
38+
}
39+
1640
return function getLinkInfoImpl(url, title, currentDoc) {
1741
var linkInfo = {
1842
url: url,
@@ -26,8 +50,9 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
2650
}
2751

2852
var docs = getDocFromAlias(url, currentDoc);
53+
var isAmbOk = getLinkInfoImpl.resolveAmbiguityForDeprecatedModules && isAmbiguityOk(docs);
2954

30-
if ( !getLinkInfoImpl.useFirstAmbiguousLink && docs.length > 1 ) {
55+
if ( !getLinkInfoImpl.useFirstAmbiguousLink && docs.length > 1 && !isAmbOk ) {
3156

3257
linkInfo.valid = false;
3358
linkInfo.errorType = 'ambiguous';
@@ -36,16 +61,17 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
3661

3762
} else if ( docs.length >= 1 ) {
3863

39-
linkInfo.url = docs[0].path;
40-
linkInfo.title = title || encodeCodeBlock(docs[0].name, true);
64+
const i = isAmbOk ? ambiguityResolver(docs, url) : 0;
65+
linkInfo.url = docs[i].path;
66+
linkInfo.title = title || encodeCodeBlock(docs[i].name, true);
4167
linkInfo.type = 'doc';
4268

4369
if ( getLinkInfoImpl.relativeLinks && currentDoc && currentDoc.path ) {
4470
var currentFolder = path.dirname(currentDoc.path);
4571
var docFolder = path.dirname(linkInfo.url);
4672
var relativeFolder = path.relative(path.join('/', currentFolder), path.join('/', docFolder));
4773
linkInfo.url = path.join(relativeFolder, path.basename(linkInfo.url));
48-
log.debug(currentDoc.path, docs[0].path, linkInfo.url);
74+
log.debug(currentDoc.path, docs[i].path, linkInfo.url);
4975
}
5076

5177
} else if ( url.indexOf('#') > 0 ) {
@@ -56,9 +82,11 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
5682

5783
} else if ( url.indexOf('/') === -1 && url.indexOf('#') !== 0 ) {
5884

59-
linkInfo.valid = false;
60-
linkInfo.errorType = 'missing';
61-
linkInfo.error = 'Invalid link (does not match any doc): "' + url + '"';
85+
if ( getLinkInfoImpl.isInvalidLinkOk && !getLinkInfoImpl.isInvalidLinkOk(url, currentDoc) ) {
86+
linkInfo.valid = false;
87+
linkInfo.errorType = 'missing';
88+
linkInfo.error = 'Invalid link (does not match any doc): "' + url + '"';
89+
}
6290

6391
} else {
6492

0 commit comments

Comments
 (0)