Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Eastwood #188

Merged
merged 3 commits into from
Sep 16, 2021
Merged

Upgrade Eastwood #188

merged 3 commits into from
Sep 16, 2021

Conversation

vemv
Copy link
Contributor

@vemv vemv commented Sep 3, 2021

Brief

Long due one!

Some of the changes in Eastwood that are most relevant to f-s:

QA plan

For the Eastwood changes, I'd recommend linting large projects and verifying/fixing that the newly enabled linters aren't being problematic. Please report any false positives.

For the runner change, one can (formatting-stack.core/format) and observe that the background runner keeps doing its job.

Author checklist

  • I have QAed the functionality
  • The PR has a reasonably reviewable size and a meaningful commit history
  • I have run the branch formatter and observed no new/significative warnings
  • The build passes
  • I have self-reviewed the PR prior to assignment
  • Additionally, I have code-reviewed iteratively the PR considering the following aspects in isolation:
    • Correctness
    • Robustness (red paths, failure handling etc)
    • Test coverage
    • Spec coverage
    • Documentation
    • Security
    • Performance
    • Breaking API changes
      • The runner change is "breaking" (changed a type from Future to Thread), at the same that ns is quite clearly not an API
      • e.g. we've never received a GH issue about the runner, so presumably nobody is hacking runner
    • Cross-compatibility (Clojure/ClojureScript)

Reviewer checklist

  • I have checked out this branch and reviewed it locally, running it
  • I have QAed the functionality
  • I have reviewed the PR
  • Additionally, I have code-reviewed iteratively the PR considering the following aspects in isolation:
    • Correctness
    • Robustness (red paths, failure handling etc)
    • Test coverage
    • Spec coverage
    • Documentation
    • Security
    • Performance
    • Breaking API changes
    • Cross-compatibility (Clojure/ClojureScript)

@@ -9,7 +9,7 @@ commands:
- v2-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v2-dependencies-
- run: lein with-profile -dev,+ci,+test,+refactor-nrepl deps
- run: lein with-profile -user,-dev,+ci,+test,+refactor-nrepl deps
Copy link
Contributor Author

@vemv vemv Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added -user everywhere, lately I've realised that this makes commands more reproducible. It saves time that people can copy-paste commands into their terminal, resting assured that ~/.lein won't interfere.

We use this in e.g. all the important https://github.com/clojure-emacs projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea, for all my 'reproducible' commands (lein test-aliases and such) I include -user too :)

@@ -70,6 +70,8 @@ jobs:
command: << parameters.lein_test_command >>
- run:
command: .circleci/e2e.sh
- run:
command: lein with-profile -user,+test eastwood
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to self-lint. It's not very formatting-stacky to lint all files, but it's a good idea (self-reference tends to be logically weak)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good change, but i'd rather implement it in terms of formatting-stack. I did some work to support cli invocation.

But i'd be fine with replacing this CI step when that's ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having both for the hinted reason: using f-s to lint f-s is somewhat weak. It can self-report being OK while it's not.

One would run the self-linting before Eastwood though, for fast feedback.

This could be an entire sequence:

  • f-s self-lint (kondo + eastwood, git diff only)
  • clj-kondo, whole project
  • eastwood, whole project

Maybe a little annoying for our standards of fast CI linting, but it could catch an issue the test suite didn't

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my suggestion it'd run the linter across the entire project as well. But we'll cross that bridge when we get there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be an issue in strategies, in reporting, in interaction with a given linter impl... bunch of things that can go wrong

@@ -131,14 +134,12 @@
;; (and shipped with this refactor-nrepl):
:plugins [[cider/cider-nrepl "0.24.0"]]}

:parallel-eastwood {:jvm-opts ["-Dformatting-stack.eastwood.parallelize-linters=true"]}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eastwood already parallelizes linters now

(f-s' own testing aided that decision!)

@@ -5,45 +5,6 @@
[formatting-stack.protocols.spec :as protocols.spec]
[nedap.speced.def :as speced]))

(speced/defn ^boolean? contains-dynamic-assertions?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix made its way into Eastwood ~1y ago

(-> f
Thread.
;; Important - daemonize this thread, otherwise under certain conditions it can prevent the JVM from exiting.
;; (We exercise this implicitly via `lein eastwood` in CI)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment hints, the thing being fixed here is that a non-daemonized thread can leave the JVM hanging forever.

I certainly have experieced that with f-s a bunch of times, it's very annoying.

@@ -24,10 +24,10 @@
(apply list runner-choice body))

;; Use kondo's official default config dir, so that we don't bloat consumers' project layouts:
(def cache-parent-dir ".clj-kondo")
(def ^String cache-parent-dir ".clj-kondo")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes found by Eastwood

@@ -27,11 +27,11 @@

"test-resources/eastwood_warning.clj"
(matchers/in-any-order
[{:source :eastwood/warn-on-reflection
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the linter rename is a breaking change

OTOH any Eastwood upgrade can bring new warning types (e.g. :eastwood/boxed-math) so it to be expected that types can appear/disappear over time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it would if we had silencing / blacklisting implemented (see #132). So I think this'll be fine :)

@@ -53,8 +45,7 @@
:filename (if (string? uri-or-file-name)
uri-or-file-name
(-> ^File uri-or-file-name .getCanonicalPath)))))
(concat (impl/warnings->reports output)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that the output-parsing is gone now 😬 !

Copy link
Contributor Author

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes to self, will fix along any feedback

@vemv
Copy link
Contributor Author

vemv commented Sep 7, 2021

Amended to use into

@vemv
Copy link
Contributor Author

vemv commented Sep 8, 2021

Removed the redundant config file. Strangely that revealed an unrelated failing test. I got to fix it by moving it to a different ns, prevening the git-cloning fixture from being run for it.

@thumbnail
Copy link
Member

Strangely that revealed an unrelated failing test.

Yeah I looked into this for a bit and am not sure what is actually happening. Moving the test out of this test-ns works but doesn't fix the root cause (maybe the refresh-within-refresh-dirs-only-strategy doesn't work properly in the other git folder?). I'll look into this a bit further.

@vemv
Copy link
Contributor Author

vemv commented Sep 9, 2021

The fixture was making all-files (sut/all-files :files []) return files such as these:

/home/circleci/repo/git-integration-testing/src/formatting_stack/formatters/cljfmt.clj

whereas they were expected to be like this:

/home/circleci/repo/src/formatting_stack/formatters/cljfmt.clj

...so it seems to me that sut/namespaces-within-refresh-dirs-only is doing its job properly as git-integration-testing/src is not a refresh dir.

@thumbnail
Copy link
Member

thumbnail commented Sep 10, 2021

That makes sense; the test-fixture sets a different CWD to make sure the git-commands run in the right CWD; but that obviously doesn't work for the refresh dirs.

I'm currently checking why the test succeeded before a805eb0

edit: it seems to have found specifically (/Users/.../formatting-stack/git-integration-testing/resources/eastwood/config/formatting_stack.clj). Because that file doesn't have a namespace declaration 😅. That test was truly hanging by a thread.

Anyway; I'm not a big fan of the test being moved out of the 'idiomatic' namespace, we could just set refresh-dirs to a value during the test. This also makes sure we control the 'hidden' variable (refresh-dirs that is):

diff --git a/test/integration/formatting_stack/strategies.clj b/test/integration/formatting_stack/strategies.clj
index 01d0dbc..b7be982 100644
--- a/test/integration/formatting_stack/strategies.clj
+++ b/test/integration/formatting_stack/strategies.clj
@@ -5,6 +5,7 @@
    [clojure.set :as set]
    [clojure.string :as string]
    [clojure.test :refer [deftest is testing use-fixtures]]
+   [clojure.tools.namespace.repl :refer [refresh-dirs]]
    [formatting-stack.strategies :as sut]
    [formatting-stack.test-helpers :as test-helpers :refer [git-integration-dir]]
    [formatting-stack.util :refer [rcomp]]
@@ -231,16 +232,18 @@
         (cleanup-testing-repo!)))))
 
 (deftest namespaces-within-refresh-dirs-only
-  (speced/let [^{::speced/spec (rcomp count (partial < 100))}
-               all-files (sut/all-files :files [])
-               result (sut/namespaces-within-refresh-dirs-only :files all-files)]
-    (is (seq result)
-        "Returns non-empty results (since f-s itself has namespaces within `src`, `test`, etc)")
-
-    (is (< (count result)
-           (count all-files))
-        "Doesn't include files outside the refresh dirs")
-
-    (is (set/subset? (set result)
-                     (set all-files))
-        "Is a subtractive (and not additive) mechanism")))
+  (with-redefs [refresh-dirs [(str (io/file git-integration-dir "src"))
+                              (str (io/file git-integration-dir "test"))]]
+   (speced/let [^{::speced/spec (rcomp count (partial < 100))}
+                all-files (sut/all-files :files [])
+                result    (sut/namespaces-within-refresh-dirs-only :files all-files)]
+     (is (seq result)
+         "Returns non-empty results  (since f-s itself has namespaces within `src`, `test`, etc)")
+
+     (is (< (count result)
+            (count all-files))
+         "Doesn't include files outside the refresh dirs")
+
+     (is (set/subset? (set result)
+                      (set all-files))
+         "Is a subtractive (and not additive) mechanism"))))

@vemv
Copy link
Contributor Author

vemv commented Sep 13, 2021

Rebased and added a minor commit

vemv added a commit to reducecombine/formatting-stack that referenced this pull request Sep 13, 2021
@vemv
Copy link
Contributor Author

vemv commented Sep 13, 2021

Added a commit following PR feedback, and removed the old one

@thumbnail thumbnail self-requested a review September 13, 2021 20:02
Copy link
Member

@thumbnail thumbnail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me! Left 2 comments but nothing mayor.

(catch Exception e
(swap! exceptions conj e)))))]
exceptions (atom nil)]
(with-out-str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting-stack.util/silence might be helpful here, since you're not capturing the output:

@@ -12,36 +12,22 @@
(java.io File)))

(def default-eastwood-options
;; Avoid false positives or undesired checks:
(let [linters (remove #{:suspicious-test :unused-ret-vals :constant-test :wrong-tag}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these linters currently disabled by default in eastwood? What if they'll be re-enabled in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these linters currently disabled by default in eastwood? What if they'll be re-enabled in the future?

They've been fixed upstream (i.e. they shouldn't give false positives) so there's no further need of disabling them.

(Which is why QAing a few large projects is recommended)

@vemv
Copy link
Contributor Author

vemv commented Sep 15, 2021

Rebased again, now we have 3 commits. The first one includes thesilence feedback

@thumbnail
Copy link
Member

Thanks a lot for the patience and the work!

@thumbnail thumbnail merged commit df434cc into nedap:master Sep 16, 2021
@thumbnail thumbnail mentioned this pull request Oct 14, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants