/
warn_earmuff.clj
27 lines (25 loc) · 1.32 KB
/
warn_earmuff.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;; Copyright (c) Nicola Mometto, Rich Hickey & contributors.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns clojure.tools.analyzer.passes.warn-earmuff
(:require [clojure.tools.analyzer.utils :refer [dynamic?]]))
(defn warn-earmuff
"Prints a warning to *err* if the AST node is a :def node and the
var name contains earmuffs but the var is not marked dynamic"
{:pass-info {:walk :pre :depends #{}}}
[ast]
(let [name (str (:name ast))]
(when (and (= :def (:op ast))
(> (count name) 2) ;; Allow * and ** as non-dynamic names
(= (nth name 0) \*)
(= (nth name (dec (count name))) \*)
(not (dynamic? (:var ast) (:val (:meta ast)))))
(binding [*out* *err*]
(println "Warning:" name "not declared dynamic and thus is not dynamically rebindable,"
"but its name suggests otherwise."
"Please either indicate ^:dynamic" name "or change the name"))))
ast)