Skip to content

Commit bb828ec

Browse files
(maint) fix eastwood issues
This fixes and ignores issues found by eastwood.
1 parent 512a819 commit bb828ec

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
lines changed

project.clj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
;; see https://github.com/puppetlabs/trapperkeeper/pull/306#issuecomment-1467059264
4444
[puppetlabs/kitchensink nil :exclusions [cheshire]]
4545
[puppetlabs/i18n]
46-
[nrepl/nrepl]]
46+
[nrepl/nrepl]
47+
[io.github.clj-kondo/config-slingshot-slingshot "1.0.0"]]
4748

4849
:deploy-repositories [["releases" {:url "https://clojars.org/repo"
4950
:username :env/clojars_jenkins_username
@@ -72,5 +73,22 @@
7273
[jonase/eastwood "1.2.2" :exclusions [org.clojure/clojure]]
7374
[puppetlabs/i18n "0.9.2"]]
7475

76+
:eastwood {:ignored-faults {:reflection {puppetlabs.trapperkeeper.logging [{:line 92}]
77+
puppetlabs.trapperkeeper.internal [{:line 128}]
78+
puppetlabs.trapperkeeper.testutils.logging true
79+
puppetlabs.trapperkeeper.testutils.logging-test true
80+
puppetlabs.trapperkeeper.services.nrepl.nrepl-service-test true
81+
puppetlabs.trapperkeeper.plugins-test true}
82+
:local-shadows-var {puppetlabs.trapperkeeper.config-test true
83+
puppetlabs.trapperkeeper.services-test true
84+
java-service-example.java-service true
85+
puppetlabs.trapperkeeper.optional-deps-test true}
86+
:deprecations {puppetlabs.trapperkeeper.testutils.logging true
87+
puppetlabs.trapperkeeper.testutils.logging-test true
88+
puppetlabs.trapperkeeper.logging-test true}
89+
:def-in-def {puppetlabs.trapperkeeper.optional-deps-test true}}
90+
91+
:continue-on-exception true}
92+
7593
:main puppetlabs.trapperkeeper.main)
7694

src/puppetlabs/trapperkeeper/internal.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
compilation / instantiation, and inspects it to see if the error data map
109109
represents a missing trapperkeeper service or function. If so, throws a
110110
more meaningful exception. If not, re-throws the original exception."
111-
[e]
111+
[^ExceptionInfo e]
112112
{:pre [(instance? ExceptionInfo e)]}
113113
(let [data (ex-data e)]
114114
(condp = (:error data)

src/puppetlabs/trapperkeeper/logging.clj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns puppetlabs.trapperkeeper.logging
2-
(:import [ch.qos.logback.classic Level PatternLayout]
2+
(:import [ch.qos.logback.classic Level LoggerContext PatternLayout]
33
(ch.qos.logback.core ConsoleAppender)
44
(org.slf4j Logger LoggerFactory)
55
(ch.qos.logback.classic.joran JoranConfigurator))
@@ -8,7 +8,9 @@
88
[puppetlabs.i18n.core :as i18n]))
99

1010
(defn logging-context
11-
[]
11+
^LoggerContext []
12+
;; in practice, this returns ch.qos.logback.classic.LoggerContext
13+
;; which the other functions below assume
1214
(LoggerFactory/getILoggerFactory))
1315

1416
(defn reset-logging
@@ -18,8 +20,8 @@
1820
(def root-logger-name Logger/ROOT_LOGGER_NAME)
1921

2022
(defn root-logger
21-
[]
22-
(LoggerFactory/getLogger root-logger-name))
23+
^ch.qos.logback.classic.Logger []
24+
(LoggerFactory/getLogger ^String root-logger-name))
2325

2426
(defn catch-all-logger
2527
"A logging function useful for catch-all purposes, that is, to
@@ -72,7 +74,7 @@
7274
(let [root (root-logger)]
7375
(.addAppender root (create-console-appender level))
7476
(when (> (.toInt (.getLevel root))
75-
(.toInt level))
77+
(.toInt ^Level level))
7678
(.setLevel root level)))))
7779

7880
(defn configure-logger!
@@ -84,8 +86,8 @@
8486
ch.qos.logback.core.classic.joran.JoranConfigurator."
8587
[logging-conf]
8688
(let [configurator (JoranConfigurator.)
87-
context (LoggerFactory/getILoggerFactory)]
88-
(.setContext configurator (LoggerFactory/getILoggerFactory))
89+
context (logging-context)]
90+
(.setContext configurator context)
8991
(.reset context)
9092
(.doConfigure configurator logging-conf)))
9193

src/puppetlabs/trapperkeeper/plugins.clj

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns puppetlabs.trapperkeeper.plugins
2-
(:import (java.util.jar JarFile)
2+
(:import (java.util.jar JarEntry JarFile)
33
(java.io File))
44
(:require [clojure.java.io :refer [file]]
55
[clojure.tools.logging :as log]
@@ -9,7 +9,7 @@
99
(defn- should-process?
1010
"Helper for `process-file`. Answers whether or not the duplicate detection
1111
code should process a file with the given name."
12-
[name]
12+
[^String name]
1313
(and
1414
;; ignore directories
1515
(not (or (.isDirectory (file name))
@@ -25,11 +25,11 @@
2525
"Helper for `process-file`; handles a found duplicate. Throws an exception
2626
if the duplicate is a .class or .clj file. Otherwise, logs a warning and
2727
returns the accumulator."
28-
[container-filename acc filename]
28+
[container-filename acc ^String filename]
2929
(let [error-msg (i18n/trs "Class or namespace {0} found in both {1} and {2}"
3030
filename container-filename (acc filename))]
3131
(if (or (.endsWith filename ".class") (.endsWith filename ".clj"))
32-
(throw (IllegalArgumentException. error-msg))
32+
(throw (IllegalArgumentException. ^String error-msg))
3333

3434
;; It is common to have other conflicts (besides classes and clojure
3535
;; namespaces), especially during development (for example,
@@ -57,20 +57,20 @@
5757
(let [file (file container-filename)]
5858
(if (.exists file)
5959
(let [filenames (if (.isDirectory file)
60-
(map #(.getPath %) (file-seq file))
61-
(map #(.getName %) (enumeration-seq (.entries (JarFile. file)))))]
60+
(map #(.getPath ^File %) (file-seq file))
61+
(map #(.getName ^JarEntry %) (enumeration-seq (.entries (JarFile. file)))))]
6262
(reduce (partial process-file container-filename) acc filenames))
63-
acc ; There may be directories on the classpath that do not exist.
64-
)))
63+
acc))) ; There may be directories on the classpath that do not exist.
64+
6565

6666
(defn jars-in-dir
6767
"Given a path to a directory on disk, returns a collection of all of the .jar
6868
files contained in that directory (not recursive)."
69-
[dir]
69+
[^File dir]
7070
{:pre [(instance? File dir)]
7171
:post [(coll? %)
7272
(every? (partial instance? File) %)]}
73-
(filter #(.endsWith (.getAbsolutePath %) ".jar") (.listFiles dir)))
73+
(filter #(.endsWith (.getAbsolutePath ^File %) ".jar") (.listFiles dir)))
7474

7575
(defn verify-no-duplicate-resources
7676
"Examines all resources on the classpath and contained in the given directory
@@ -97,9 +97,9 @@
9797
(if (.exists plugins)
9898
(do
9999
(verify-no-duplicate-resources plugins)
100-
(doseq [jar (jars-in-dir plugins)]
100+
(doseq [^File jar (jars-in-dir plugins)]
101101
(log/info (i18n/trs "Adding plugin {0} to classpath." (.getAbsolutePath jar)))
102102
(kitchensink/add-classpath jar)
103103
(kitchensink/add-classpath jar (clojure.lang.RT/baseLoader))))
104-
(throw (IllegalArgumentException.
105-
(i18n/trs "Plugins directory {0} does not exist" plugins-path)))))))
104+
(let [^String msg (i18n/trs "Plugins directory {0} does not exist" plugins-path)]
105+
(throw (IllegalArgumentException. msg)))))))

src/puppetlabs/trapperkeeper/services_internal.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns puppetlabs.trapperkeeper.services-internal
2-
(:import (clojure.lang IFn))
2+
(:import (clojure.lang IFn Namespace))
33
(:require [clojure.set :refer [difference union intersection]]
44
[schema.core :as schema]
55
[puppetlabs.kitchensink.core :as ks]
@@ -79,8 +79,9 @@
7979
(schema/defn ^:always-validate var->symbol :- Symbol
8080
"Returns a symbol for the var, including its namespace"
8181
[fn-var :- Var]
82-
(symbol (str (-> fn-var meta :ns .name))
83-
(str (-> fn-var meta :name))))
82+
(let [m (meta fn-var)]
83+
(symbol (str (.name ^Namespace (:ns m)))
84+
(str (:name m)))))
8485

8586
(schema/defn ^:always-validate transform-deps-map :- (schema/pred vector?)
8687
"Given a map of required and optional dependencies, return a vector that

test/puppetlabs/trapperkeeper/testutils/logging.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@
337337
(one-element?)))))
338338

339339
(defmethod clojure.test/assert-expr 'logged? [is-msg form]
340-
"Asserts that exactly one event in *test-log-events* has a message
341-
that matches msg-or-pred. The match is performed via = if
342-
msg-or-pred is a string, via re-find if msg-or-pred is a pattern, or
343-
via (msg-or-pred event-map) if msg-or-pred is a function. If level
344-
is specified, the message's keyword level (:info, :error, etc.) must
345-
also match. For example:
346-
(with-test-logging (log/info \"123\") (is (logged? #\"2\")))."
340+
;"Asserts that exactly one event in *test-log-events* has a message
341+
;that matches msg-or-pred. The match is performed via = if
342+
;msg-or-pred is a string, via re-find if msg-or-pred is a pattern, or
343+
;via (msg-or-pred event-map) if msg-or-pred is a function. If level
344+
;is specified, the message's keyword level (:info, :error, etc.) must
345+
;also match. For example:
346+
; (with-test-logging (log/info \"123\") (is (logged? #\"2\")))."
347347
(assert (#{2 3} (count form)))
348348
(let [[_ msg-or-pred level] form]
349349
`(let [events# @@#'puppetlabs.trapperkeeper.testutils.logging/*test-log-events*]

0 commit comments

Comments
 (0)