Fork me on GitHub
#clj-kondo
<
2022-02-09
>
borkdude15:02:59

If you want clj-kondo to find "redundant fn wrappers" please take this for a spin!

clojure -Sdeps '{:deps {clj-kondo/clj-kondo {:git/url "" :git/sha "2cc9777752d9f54ed91baa4c6ddaa0c2b8812049"}}}' -M -m clj-kondo.main --config "^:replace {:linters {:redundant-fn-wrapper {:level :warning}}}" --lint src
and 🙏 report any false positives as a reply to this message.

🤞 2
☝️ 1
⚠️ 1
wilkerlucio17:02:44

is this a false positive?

(defn sub-sequence? [seq-a seq-b]
  (->> (map #(= % %2) seq-a seq-b)
       (every? true?)))

wilkerlucio17:02:00

(Im guessing its not, I can replace #(= % %2) with =, is this what this linter is looking for?)

dpsutton15:02:30

can you paste an inline config that uses only that linter? Quite interested to run it but will get lots of other output at the moment (i think)

dpsutton15:02:58

something like "^:replace {:linters {??}}"

borkdude15:02:15

yes, exactly that

borkdude15:02:31

or maybe {:linters ^:replace {}}

borkdude15:02:34

not sure anymore :)

😂 1
dpsutton15:02:59

"--config ^:replace {:linters {:redundant-fn-wrappers :warning}}" i guess?

borkdude15:02:13

is this bash?

borkdude15:02:27

you must then spit --config out of the string

borkdude15:02:40

--config "..."

dpsutton15:02:36

zsh but yeah

dpsutton15:02:07

i threw

(defn foo [x]
  (let [inc' #(inc %)]
    (inc' x)))
in a file i’m working on and
clojure -Sdeps '{:deps {clj-kondo/clj-kondo {:git/url "" :git/sha "2cc9777752d9f54ed91baa4c6ddaa0c2b8812049"}}}' -M -m clj-kondo.main --config "^:replace {:linters {:redundant-fn-wrapper :warning}}" --lint src
and got no warning

borkdude15:02:15

--config "^:replace {:linters {:redundant-fn-wrapper {:level :warning}}}"
worked for me locally here

borkdude15:02:43

hmm I'll try that example

borkdude16:02:10

hmm, with the version I previously compiled, but maybe not with the branch. taking a closer look

👍 1
borkdude16:02:56

it also works for me when I remove that config, there must be something wrong with that part

borkdude16:02:10

this is with my compiled version (which is slightly behind on the branch)

borkdude16:02:25

This worked:

$ clojure -Sdeps '{:deps {clj-kondo/clj-kondo {:git/url "" :git/sha "2cc9777752d9f54ed91baa4c6ddaa0c2b8812049"}}}' -M -m clj-kondo.main --config "^:replace {:linters {:redundant-fn-wrapper {:level :warning}}}" --lint /tmp/dude.clj

dpsutton16:02:06

ah, it needs a map with {:level :warning}

dpsutton16:02:09

success! #(vector? %) ha

dpsutton16:02:59

oh nice, it caught a multi-arity map version

borkdude16:02:27

can you show?

dpsutton16:02:28

(map (fn [join rhs]
       (rhso join rhs))
     joins rhses)
is of course (map rhso joins rhses)

dpsutton16:02:44

the single arity versions are easy to see. i didn’t notice this one right away

dpsutton16:02:36

you should ping ghadi about this

borkdude16:02:43

yeah, I've done that

👍 1
borkdude16:02:56

he found one in nubank's code

borkdude16:02:38

I think I'll disable this linter by default, what do you think?

borkdude16:02:57

For some reason I write #(genysm) a lot

dpsutton16:02:43

makes me think of some core set of default enabled linters, and an easy way to enable all new linters that haven’t made their way into core yet?

dpsutton16:02:56

but yeah i agree maybe not by default. but i wonder how many people use non-default linters

borkdude16:02:58

right, the original cause for this linter was that beginners tend to write (update foo :bar #(inc %))

borkdude16:02:06

and those beginners might not enable a non-default linter

borkdude16:02:59

Maybe I can make it opt-in for 1 quarter and then enable it by default

borkdude16:02:12

to get rid of initial false positives

borkdude20:02:07

clj-kondo, a linter for clojure (code) that sparks joy, v2022.02.09 clj-kondo 2022.02.09. • Feature https://github.com/clj-kondo/clj-kondo/issues/1549: detect and warn on cyclic task dependencies in bb.edn (https://github.com/mknoszlig) • Feature https://github.com/clj-kondo/clj-kondo/issues/1547: catch tasks undefined tasks present in `:depends`. (https://github.com/mknoszlig) • Feature https://github.com/clj-kondo/clj-kondo/issues/783: `:keys` can be used in `:ret` position, also fixes types return map call as input for another typed map function. (https://github.com/pfeodrippe) • Feature https://github.com/clj-kondo/clj-kondo/issues/1526: detect redundant fn wrappers, like `#(inc %)`. See https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#redundant-fn-wrapper. This linter is :off by default, but may be enabled by default in future versions after more testing. • Feature https://github.com/clj-kondo/clj-kondo/issues/1560: lint task definition keys in bb.edn (https://github.com/mknoszlig) • Feature https://github.com/clj-kondo/clj-kondo/issues/1484: Add analysis information about protocol implementations. (https://github.com/ericdallo) • Fix https://github.com/clj-kondo/clj-kondo/issues/1563: vector inside list should not be linted as function call when inside tagged literal. • Fix https://github.com/clj-kondo/clj-kondo/issues/1540: imported class flagged as unused when it only appears in annotation metadata. • Fix https://github.com/clj-kondo/clj-kondo/issues/1571: ignore spliced reader conditionals wrt. namespace sorting. • Fix https://github.com/clj-kondo/clj-kondo/issues/1574: def usage context contains reference of the re-frame reg-sub it is used in. (https://github.com/benedekfazekas)

👍 6
🎉 7
borkdude22:02:39

For people not noticing that @lee posted a link to a commit where he applied :redundant-fn-wrapper , he did. @ericdallo Perhaps clojure-lsp could also automatically clean this :)

ericdallo23:02:12

@borkdude we can for sure create a code action on clojure-lsp to auto remove that when that lint exists on the line :)

ericdallo23:02:34

What do you think about a linter :simplify-not-equal which check if you typed (not (= :foo :bar)) suggesting to replace with (not= :foo :bar) ?

borkdude23:02:17

there's been a previous attempt to this but it wasn't so clear cut that one form is always desirable over another

☝️ 1
👍 1
Darin Douglass23:02:26

(not (= …)) all the way :)