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

Linter for redundant nesting #2212

Open
tomdl89 opened this issue Nov 6, 2023 · 0 comments
Open

Linter for redundant nesting #2212

tomdl89 opened this issue Nov 6, 2023 · 0 comments

Comments

@tomdl89
Copy link
Contributor

tomdl89 commented Nov 6, 2023

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Is your feature request related to a problem? Please describe.
Nesting certain variadic functions/macros is redundant, and is usually confusing. We could catch this quite easily. E.g:

(min 5 2 (min 3 7))
;; => 2
(min 5 2 3 7)
;; => 2

(* 3 4 (* 5 6))
;; => 360
(* 3 4 5 6)
;; => 360

(str "foo" "bar" (str "baz" "qux"))
;; => "foobarbazqux"
(str "foo" "bar" "baz" "qux")
;; => "foobarbazqux"

(concat [1 2] [3 4] (concat [5 6] [7 8]))
;; => (1 2 3 4 5 6 7 8)
(concat [1 2] [3 4] [5 6] [7 8])
;; => (1 2 3 4 5 6 7 8)

Describe the solution you'd like
When one of these functions/macros is nested within itself, raise a warning.

Additional context
From a cursory browse of clojure.core, this is a list of functions which could be included:
* *' + +' and comp concat every-pred lazy-cat max merge min or some-fn str

The redundant do and let linters are already present, but I guess a similar idea.

I knocked up the code for it here: https://github.com/tomdl89/clj-kondo/tree/redundant-nesting and can submit as a PR if there's interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant