Open ST-DDT opened 1 month ago
Name | Link |
---|---|
Latest commit | e888b877af5f2c1fbe07023290ccb81fa43daca0 |
Latest deploy log | https://app.netlify.com/sites/fakerjs/deploys/661cef4976e84900086d8d34 |
Deploy Preview | https://deploy-preview-2814.fakerjs.dev |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.95%. Comparing base (
a9929e2
) to head (e888b87
).
Please pay extra attention when reviewing the files changed by f48dfe4 because I had to convert them by hand and I don't know why.
From the docs:
String#substr() and String#substring() are the two lesser known legacy ways to slice a string.
Have to disagree on the String#substring
part. Without having prove of it, I would say that most JS developers would know String#substring
while being unaware of String#slice
π€
I can also disable the rule permanently.
While I have some doubts about the previously explained statement, this rule would at least unify the way string slicing would be performed in the project. This might be a DX improvement (for faker developers) in itself because one has not wondered why X is used in one place while Y is used in another.
My personal rules:
substr
π
its the most deprecated onesubstring
in specific cases (as far as I know it has some specific behavior, but I would need always to look these up)slice
-1
to address elements from the endExamples:
- filePath.substring(pathLocales.length + 1, filePath.length - 3)
+ filePath.slice(pathLocales.length + 1, -3)
this is a really good change, and I like it
- fileContent.substring(0, compareIndex)
+ fileContent.slice(0, Math.max(0, compareIndex))
this is not so good, because it complexifies the code by using Math.max
and some need to more think about what's going on
-> Looks like the thing is that substring(_, negativeValue)
results always in empty string.
TBH I personally like use substring
for such cases then... π
Does the lint-rule has some options to configure it?
This only really makes sense if we manually go through cases like this and remove the ugly Math.max in places where we know compareIndex must be positive.
fileContent.slice(0, Math.max(0, compareIndex))
Ref: #2439
2439
Enables the
unicorn/prefer-string-slice
lint rule.