-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
clojure.core/subs positions #2261
Projects
Comments
I think we could just make a dedicated linter for this in |
borkdude
moved this from High priority (next release)
to Medium priority (new / enhance)
in clj-kondo
Feb 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Currently the following error appears for
(subs "012" 1 -1)
:$ echo '(subs "012" 1 -1)' | clj-kondo --lint -
:1:15: error: Expected: natural integer, received: negative integer.
On cljs this code works fine though (ie it yields
"0"
) because it delegates to Javascript'sString.substring
which swaps thestart
andend
arguments whenend
<start
and rounds any negative position up to 0 and rounds any position > s.length to s.length. So for this example it's equivalent to(subs "012" 0 1)
.In clj when either
start
orend
are not in[0, n]
an exception is thrown. Same whenend < start
.Describe the solution you'd like
Make the linter (more) in line with the clj behavior:
start
orend
are not in[0, n]
Not sure how viable option 2 is.
The text was updated successfully, but these errors were encountered: