Skip to content

Commit df434cc

Browse files
authored
Upgrade Eastwood (#188)
1 parent 6ca2d6b commit df434cc

File tree

11 files changed

+73
-223
lines changed

11 files changed

+73
-223
lines changed

.circleci/config.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ commands:
99
- v2-dependencies-{{ checksum "project.clj" }}
1010
# fallback to using the latest cache if no exact match is found
1111
- v2-dependencies-
12-
- run: lein with-profile -dev,+ci,+test,+refactor-nrepl deps
12+
- run: lein with-profile -user,-dev,+ci,+test,+refactor-nrepl deps
1313
- save_cache:
1414
paths:
1515
- ~/.m2
@@ -70,6 +70,8 @@ jobs:
7070
command: << parameters.lein_test_command >>
7171
- run:
7272
command: .circleci/e2e.sh
73+
- run:
74+
command: lein with-profile -user,+test eastwood
7375
deploy:
7476
executor: openjdk8
7577
steps:
@@ -79,13 +81,13 @@ jobs:
7981
command: echo -e "$GPG_KEY_V2" | gpg --import
8082
- run:
8183
name: Perform pre-release sanity check
82-
command: lein with-profile -dev,+ci,+ncrw run -m nedap.ci.release-workflow.api sanity-check
84+
command: lein with-profile -user,-dev,+ci,+ncrw run -m nedap.ci.release-workflow.api sanity-check
8385
- run:
8486
name: release to JFrog
85-
command: lein deploy
87+
command: lein with-profile -user deploy
8688
- run:
8789
name: release to Clojars
88-
command: lein deploy clojars
90+
command: lein with-profile -user deploy clojars
8991

9092
test_code_filters: &test_code_filters
9193
filters:
@@ -101,57 +103,45 @@ workflows:
101103
- test_code:
102104
name: "JDK 8 including refactor-nrepl"
103105
jdk_version: openjdk8
104-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl do clean, test
105-
<<: *test_code_filters
106-
- test_code:
107-
name: "JDK 8 including refactor-nrepl, and parallel Eastwood linters"
108-
jdk_version: openjdk8-parallel
109-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl,+parallel-eastwood do clean, test
106+
lein_test_command: lein with-profile -user,-dev,+ci,+refactor-nrepl do clean, test
110107
<<: *test_code_filters
111108
- test_code:
112109
name: "JDK 8 including refactor-nrepl (at its latest version)"
113110
jdk_version: openjdk8
114-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl-latest do clean, test
111+
lein_test_command: lein with-profile -user,-dev,+ci,+refactor-nrepl-latest do clean, test
115112
<<: *test_code_filters
116113
- test_code:
117114
name: "JDK 8 excluding refactor-nrepl"
118115
jdk_version: openjdk8
119-
lein_test_command: lein with-profile -dev,+ci do clean, test
116+
lein_test_command: lein with-profile -user,-dev,+ci do clean, test
120117
<<: *test_code_filters
121118
- test_code:
122119
name: "JDK 8, with an old clojurescript dependency on the classpath"
123120
jdk_version: openjdk8
124-
lein_test_command: lein with-profile -dev,-provided,+ci,+cljs-old do clean, test
121+
lein_test_command: lein with-profile -user,-dev,-provided,+ci,+cljs-old do clean, test
125122
<<: *test_code_filters
126123
- test_code:
127124
name: "JDK 11 including refactor-nrepl"
128125
jdk_version: openjdk11
129-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl do clean, test
130-
<<: *test_code_filters
131-
- test_code:
132-
name: "JDK 11 including refactor-nrepl, and parallel Eastwood linters"
133-
jdk_version: openjdk11-parallel
134-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl,+parallel-eastwood do clean, test
126+
lein_test_command: lein with-profile -user,-dev,+ci,+refactor-nrepl do clean, test
135127
<<: *test_code_filters
136128
- test_code:
137129
name: "JDK 11 including refactor-nrepl (at its latest version)"
138130
jdk_version: openjdk11
139-
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl-latest do clean, test
131+
lein_test_command: lein with-profile -user,-dev,+ci,+refactor-nrepl-latest do clean, test
140132
<<: *test_code_filters
141133
- test_code:
142134
name: "JDK 11 excluding refactor-nrepl"
143135
jdk_version: openjdk11
144-
lein_test_command: lein with-profile -dev,+ci do clean, test
136+
lein_test_command: lein with-profile -user,-dev,+ci do clean, test
145137
<<: *test_code_filters
146138
- deploy:
147139
context: JFrog
148140
requires:
149141
- "JDK 8, with an old clojurescript dependency on the classpath"
150-
- "JDK 8 including refactor-nrepl, and parallel Eastwood linters"
151142
- "JDK 8 including refactor-nrepl"
152143
- "JDK 8 excluding refactor-nrepl"
153144
- "JDK 11 including refactor-nrepl"
154-
- "JDK 11 including refactor-nrepl, and parallel Eastwood linters"
155145
- "JDK 11 excluding refactor-nrepl"
156146
filters:
157147
branches:

project.clj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(def eastwood-version "0.9.9")
2+
13
;; Please don't bump the library version by hand - use ci.release-workflow instead.
24
(defproject formatting-stack "4.4.0-alpha1"
35
;; Please keep the dependencies sorted a-z.
@@ -10,7 +12,7 @@
1012
[com.nedap.staffing-solutions/utils.modular "2.2.0-alpha3"]
1113
[com.nedap.staffing-solutions/utils.spec.predicates "1.1.0"]
1214
[io.reflectoring.diffparser/diffparser "1.4"]
13-
[jonase/eastwood "0.3.14"]
15+
[jonase/eastwood ~eastwood-version]
1416
[medley "1.2.0"]
1517
[org.clojure/clojure "1.10.1"]
1618
[org.clojure/java.classpath "1.0.0"]
@@ -55,7 +57,8 @@
5557

5658
:monkeypatch-clojure-test false
5759

58-
:plugins [[lein-pprint "1.1.2"]]
60+
:plugins [[lein-pprint "1.1.2"]
61+
[jonase/eastwood ~eastwood-version]]
5962

6063
;; A variety of common dependencies are bundled with `nedap/lein-template`.
6164
;; They are divided into two categories:
@@ -102,9 +105,9 @@
102105
[integrant "0.8.0"]
103106
[org.clojure/clojurescript "1.7.228"]]}
104107

105-
:provided {:dependencies [[org.clojure/clojurescript "1.10.597"]
106-
[com.stuartsierra/component "0.4.0"]
107-
[integrant "0.8.0"]]
108+
:provided {:dependencies [[org.clojure/clojurescript "1.10.597"]
109+
[com.stuartsierra/component "0.4.0"]
110+
[integrant "0.8.0"]]
108111
:managed-dependencies [[com.cognitect/transit-clj "1.0.324"]
109112
[com.google.code.findbugs/jsr305 "3.0.2"]
110113
[com.google.errorprone/error_prone_annotations "2.1.3"]
@@ -131,14 +134,12 @@
131134
;; (and shipped with this refactor-nrepl):
132135
:plugins [[cider/cider-nrepl "0.24.0"]]}
133136

134-
:parallel-eastwood {:jvm-opts ["-Dformatting-stack.eastwood.parallelize-linters=true"]}
135-
136-
:ncrw {:global-vars {*assert* true} ;; `ci.release-workflow` relies on runtime assertions
137+
:ncrw {:global-vars {*assert* true} ;; `ci.release-workflow` relies on runtime assertions
137138
:source-paths ^:replace []
138139
:test-paths ^:replace []
139140
:resource-paths ^:replace []
140141
:plugins ^:replace []
141142
:dependencies ^:replace [[com.nedap.staffing-solutions/ci.release-workflow "1.12.0"]]}
142143

143-
:ci {:pedantic? :abort
144-
:jvm-opts ["-Dclojure.main.report=stderr"]}})
144+
:ci {:pedantic? :abort
145+
:jvm-opts ["-Dclojure.main.report=stderr"]}})

resources/eastwood/config/formatting_stack.clj

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/formatting_stack/linters/eastwood.clj

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,30 @@
55
[eastwood.lint]
66
[formatting-stack.linters.eastwood.impl :as impl]
77
[formatting-stack.protocols.linter :as linter]
8-
[formatting-stack.util :refer [ns-name-from-filename]]
8+
[formatting-stack.util :refer [ns-name-from-filename silence]]
99
[medley.core :refer [assoc-some deep-merge]]
1010
[nedap.utils.modular.api :refer [implement]])
1111
(:import
1212
(java.io File)))
1313

1414
(def default-eastwood-options
15-
;; Avoid false positives or undesired checks:
16-
(let [linters (remove #{:suspicious-test :unused-ret-vals :constant-test :wrong-tag}
17-
eastwood.lint/default-linters)]
18-
(-> eastwood.lint/default-opts
19-
(assoc :linters linters
20-
:rethrow-exceptions? true))))
21-
22-
(def parallelize-linters? (System/getProperty "formatting-stack.eastwood.parallelize-linters"))
23-
24-
(def config-filename "formatting_stack.clj")
25-
26-
(assert (io/resource (str (io/file "eastwood" "config" config-filename)))
27-
"The formatting-stack config file must exist and be prefixed by `eastwood/config`
28-
(note that this prefix must not be passed to Eastwood itself).")
15+
(-> eastwood.lint/default-opts
16+
(assoc :rethrow-exceptions? true)))
2917

3018
(defn lint! [{:keys [options]} filenames]
3119
(let [namespaces (->> filenames
3220
(remove #(str/ends-with? % ".edn"))
3321
(keep ns-name-from-filename))
3422
reports (atom nil)
35-
exceptions (atom nil)
36-
output (with-out-str
37-
(binding [*warn-on-reflection* true]
38-
(try
39-
(cond-> options
40-
true (assoc :namespaces namespaces)
41-
parallelize-linters? (update :builtin-config-files conj config-filename)
42-
true (eastwood.lint/eastwood (impl/->TrackingReporter reports)))
43-
(catch Exception e
44-
(swap! exceptions conj e)))))]
23+
exceptions (atom nil)]
24+
25+
(silence
26+
(try
27+
(-> options
28+
(assoc :namespaces namespaces)
29+
(eastwood.lint/eastwood (impl/->TrackingReporter reports)))
30+
(catch Exception e
31+
(swap! exceptions conj e))))
4532
(->> @reports
4633
:warnings
4734
(map :warn-data)
@@ -53,8 +40,7 @@
5340
:filename (if (string? uri-or-file-name)
5441
uri-or-file-name
5542
(-> ^File uri-or-file-name .getCanonicalPath)))))
56-
(concat (impl/warnings->reports output)
57-
(impl/exceptions->reports @exceptions)))))
43+
(into (impl/exceptions->reports @exceptions)))))
5844

5945
(defn new [{:keys [eastwood-options]
6046
:or {eastwood-options {}}}]

src/formatting_stack/linters/eastwood/impl.clj

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,6 @@
55
[formatting-stack.protocols.spec :as protocols.spec]
66
[nedap.speced.def :as speced]))
77

8-
(speced/defn ^boolean? contains-dynamic-assertions?
9-
"Does this linting result refer to a :pre/:post containing dynamic assertions?
10-
11-
See https://git.io/fhQTx"
12-
[{{{ast-form :form} :ast} :wrong-pre-post
13-
msg :msg}]
14-
(let [[_fn* fn-tails] (if (coll? ast-form)
15-
ast-form
16-
[])
17-
[_arglist & body] (if (coll? fn-tails)
18-
fn-tails
19-
[])]
20-
(->> body
21-
(some (fn [form]
22-
(when (and (coll? form)
23-
(= 'clojure.core/assert
24-
(first form)))
25-
(let [v (second form)
26-
v-name (when (symbol? v)
27-
(name v))]
28-
(and v-name
29-
(string/includes? msg v-name) ;; make sure it's the same symbol as in msg
30-
(= \*
31-
(first v-name)
32-
(last v-name)))))))
33-
(boolean))))
34-
35-
(speced/defn ^::protocols.spec/reports warnings->reports
36-
[^string? warnings]
37-
(->> warnings
38-
(re-seq #"(.*):(\d+):(\d+): Reflection warning - (.+)\.")
39-
(map (fn [[_, filename, line, column, msg]]
40-
{:filename filename
41-
:line (Long/parseLong line)
42-
:column (Long/parseLong column)
43-
:msg msg
44-
:level :warning
45-
:source :eastwood/warn-on-reflection}))))
46-
478
(speced/defn ^::protocols.spec/reports exceptions->reports
489
[exceptions]
4910
(->> exceptions

src/formatting_stack/strategies.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
A strategy may not return nil."
1414
(:require
1515
[clojure.string :as string]
16-
[clojure.tools.namespace.repl :refer [refresh-dirs]]
16+
[clojure.tools.namespace.repl :as tools.namespace.repl]
1717
[formatting-stack.protocols.spec :as protocols.spec]
1818
[formatting-stack.strategies.impl :as impl]
1919
[formatting-stack.strategies.impl.git-status :as git-status]
@@ -163,7 +163,9 @@
163163
and then ensuring that code-evaluating tools such as refactor-nrepl or Eastwood also respect that exclusion.
164164
165165
That can avoid some code-reloading issues related to duplicate `defprotocol` definitions, etc."
166-
[& {:keys [^::protocols.spec/filenames files]}]
166+
[& {:keys [^::protocols.spec/filenames files
167+
refresh-dirs]
168+
:or {refresh-dirs tools.namespace.repl/refresh-dirs}}]
167169
{:pre [(check! seq refresh-dirs
168170
(partial every? (speced/fn [^string? refresh-dir]
169171
(let [file (-> refresh-dir File.)]

test/functional/formatting_stack/linters/eastwood.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
"test-resources/eastwood_warning.clj"
2929
(matchers/in-any-order
30-
[{:source :eastwood/warn-on-reflection
31-
:msg "reference to field getPath can't be resolved"
30+
[{:source :eastwood/reflection
31+
:msg "reference to field getPath can't be resolved."
3232
:line pos-int?
3333
:column pos-int?
34-
:warning-details-url matchers/absent
34+
:warning-details-url "https://github.com/jonase/eastwood#reflection"
3535
:filename "test-resources/eastwood_warning.clj"}
3636
{:source :eastwood/def-in-def
3737
:line pos-int?

test/integration/formatting_stack/strategies.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[clojure.set :as set]
66
[clojure.string :as string]
77
[clojure.test :refer [deftest is testing use-fixtures]]
8+
[clojure.tools.namespace.repl :as tools.namespace.repl]
89
[formatting-stack.strategies :as sut]
910
[formatting-stack.test-helpers :as test-helpers :refer [git-integration-dir]]
1011
[formatting-stack.util :refer [rcomp]]
@@ -233,7 +234,11 @@
233234
(deftest namespaces-within-refresh-dirs-only
234235
(speced/let [^{::speced/spec (rcomp count (partial < 100))}
235236
all-files (sut/all-files :files [])
236-
result (sut/namespaces-within-refresh-dirs-only :files all-files)]
237+
refresh-dirs (->> tools.namespace.repl/refresh-dirs
238+
(mapv (rcomp (partial io/file git-integration-dir)
239+
str)))
240+
result (sut/namespaces-within-refresh-dirs-only :files all-files
241+
:refresh-dirs refresh-dirs)]
237242
(is (seq result)
238243
"Returns non-empty results (since f-s itself has namespaces within `src`, `test`, etc)")
239244

0 commit comments

Comments
 (0)