Skip to content

Commit

Permalink
docs: remove a link from keyword 'never' in code examples (#6845)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakovljevic-mladen authored Mar 8, 2022
1 parent 22f340a commit 676fb23
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs_app/tools/transforms/angular-base-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = new Package('angular-base', [
.factory(require('./services/filterPipes'))
.factory(require('./services/filterAmbiguousDirectiveAliases'))
.factory(require('./services/filterFromInImports'))
.factory(require('./services/filterNeverAsGeneric'))
.factory(require('./services/getImageDimensions'))

.factory(require('./post-processors/add-image-dimensions'))
Expand Down Expand Up @@ -132,10 +133,10 @@ module.exports = new Package('angular-base', [
computePathsProcessor.pathTemplates = [{ docTypes: ['example-region'], getOutputPath: function () {} }];
})

.config(function (postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, filterFromInImports) {
.config(function (postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, filterFromInImports, filterNeverAsGeneric) {
addImageDimensions.basePath = path.resolve(AIO_PATH, 'src');
autoLinkCode.customFilters = [filterPipes, filterAmbiguousDirectiveAliases];
autoLinkCode.wordFilters = [filterFromInImports];
autoLinkCode.wordFilters = [filterFromInImports, filterNeverAsGeneric];
postProcessHtml.plugins = [
require('./post-processors/autolink-headings'),
addImageDimensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const filterFromInImports = require('./filterFromInImports')();
const words = ['import', ' { ', 'from', ' } ', 'from', ' \'', 'rxjs', '\';'];
const words2 = [' } ', 'from', '(', 'of'];

describe('filterFromInImports(word, index, words)', () => {
describe('filterFromInImports(words, index)', () => {
it('should not filter the word, if the word is not "from"', () => {
expect(filterFromInImports(words, 0)).toEqual(false);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const filterNeverAsGeneric = require('./filterNeverAsGeneric')();

const words = ['const', ' ', 'never', ': ', 'Observable', '<', 'never', '>;'];

describe('filterNeverAsGeneric(words, index)', () => {
it('should not filter the word, if the word is not "never"', () => {
expect(filterNeverAsGeneric(words, 0)).toEqual(false);
});

it('should not filter the word, if the word "never" is not positioned between < and > signs', () => {
expect(filterNeverAsGeneric(words, 2)).toEqual(false);
});

it('should filter "never" when "never" is positioned between < and > signs', () => {
expect(filterNeverAsGeneric(words, 6)).toEqual(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This filter is filtering word 'never' when 'never' appears as
* generic type. For example, next line:
*
* ```
* const NEVER: Observable<never>;
* ```
*
* will filter 'never' in generic declaration of Observable type.
*
* This filter is not perfect at all and does not include many
* cases, such as multiple generic parameter (e.g. <string, never>),
* but it should be enough to cover the most use cases.
*/
module.exports = function filterNeverAsGeneric(): (words: string[], index: number) => boolean {
return (words: string[], index: number) => {
const previousWord = words[index - 1];
const nextWord = words[index + 1];

return words[index] === 'never' && /</.test(previousWord) && />/.test(nextWord);
};
};

0 comments on commit 676fb23

Please sign in to comment.