-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: remove a link from keyword 'never' in code examples (#6845)
- Loading branch information
1 parent
22f340a
commit 676fb23
Showing
4 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
docs_app/tools/transforms/angular-base-package/services/filterNeverAsGeneric.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
docs_app/tools/transforms/angular-base-package/services/filterNeverAsGeneric.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}; |