From 63ed63740d04ea4b6cde95a350a1e72a65c0b47a Mon Sep 17 00:00:00 2001 From: vemv Date: Sat, 22 May 2021 20:56:12 +0200 Subject: [PATCH] [Fix #386] Support `(while true)` pattern (#391) Closes https://github.com/jonase/eastwood/issues/386 --- cases/testcases/while_true/green.clj | 5 +++++ cases/testcases/while_true/red.clj | 5 +++++ changes.md | 2 ++ resource/eastwood/config/clojure.clj | 7 +++++++ test/eastwood/lint_test.clj | 11 +++++++++++ 5 files changed, 30 insertions(+) create mode 100644 cases/testcases/while_true/green.clj create mode 100644 cases/testcases/while_true/red.clj diff --git a/cases/testcases/while_true/green.clj b/cases/testcases/while_true/green.clj new file mode 100644 index 00000000..11833ee9 --- /dev/null +++ b/cases/testcases/while_true/green.clj @@ -0,0 +1,5 @@ +(ns testcases.while-true.green) + +(defn foo [] + (while true + (println 1))) diff --git a/cases/testcases/while_true/red.clj b/cases/testcases/while_true/red.clj new file mode 100644 index 00000000..d07d8fbb --- /dev/null +++ b/cases/testcases/while_true/red.clj @@ -0,0 +1,5 @@ +(ns testcases.while-true.red) + +(defn foo [] + (while 1 + (println 1))) diff --git a/changes.md b/changes.md index 0028934f..b79597cf 100644 --- a/changes.md +++ b/changes.md @@ -6,6 +6,8 @@ * Support `(is false)` pattern * Closes https://github.com/jonase/eastwood/issues/384 +* Support `(while true)` pattern + * Closes https://github.com/jonase/eastwood/issues/386 #### Bugfixes diff --git a/resource/eastwood/config/clojure.clj b/resource/eastwood/config/clojure.clj index 2bfb2e76..098bb4db 100644 --- a/resource/eastwood/config/clojure.clj +++ b/resource/eastwood/config/clojure.clj @@ -77,6 +77,13 @@ :within-depth 2 :reason "Allow as-> to have constant tests without warning"}) +(disable-warning + {:linter :constant-test + :if-inside-macroexpansion-of #{'clojure.core/while} + :within-depth 3 + :qualifier true + :reason "Allow `(while true)` idiom"}) + (disable-warning {:linter :wrong-arity :function-symbol 'clojure.core/eduction diff --git a/test/eastwood/lint_test.clj b/test/eastwood/lint_test.clj index b960d82f..f5408a41 100644 --- a/test/eastwood/lint_test.clj +++ b/test/eastwood/lint_test.clj @@ -261,6 +261,17 @@ relative to a specific macroexpansion" #{'testcases.let.green} {:some-warnings false} #{'testcases.let.red} {:some-warnings true}))) +(deftest while-true-test + (testing "The `(while true)` idiom is supported" + (are [input expected] (testing input + (is (= (assoc expected :some-errors false) + (-> eastwood.lint/default-opts + (assoc :namespaces input) + (eastwood.lint/eastwood)))) + true) + #{'testcases.while-true.green} {:some-warnings false} + #{'testcases.while-true.red} {:some-warnings true}))) + (deftest is-false-test (testing "The `(is false)` idiom is supported" (are [input expected] (testing input