build(docs-infra): throw error if using title on code snippets (#26514)

Since #26396, the `title` property is ignored and `header` should be
used instead for specifying a code snippet's header.

This commit ensures that we don't accidentally set `title` have it be
silently ignored.

PR Close #26514
This commit is contained in:
George Kalpakas
2018-10-17 17:35:20 +03:00
committed by Miško Hevery
parent d557f1d9de
commit 0add00a743
4 changed files with 94 additions and 11 deletions

View File

@ -10,6 +10,8 @@ module.exports = function renderExamples(getExampleRegion, log, createDocMessage
$runBefore: ['writing-files'],
ignoreBrokenExamples: false,
$process: function(docs) {
const titleVsHeaderErrors = [];
docs.forEach(doc => {
if (doc.renderedContent) {
// We match either `code-example` or `code-pane` elements that have a path attribute
@ -17,6 +19,14 @@ module.exports = function renderExamples(getExampleRegion, log, createDocMessage
/<(code-example|code-pane)([^>]*)>[^<]*<\/([^>]+)>/g,
(original, openingTag, attributes, closingTag) => {
const attrMap = parseAttributes(attributes);
if (attrMap.hasOwnProperty('title')) {
titleVsHeaderErrors.push(createDocMessage(
`Using the "title" attribute for specifying a ${openingTag} header is no longer supported. ` +
`Use the "header" attribute instead.\n<${openingTag}${attributes}>`, doc));
return;
}
if (attrMap.path) {
try {
if (closingTag !== openingTag) {
@ -59,6 +69,11 @@ module.exports = function renderExamples(getExampleRegion, log, createDocMessage
});
}
});
if (titleVsHeaderErrors.length) {
titleVsHeaderErrors.forEach(err => log.error(err));
throw new Error('Some code snippets use the `title` attribute instead of `header`.');
}
}
};
};