-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-base-to-string] add option to prevent usage of Array .join on non-toString things #3388
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
Comments
THis definitely makes sense as something to lint for, but I don't think it should be a brand new rule. I think this would work well as an extension / additional option in our no-base-to-string rule, which already does these checks, just not on a |
That sounds great! Turns out I’m already using that rule, but didn’t remember it when writing this issue. |
This comment was marked as spam.
This comment was marked as spam.
Would it make sense to also prevent calling // both resolve to `[object Object],[object Object]`
[{}, {}].toString();
`${[{}, {}]}`; |
@ronami The latter case would already be covered by restrict-template-expressions. It's not as granular as "the elements must be |
(Note: I couldn’t find any issue template/info about feature requests, I hope this is ok! 🙏 )
Summary: Disallow
.join()
calls onArray
s that aren’tArray<string>
.Motivation:
I had a function like this:
I had trouble with using too much
string
types an mixing stuff up, so I introduced anAbsolutePath
type to help me, and replacedstring
withAbsolutePath
in many places.When I had fixed all compile errors, I had accidentally introduced a bug!
noCommonRoot
now outputs:Oops!
I searched for
.join
in the entire project and switched to using this function instead, to avoid this problem in the future:That way I could fix the
noCommonRoot
function:Bonus: my
join
function requires the separator argument. That would be nice to lint too. The default","
is never what I want.The text was updated successfully, but these errors were encountered: