Fork me on GitHub
#clj-kondo
<
2024-01-19
>
eval202012:01:23

Before opening an issue: would it be feasible to also err when end < start in the following case?

$ echo '(subs "foo" 1 -1)' | clj-kondo --lint -
<stdin>:1:15: error: Expected: natural integer, received: negative integer.
On cljs the above code works fine: it delegates to js’ String.substring which swaps the positions when end < start and rounds any negative position up to 0 and rounds any position > s.length to s.length. clj errs when start or end is outside [0,n] or when end < start. To help writing compatible code, the linter would not only check for type but also emit an error when end < start .

borkdude12:01:14

yeah we could add that as a check

borkdude12:01:33

but only for clj I'd say

eval202012:01:57

👍 not familiar with clj-kondo design-goals when it comes to clj/cljs-compat, but it could be a warning in cljs?

eval202012:01:08

Will open an issue, thx.

borkdude12:01:31

yes, it could be a warning in cljs only

borkdude12:01:44

eh in clj only I mean

borkdude12:01:00

so if you write a .cljc file, you'd get only a warning if the expression occurs in something that is relevant to clj

borkdude12:01:20

since in cljs it's valid to so those negative indexes and it might be on purpose, unless the docstring says it's not ok to do so in cljs

eval202012:01:07

If in clj end < start yields an error, shouldn’t the linter emit an error?

borkdude12:01:50

yes, is that contradictory to anything I said? :)

eval202012:01:05

> borkdude [1:33 PM] > yes, it could be a warning in cljs only > borkdude [1:33 PM] > eh in clj only I mean

eval202012:01:51

Anyway, an error in clj sounds good 🙂