-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bugs to ignore Capital letter at the beginning of the Sentence #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add test case for this bug?
We want to prevent regression.
src/word-utils.js
Outdated
*/ | ||
export function expandWordsToAcronym(words) { | ||
//XMLHttpRequest -> XHR | ||
if (words.length === 1) { | ||
return expandOneWordToAcronym(words[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good interface that always return an array.
return [expandOneWordToAcronym(words[0]))
This change will remove unnessary Array.isArray
code from https://github.com/textlint-rule/textlint-rule-unexpanded-acronym/pull/6/files#diff-8c133963a70d07eee0bd3b0a4e71f38eR72
var acronyms = acronymCreator.extractAcronym();
- //if the acronyms is a string i.e. only one acronym
- if(!Array.isArray(acronyms)){
- if (isWordSatisfy(acronyms)) {
- expandedAcronymList.push(acronyms);
- }
- //if the acronyms is an array of acronym, we need - to extract the satisfied ones
- }else{
acronyms.forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
- }
src/word-utils.js
Outdated
* @returns {string} | ||
* @example XMLHttpRequest -> XHR | ||
* @example World Health Organization -> WHO | ||
* @param words (array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not JSDoc.
* @param words (array) | |
* @param {string[]} words |
Changes fixed |
@azu hello, could you please review my changes? thanks |
I have the following sentence where the acronym "AWS" is being reported as unexpanded. Will this PR fix this issue?
|
Hello, any update on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry to delay.
Hi, @azu
As I was using this rule on my documents, I found a bug that if there is a capital letter at the beginning of the sentence and there is an explanation to an acronym right after it, the rule won't extract the right acronym for the comparison. Here is an example:
In this case, previously the rule will extract
IAWS
to compare withAWS
because "the" is anacronymJoiningWords
, which generates an error message.In order to fix it, I first reverse the
AcronymCreater
array and loop using reduce and add the first character to beginning on every iteration and finally join on every iteration and push to result arrayThen check this array using
isWordSatidfy
method and push the good ones toexpandedAcronymList
to compare withAWS
.I added this test case in the
textlint-rule-unexpanded-acronym-test.js
and it passed all the previous test as well.I also update the
array-includes
package to the latest version.Cheers!