-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
📎 Implement useConsistentStringFunctions
- unicorn prefer-string-trim-start-end
prefer-string-slice
#2817
Comments
Can I pick this issue? |
@chansuke I have started implementing it, but haven't worked on it for a while so sure why not. One insight I can provide, that substring and slice are not identical unicorn/prefer-string-slice provides a lot of complex fixes which require type inference or static analysis which biome does not support yet. For Biome lets provide simple fixes and in other cases diagnostic error is good enough. |
Because of this we should certainly create a dedicate rule for unicorn/prefer-string-slice? |
If we are only including unicorn/prefer-string-trim-start-end and unicorn/prefer-string-slice under From implementation standpoint detection is not hard, fixes requiring type inferences are, but we don't need to implement them right now (if at all?), so it's fine. The only case I see that maybe some users would like to disable substring part, I feel that is unlikely, but in that case we could provide an option. Because of that I lean towards keeping them together. |
Looks fair to me. |
Based on discussion on #3039 (comment) this rule should be split into two separate ones. To allow easier implementation, documentation and being more consistent with other rules. Sorry for the trouble @chansuke |
@minht11 |
Should it be:
? Thanks. |
The unicorn rules don't retrieve type information. So, these rules apply to all methods named
Note that I use the negation form here because I think it is more appropriate and consistent with our existing rules. In the future we might decide to introduce new rules that make use of type information. These rules could be called I didn't add the |
My intention was to provide users with clear and detailed information, even if it is redundant. However, if the following plan is
But I also agree with emphasizing consistency and |
That is very interesting point useFlatMap would not be good example because it doesn't only match arrays but also any iterator Though while unicorn does use static analysis sometimes for fixes and parameters, it does not use it to find method itself and they still call it prefer-string When we have type inference in Biome, but are in pure javascript environment where nothing is typed is Biome gonna stop finding issues for this rule? We can't know if value is a string, because everything is any, so in that regard nothing is gonna change, for that kind of project type inference does not help. I see type inference more like false positive prevention, in cases where we know categorically that value is never a string. That would not be breaking change, but a fix.
Edit: I started to look into how I would name array apis: So technically only |
Anyway, I think it is a small thing. Choose the name you prefer and I think we are good for that. |
Taking a look at the implementation, I wonder if we should also handle cases like: - const f = foo.substr;
+ const f = foo.slice; |
Description
Implement unicorn/prefer-string-trim-start-end and unicorn/prefer-string-slice
The rules themeselves are straightforward, and naming
useConsistentStringFunctions
fits them, question I have should this rule include other string related operation rules such as prefer-string-replace-all and prefer-string-starts-ends-with if yes is the current name appropriate?Will work on this rule.The text was updated successfully, but these errors were encountered: