build(docs-infra): add auto-link-filter for generic words (#34835)

Fixes #34794

PR Close #34835
This commit is contained in:
Kapunahele Wong 2020-01-17 11:42:55 -05:00 committed by Matias Niemelä
parent 5b77e67dff
commit a3b2d6735a
3 changed files with 34 additions and 2 deletions

View File

@ -40,6 +40,7 @@ module.exports = new Package('angular-base', [
.factory(require('./services/auto-link-filters/filterPipes'))
.factory(require('./services/auto-link-filters/filterAmbiguousDirectiveAliases'))
.factory(require('./services/auto-link-filters/ignoreHttpInUrls'))
.factory(require('./services/auto-link-filters/ignoreGenericWords'))
.factory(require('./post-processors/add-image-dimensions'))
.factory(require('./post-processors/auto-link-code'))
@ -129,9 +130,9 @@ module.exports = new Package('angular-base', [
})
.config(function(postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, ignoreHttpInUrls) {
.config(function(postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, ignoreHttpInUrls, ignoreGenericWords) {
addImageDimensions.basePath = path.resolve(AIO_PATH, 'src');
autoLinkCode.customFilters = [ignoreHttpInUrls, filterPipes, filterAmbiguousDirectiveAliases];
autoLinkCode.customFilters = [ignoreGenericWords, ignoreHttpInUrls, filterPipes, filterAmbiguousDirectiveAliases];
postProcessHtml.plugins = [
require('./post-processors/autolink-headings'),
addImageDimensions,

View File

@ -0,0 +1,10 @@
/**
* This service is used by the autoLinkCode post-processor to ignore generic words
* that could be mistaken as classes, functions, etc.
*/
module.exports = function ignoreGenericWords() {
const ignoredWords = new Set(['a', 'create', 'error', 'group', 'request', 'value']);
return (docs, words, index) => ignoredWords.has(words[index].toLowerCase()) ? [] : docs;
};

View File

@ -0,0 +1,21 @@
const ignoreGenericWords = require('./ignoreGenericWords')();
describe('ignoreGenericWords', () => {
it('should ignore generic words in all docs', () => {
const docs = [{docType: 'package', name: 'create'}, {docType: 'class', name: 'Foo'}];
const words = ['create', 'a', 'thing'];
expect(ignoreGenericWords(docs, words, 0)).toEqual([]);
expect(ignoreGenericWords(docs, words, 1)).toEqual([]);
expect(ignoreGenericWords(docs, words, 2)).toEqual(docs);
});
it('should ignore generic words with mixed case in all docs', () => {
const docs = [{docType: 'package', name: 'create'}, {docType: 'class', name: 'Foo'}];
const words = ['Create', 'eRrOr', 'STUFF'];
expect(ignoreGenericWords(docs, words, 0)).toEqual([]);
expect(ignoreGenericWords(docs, words, 1)).toEqual([]);
expect(ignoreGenericWords(docs, words, 2)).toEqual(docs);
});
});