Skip to content
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

Open
1 task done
eval opened this issue Jan 22, 2024 · 1 comment
Open
1 task done

clojure.core/subs positions #2261

eval opened this issue Jan 22, 2024 · 1 comment
Projects

Comments

@eval
Copy link

eval commented Jan 22, 2024

  • I have read the Clojure etiquette and will respect it when communicating on this platform.

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's String.substring which swaps the start and end arguments when end < 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 or end are not in [0, n] an exception is thrown. Same when end < start.

Describe the solution you'd like
Make the linter (more) in line with the clj behavior:

  1. emit when end < start
  2. emit when either start or end are not in [0, n]

Not sure how viable option 2 is.

@borkdude
Copy link
Member

I think we could just make a dedicated linter for this in clj-kondo.impl.analyzer.

@borkdude borkdude added this to Needs triage in clj-kondo via automation Jan 22, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Jan 22, 2024
@borkdude 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
Labels
None yet
Projects
clj-kondo
  
Medium priority (new / enhance)
Development

No branches or pull requests

2 participants