Permalink
Browse files

Work on 'deprecated' linter

  • Loading branch information...
1 parent dbf6c07 commit b0ae73e78e8aaa6c8087760ea90c258c8db9a46c @jonase committed Jan 12, 2012
Showing with 32 additions and 11 deletions.
  1. +5 −3 src/brittle/core.clj
  2. +3 −1 src/eastwood/core.clj
  3. +24 −7 src/eastwood/linters/deprecated.clj
View
@@ -1,7 +1,7 @@
(ns brittle.core
(:use clojure.java.io)) ; Naked use
-(def *rebind-me* nil) ; non-dynamic, already checked by the compiler
+#_(def *rebind-me* nil) ; non-dynamic, already checked by the compiler
(def ^:private unused) ; Never used
@@ -13,5 +13,7 @@
(replicate 1 0) ; deprecated
(.length s))
-(defn hour [] ;; Deprecated!
- (.getHour ^java.util.Date (java.util.Date.)))
+
+
+(defn hour [] ;; Deprecated x 2!
+ (.getHours (java.util.Date. 2012 21 12)))
View
@@ -1,10 +1,12 @@
+(set! *warn-on-reflection* false)
(ns eastwood.core
(:require [analyze.core :as analyze]
[clojure.string :as string]
[clojure.set :as set]
[eastwood.linters.core :as linters]
[eastwood.linters.deprecated :as deprecated]))
+
(defn analyze [ns-sym]
(let [source-file (-> (name ns-sym)
(string/replace "." "/")
@@ -33,4 +35,4 @@
(doseq [ns namespaces]
(lint exprs ns))))
-;(lint-ns 'brittle.core :exclude [:naked-use])
+;(lint-ns 'brittle.core :only [:deprecations])
@@ -1,31 +1,48 @@
(ns eastwood.linters.deprecated
- (:use [analyze.util :only [expr-seq]]))
+ (:use [analyze.util :only [expr-seq print-expr]]))
(defmulti deprecated :op)
(defmethod deprecated :var [expr]
(-> expr :var meta :deprecated))
+(defn java-is-deprecated? [obj]
+ (->> obj
+ .getAnnotations
+ (map #(.annotationType %))
+ (some #{java.lang.Deprecated})))
+
(defmethod deprecated :instance-method [expr]
+ ;(println "GOTHERE")
(->> expr
:Expr-obj
.method
- .getAnnotations
- (map #(.annotationType %))
- (some #{java.lang.Deprecated})))
+ java-is-deprecated?))
+
+#_(defmethod deprecated :new [expr]
+ (println "GOTHERE")
+ (->> expr
+ :Expr-obj
+ .ctor
+ java-is-deprecated?))
+
+(defmethod deprecated :default [_]
+ (println (:op _))
+ false)
-(defmethod deprecated :default [_])
(defmulti report-deprecated :op)
(defmethod report-deprecated :var [expr]
(println (:var expr) "is deprecated"))
(defmethod report-deprecated :instance-method [expr]
- (println "Instance method" (-> expr :method :name)
- "on" (-> expr :method :declaring-class)
+ (println "Instance method" (str \" (-> expr :Expr-obj .method) \")
"is deprecated."))
+(defmethod report-deprecated :new [expr]
+ (println "Constructor" (str \" (-> expr :Expr-obj .ctor) \") "is deprecated"))
+
(defn deprecations [exprs]
(doseq [expr exprs
dexpr (filter deprecated (expr-seq expr))]

0 comments on commit b0ae73e

Please sign in to comment.