diff --git a/aio/tools/transforms/angular-base-package/index.js b/aio/tools/transforms/angular-base-package/index.js index 836170636b..7a163afbe3 100644 --- a/aio/tools/transforms/angular-base-package/index.js +++ b/aio/tools/transforms/angular-base-package/index.js @@ -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, diff --git a/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.js b/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.js new file mode 100644 index 0000000000..5d3dab84d6 --- /dev/null +++ b/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.js @@ -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; +}; diff --git a/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.spec.js b/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.spec.js new file mode 100644 index 0000000000..de843a3c23 --- /dev/null +++ b/aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.spec.js @@ -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); + }); +}); + +