-
-
Notifications
You must be signed in to change notification settings - Fork 945
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
refactor(random.arrayElement): remove default parameter #589
refactor(random.arrayElement): remove default parameter #589
Conversation
Should this change also apply to |
Ok cool of course I forgot to look at the test cases on such a method. |
Lines 234 to 238 in 60d3cc5
Meaning that if a local doesn't export a |
How to handle this? |
It will only fail, if both the selected and the fallback locale don't have that value. |
Please also update E.g. by changing: return (
this.faker.random.arrayElement(wordList) ||
this.faker.random.arrayElement(this.faker.definitions.word.adjective)
); to return (
wordList.length > 0 ? this.faker.random.arrayElement(wordList) : this.faker.random.arrayElement(this.faker.definitions.word.adjective)
); Maybe add a check that checks the array before calling arrayElement and throws an error that contains a the method/definition that caused it. For adjective(length?: number): string {
return selectOneWord(length, this.faker.definitions.word.adjective);
}
private selectOneWord(length?: number, words: string[]): string {
let wordList = words;
if (length) {
wordList = words.filter((word) => word.length == length);
if (!wordList.length) {
wordList = words;
}
}
return this.faker.random.arrayElement(words);
} |
Can I expect intern-provided arrays (like |
Theoretically we don't have an Maybe we should use special syntax for the definitions to make this implicitly?
(both would use the same "data source") This kind of relates to #265 and the more I think of this, the more it feels like a big change to be made in v7. |
@xDivisionByZerox In preparation of starting to review some v6.1 PRs, could you rebase this one and fix conflicts? |
Rebase is done and conflicts resolved. Haven't had time for the test and probably won't have this week either. |
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.
Due to how we handle our "module" classes, it's not possible to define private methods in them
So you need to extract selectOneWord
out of the class and define it above as a raw function (that is not exported!)
An example for that can be found here: https://github.com/faker-js/faker/pull/644/files#diff-f2b24a1df2ffea4071c80b9948ecf7ed59397468799db7ee1ec376b3c9740b06R17
Also this PR needs a rebase 🙂
Not really since the problem is the same I stated 1 month ago. |
So yeah, but as I understand this PR: This is THE bug we want to fix! |
I'll change the test to expect an Error and add a comment to expect a real value when locales were included. |
@ST-DDT Can you give insight into how the |
My opinion is that there's a non-trivial chance that this is breaking for someone. If we release this as |
I agree. We should move this to v7. |
Yes, if effectively contains all tests that are disabled for a certain locale. |
Well then this doesn't work I guess. If you have a look at the log files from
Even tho we have the following in
Or did I misunderstood you? |
Or can I remove this now since the |
The faker.fake method currently does not have an exclude handling, as it does not fail. |
author xDivisionByZerox <leyla.jaehnig@gmx.de> 1646178349 +0100 committer Shinigami92 <chrissi92@hotmail.de> 1648155830 +0100 parent 7635dc9 author xDivisionByZerox <leyla.jaehnig@gmx.de> 1646178349 +0100 committer Shinigami92 <chrissi92@hotmail.de> 1648155650 +0100 refactor: remove default param from arrayElement fix: unhandled nullish array refactor: nullish type check Co-authored-by: Shinigami <chrissi92@hotmail.de> refactor: remove default value from arrayElements refactor: remove arrayElements default value from jsdocs refactor: word methods implementation chore: fix lint error refactor: word methods implementation
@xDivisionByZerox Can you split the word improvements to its own PR? |
Well you yourself suggested this change in this PR. This logic is not required to change if this PR is not in place. So a separate PR should IMO be dismissed because it doesn't provide any meaningful architectural refactoring/performance boosting. |
But yeah, I can provide a separate PR if you wish to merge this in 6.3.0. |
It simplifies the code by removing duplicate code. IMO that is worth enough. |
I will close this PR due to MASSIV changes in the file structure. I will provide a new PR with changes discussed in this PR. |
Fixes #581.