-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
chore: prefer string templates over string concatenation #732
Conversation
Codecov Report
@@ Coverage Diff @@
## main #732 +/- ##
==========================================
- Coverage 99.35% 99.34% -0.02%
==========================================
Files 1922 1921 -1
Lines 183098 179122 -3976
Branches 902 893 -9
==========================================
- Hits 181924 177945 -3979
- Misses 1118 1121 +3
Partials 56 56
|
Needs #733 no to fail... |
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.
Please also update vendor files, we could rename the folder later if you like to
Check #733 which excludes vendor from eslint... This should be sufficient, right? |
Done... |
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.
The performance gain is minimal and it has some implications on code readability.
Note sure, about it.
The performance gain is minimal, but the readability increases big time. At least to my taste. |
Yes: - writeFileSync(resolve(pathOutputDir, methodName + '.md'), content);
+ writeFileSync(resolve(pathOutputDir, `${methodName}.md`), content); Maybe: - return (
- this.faker.commerce.productAdjective() +
- ' ' +
- this.faker.commerce.productMaterial() +
- ' ' +
- this.faker.commerce.product()
- );
+ return `${this.faker.commerce.productAdjective()} ${this.faker.commerce.productMaterial()} ${this.faker.commerce.product()}`; (We have line breaks for a reason) Not so much: - examples: mdToHtml('```ts\n' + examples + '```'),
+ examples: mdToHtml(`\`\`\`ts\n${examples}\`\`\``), (Which characters are escaped?) Not at all: - return (
- this.Helpers.replaceSymbols('???') +
- this.faker.random.arrayElement(vowels) +
- this.faker.random.arrayElement(this.ibanLib.iso3166) +
- this.Helpers.replaceSymbols('?') +
- '1' +
- (prob < 10
- ? this.Helpers.replaceSymbols(
- '?' + this.faker.random.arrayElement(vowels) + '?'
- )
- : prob < 40
- ? this.Helpers.replaceSymbols('###')
- : '')
- );
+ return `${
+ this.Helpers.replaceSymbols('???') +
+ this.faker.random.arrayElement(vowels) +
+ this.faker.random.arrayElement(this.ibanLib.iso3166) +
+ this.Helpers.replaceSymbols('?')
+ }1${
+ prob < 10
+ ? this.Helpers.replaceSymbols(
+ `?${this.faker.random.arrayElement(vowels)}?`
+ )
+ : prob < 40
+ ? this.Helpers.replaceSymbols('###')
+ : ''
+ }`; (Because now you use nested conditional string templates in combination with string concatenation.) |
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.
One last quibble, otherwise it looks good to me.
# Conflicts: # src/finance.ts # test/finance_iban.spec.ts
# Conflicts: # src/commerce.ts # src/finance.ts # src/internet.ts # src/lorem.ts # src/system.ts # src/utils/unique.ts
# Conflicts: # src/commerce.ts # src/finance.ts # src/internet.ts # src/lorem.ts # src/system.ts # src/utils/unique.ts
@ST-DDT @Shinigami92 all changes applied... Can you re-review, please? |
String templates are more readable, compact, and a bit faster than string concatenation. Edding eslint rule to force them.
See test results here:
https://jsben.ch/dWhr2
Or benchmark yourself:
My results in node: