Skip to content

Commit

Permalink
Add :unused-as rule
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed May 27, 2018
1 parent bf7adf2 commit c87d223
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions core/data/core.joke
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,11 @@

;redefine let and loop with destructuring
(defn ^:private destructure [bindings]
(let [bents (partition 2 bindings)
(let [mark-as (fn [s]
(if (and *linter-mode* (false? (:unused-as (:rules *linter-config*))))
(vary-meta s assoc :skip-unused true)
s))
bents (partition 2 bindings)
pb (fn pb [bvec b v]
(let [pvec
(fn [bvec b val]
Expand All @@ -2491,7 +2495,7 @@
n
(nnext bs)
true)
(= firstb :as) (pb ret (second bs) gvec)
(= firstb :as) (pb ret (mark-as (second bs)) gvec)
:else (if seen-rest?
(throw (ex-info "Unsupported binding form, only :as can follow & parameter" {:form bindings}))
(recur (pb (if has-rest
Expand All @@ -2516,7 +2520,7 @@
(conj gmap) (conj `(if (seq? ~gmap) (apply array-map__ (seq ~gmapseq)) ~gmap))
((fn [ret]
(if (:as b)
(conj ret (:as b) gmap)
(conj ret (mark-as (:as b)) gmap)
ret))))
bes (let [transforms
(reduce
Expand Down
2 changes: 1 addition & 1 deletion core/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ func parseLetLoop(obj Object, isLoop bool, ctx *ParseContext) *LetExpr {

if !isSkipUnused(b) {
for _, b := range ctx.localBindings.bindings {
if !b.isUsed && !b.name.Equals(SYMBOLS.underscore) {
if !b.isUsed && !b.name.Equals(SYMBOLS.underscore) && !isSkipUnused(b.name) {
printParseWarning(GetPosition(b.name), "unused binding: "+b.name.ToString(false))
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/linter/as/.joker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:rules {:unused-as false}}
2 changes: 2 additions & 0 deletions tests/linter/as/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(let [{:keys [k] :as m} {}] k)
(let [[f :as v] []] f)
Empty file added tests/linter/as/output.txt
Empty file.

0 comments on commit c87d223

Please sign in to comment.