From f5335d17ec1d11611ac605229c0a52375f338801 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 10 May 2017 10:22:51 +0100 Subject: [PATCH] build(aio): fail the doc-gen if there is an invalid `{@link ...}` tag This fail behaviour is only turned on for `yarn docs`; in `yarn docs-watch` you only receive a warning. This is because you can get false errors when watching since we don't parse all the docs in that case. --- aio/tools/transforms/angular.io-package/index.js | 6 +++++- .../links-package/inline-tag-defs/link.js | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/aio/tools/transforms/angular.io-package/index.js b/aio/tools/transforms/angular.io-package/index.js index 1834957db0..77ac13f9e1 100644 --- a/aio/tools/transforms/angular.io-package/index.js +++ b/aio/tools/transforms/angular.io-package/index.js @@ -25,7 +25,11 @@ module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPacka renderDocsProcessor.extraData.versionInfo = versionInfo; }) - .config(function(checkAnchorLinksProcessor) { + .config(function(checkAnchorLinksProcessor, linkInlineTagDef) { + + // Fail the processing if there is an invalid link + linkInlineTagDef.failOnBadLink = true; + checkAnchorLinksProcessor.$enabled = true; // since we encode the HTML to JSON we need to ensure that this processor runs before that encoding happens. checkAnchorLinksProcessor.$runBefore = ['convertToJsonProcessor']; diff --git a/aio/tools/transforms/links-package/inline-tag-defs/link.js b/aio/tools/transforms/links-package/inline-tag-defs/link.js index 2b24828bad..e957a22e81 100644 --- a/aio/tools/transforms/links-package/inline-tag-defs/link.js +++ b/aio/tools/transforms/links-package/inline-tag-defs/link.js @@ -9,23 +9,29 @@ var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/; * @param {Function} docs error message * @return {String} The html link information * - * @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc + * @property {boolean} failOnBadLink Whether to throw an error (aborting the processing) if a link is invalid. */ module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage, log) { return { name: 'link', aliases: ['linkDocs'], + failOnBadLink: false, description: 'Process inline link tags (of the form {@link some/uri Some Title}), replacing them with HTML anchors', - handler: function(doc, tagName, tagDescription) { + handler(doc, tagName, tagDescription) { // Parse out the uri and title - return tagDescription.replace(INLINE_LINK, function(match, uri, title) { + return tagDescription.replace(INLINE_LINK, (match, uri, title) => { var linkInfo = getLinkInfo(uri, title, doc); if (!linkInfo.valid) { - log.warn(createDocMessage(linkInfo.error, doc)); + const message = createDocMessage(linkInfo.error, doc); + if (this.failOnBadLink) { + throw new Error(message); + } else { + log.warn(message); + } } return '' + linkInfo.title + '';