Skip to content

Commit

Permalink
Add ns-exclude-regex for commands that check whole project, allowin…
Browse files Browse the repository at this point in the history
…g to exclude certain namespaces via regex
  • Loading branch information
ericdallo committed Jul 27, 2021
1 parent bc43868 commit 1647ff1
Show file tree
Hide file tree
Showing 46 changed files with 206 additions and 169 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- API/CLI
- Fix filename in diffs with dry option.
- Add coloring to diffs following git diff.
- Add `ns-exclude-regex` for commands that check whole project, allowing to exclude certain namespaces via regex.

## 2021.07.19-14.46.52

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test: classes
clojure -M:test

lint-fix:
clojure -M:run clean-ns
clojure -M:run clean-ns --ns-exclude-regex "sample-test.*"
clojure -M:run format

release:
Expand Down
16 changes: 8 additions & 8 deletions integration-test/integration/api/clean_ns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@

(lsp/clean-after-test)

(def a-subject-path (h/project-path->abs-path "src/api/clean_ns/a.clj"))
(def a-subject-path (h/project-path->abs-path "src/sample_test/api/clean_ns/a.clj"))
(def a-subject-text (slurp a-subject-path))
(def a-expected-path (h/project-path->abs-path "fixtures/api/clean_ns/a.clj"))
(def a-expected-path (h/project-path->abs-path "fixtures/sample_test/api/clean_ns/a.clj"))
(def a-expected-text (slurp a-expected-path))

(deftest clean-ns
(testing "passing a single namespace"
(with-open [rdr (lsp/cli! "clean-ns"
"--project-root" h/root-project-path
"--namespace" "api.clean-ns.a")]
(is (string/includes? (slurp rdr) "Cleaned api.clean-ns.a\n"))
"--namespace" "sample-test.api.clean-ns.a")]
(is (string/includes? (slurp rdr) "Cleaned sample-test.api.clean-ns.a\n"))
(is (= a-expected-text (slurp a-subject-path))))
(spit a-subject-path a-subject-text))
(testing "passing multiple namespaces but only one is cleanable"
(with-open [rdr (lsp/cli! "clean-ns"
"--project-root" h/root-project-path
"--namespace" "api.clean-ns.b"
"--namespace" "api.clean-ns.a")]
(is (string/includes? (slurp rdr) "Cleaned api.clean-ns.a\n"))
"--namespace" "sample-test.api.clean-ns.b"
"--namespace" "sample-test.api.clean-ns.a")]
(is (string/includes? (slurp rdr) "Cleaned sample-test.api.clean-ns.a\n"))
(is (= a-expected-text (slurp a-subject-path))))
(spit a-subject-path a-subject-text))
(testing "when running with dry"
(with-open [rdr (lsp/cli! "clean-ns"
"--project-root" h/root-project-path
"--namespace" "api.clean-ns.a"
"--namespace" "sample-test.api.clean-ns.a"
"--dry")]
(is (string/includes? (slurp rdr) a-subject-path))
(is (= a-subject-text (slurp a-subject-path))))))
16 changes: 8 additions & 8 deletions integration-test/integration/api/format_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@

(lsp/clean-after-test)

(def a-subject-path (h/project-path->abs-path "src/api/format/a.clj"))
(def a-subject-path (h/project-path->abs-path "src/sample_test/api/format/a.clj"))
(def a-subject-text (slurp a-subject-path))
(def a-expected-path (h/project-path->abs-path "fixtures/api/format/a.clj"))
(def a-expected-path (h/project-path->abs-path "fixtures/sample_test/api/format/a.clj"))
(def a-expected-text (slurp a-expected-path))

(deftest format-test
(testing "passing a single namespace"
(with-open [rdr (lsp/cli! "format"
"--project-root" h/root-project-path
"--namespace" "api.format.a")]
(is (string/includes? (slurp rdr) "Formatted api.format.a\n"))
"--namespace" "sample-test.api.format.a")]
(is (string/includes? (slurp rdr) "Formatted sample-test.api.format.a\n"))
(is (= a-expected-text (slurp a-subject-path))))
(spit a-subject-path a-subject-text))
(testing "passing multiple namespaces but only one is formatable"
(with-open [rdr (lsp/cli! "format"
"--project-root" h/root-project-path
"--namespace" "api.format.b"
"--namespace" "api.format.a")]
(is (string/includes? (slurp rdr) "Formatted api.format.a\n"))
"--namespace" "sample-test.api.format.b"
"--namespace" "sample-test.api.format.a")]
(is (string/includes? (slurp rdr) "Formatted sample-test.api.format.a\n"))
(is (= a-expected-text (slurp a-subject-path))))
(spit a-subject-path a-subject-text))
(testing "when running with dry"
(with-open [rdr (lsp/cli! "format"
"--project-root" h/root-project-path
"--namespace" "api.format.a"
"--namespace" "sample-test.api.format.a"
"--dry")]
(is (string/includes? (slurp rdr) a-subject-path))
(is (= a-subject-text (slurp a-subject-path))))))
12 changes: 6 additions & 6 deletions integration-test/integration/api/rename_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

(lsp/clean-after-test)

(def a-subject-path (h/project-path->abs-path "src/rename/a.cljc"))
(def a-subject-path (h/project-path->abs-path "src/sample_test/rename/a.cljc"))
(def a-subject-text (slurp a-subject-path))
(def a-expected-path (h/project-path->abs-path "fixtures/api/rename/a.cljc"))
(def a-expected-path (h/project-path->abs-path "fixtures/sample_test/api/rename/a.cljc"))
(def a-expected-text (slurp a-expected-path))

(def b-subject-path (h/project-path->abs-path "src/rename/b.cljc"))
(def b-subject-path (h/project-path->abs-path "src/sample_test/rename/b.cljc"))
(def b-subject-text (slurp b-subject-path))

(deftest rename
(testing "passing a valid from and too"
(with-open [rdr (lsp/cli! "rename"
"--project-root" h/root-project-path
"--from" "rename.a/my-func"
"--to" "rename.a/your-func")]
(is (string/includes? (slurp rdr) "Renamed rename.a/my-func to rename.a/your-func\n"))
"--from" "sample-test.rename.a/my-func"
"--to" "sample-test.rename.a/your-func")]
(is (string/includes? (slurp rdr) "Renamed sample-test.rename.a/my-func to sample-test.rename.a/your-func\n"))
(is (= a-expected-text (slurp a-subject-path))))
(spit a-subject-path a-subject-text)
(spit b-subject-path b-subject-text)))
8 changes: 4 additions & 4 deletions integration-test/integration/diagnostics_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
:severity 3
:code "unused-public-var"
:source "clojure-lsp"
:message "Unused public var 'diagnostics.unused-public-var/foo'"
:message "Unused public var 'sample-test.diagnostics.unused-public-var/foo'"
:tags [1]}
{:range {:start {:line 5 :character 5}
:end {:line 5 :character 8}}
:severity 3
:code "unused-public-var"
:source "clojure-lsp"
:message "Unused public var 'diagnostics.unused-public-var/bar'"
:message "Unused public var 'sample-test.diagnostics.unused-public-var/bar'"
:tags [1]}]
(lsp/await-diagnostics "diagnostics/unused_public_var.clj"))))

Expand All @@ -43,7 +43,7 @@
:severity 2
:code "unused-private-var"
:source "clj-kondo"
:message "Unused private var diagnostics.kondo/foo"
:message "Unused private var sample-test.diagnostics.kondo/foo"
:tags [1]}
{:range {:start {:line 5 :character 0} :end {:line 5 :character 3}}
:severity 1
Expand Down Expand Up @@ -72,7 +72,7 @@
:severity 2
:code "unused-private-var"
:source "clj-kondo"
:message "Unused private var diagnostics.kondo/foo"
:message "Unused private var sample-test.diagnostics.kondo/foo"
:tags [1]}
{:range {:start {:line 5 :character 0} :end {:line 5 :character 3}}
:severity 1
Expand Down
4 changes: 2 additions & 2 deletions integration-test/integration/document_symbol_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

(testing "get file document symbols"
(h/assert-submaps
[{:name "document-symbol.a"
[{:name "sample-test.document-symbol.a"
:kind 3
:range {:start {:line 0 :character 0} :end {:line 999999 :character 999999}}
:selectionRange {:start {:line 0 :character 0} :end {:line 0 :character 21}}
:selectionRange {:start {:line 0 :character 0} :end {:line 0 :character 33}}
:children
[{:name "a-some-var"
:kind 13
Expand Down
2 changes: 1 addition & 1 deletion integration-test/integration/formatting_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(h/assert-submaps
[{:range {:start {:line 0, :character 0}
:end {:line 999999, :character 999999}}
:newText "(ns formatting)\n\n(def foo 123)\n\n(defn bar []\n (+\n 1 foo))\n\n(bar)\n"}]
:newText "(ns sample-test.formatting)\n\n(def foo 123)\n\n(defn bar []\n (+\n 1 foo))\n\n(bar)\n"}]
(lsp/request! (fixture/formatting-full-request "formatting.clj"))))

(testing "we format the whole top-level form otherwise we get wrong spaces on parent forms"
Expand Down
8 changes: 4 additions & 4 deletions integration-test/integration/helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

(defn source-path->file [source-path]
(->> source-path
(str "integration-test/sample-test/src/")
(str "integration-test/sample-test/src/sample_test/")
io/as-relative-path
io/file))

(defn file->uri [file]
(-> file .toPath .toUri .toString))

(defn source-path->uri [source-path]
(-> source-path
source-path->file
file->uri))
(->> source-path
source-path->file
file->uri))

(defn assert-submap [expected actual]
(is (= expected
Expand Down
24 changes: 12 additions & 12 deletions integration-test/integration/rename_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(h/assert-submap
{:changes
{(keyword (h/source-path->uri "rename/b.cljc"))
[{:range {:start {:line 1 :character 36} :end {:line 1 :character 43}}
[{:range {:start {:line 1 :character 48} :end {:line 1 :character 55}}
:newText "your-func"}
{:range {:start {:line 3 :character 3} :end {:line 3 :character 10}}
:newText "your-func"}
Expand All @@ -39,7 +39,7 @@
(h/assert-submap
{:changes
{(keyword (h/source-path->uri "rename/b.cljc"))
[{:range {:start {:line 1 :character 36} :end {:line 1 :character 43}}
[{:range {:start {:line 1 :character 48} :end {:line 1 :character 55}}
:newText "your-func"}
{:range {:start {:line 3 :character 3} :end {:line 3 :character 10}}
:newText "your-func"}
Expand Down Expand Up @@ -70,14 +70,14 @@
{(keyword (h/source-path->uri "rename/a.cljc"))
[{:range {:start {:line 15 :character 0} :end {:line 15 :character 7}}
:newText "::click-now"}
{:range {:start {:line 17 :character 0} :end {:line 17 :character 15}}
:newText ":rename.a/click-now"}]
{:range {:start {:line 17 :character 0} :end {:line 17 :character 27}}
:newText ":sample-test.rename.a/click-now"}]

(keyword (h/source-path->uri "rename/b.cljc"))
[{:range {:start {:line 7 :character 0} :end {:line 7 :character 9}}
:newText "::a/click-now"}
{:range {:start {:line 9 :character 0} :end {:line 9 :character 15}}
:newText ":rename.a/click-now"}]}}
{:range {:start {:line 9 :character 0} :end {:line 9 :character 27}}
:newText ":sample-test.rename.a/click-now"}]}}
(lsp/request! (fixture/rename-request "rename/a.cljc" "::click-now" 15 0))))

(testing "Renaming single-name-namespace'd keywords"
Expand All @@ -86,14 +86,14 @@
{(keyword (h/source-path->uri "rename/single_a.clj"))
[{:range {:start {:line 2 :character 0} :end {:line 2 :character 7}}
:newText "::click-now"}
{:range {:start {:line 4 :character 0} :end {:line 4 :character 22}}
:newText ":rename.single-a/click-now"}]
{:range {:start {:line 4 :character 0} :end {:line 4 :character 34}}
:newText ":sample-test.rename.single-a/click-now"}]

(keyword (h/source-path->uri "rename/single_b.clj"))
[{:range {:start {:line 3 :character 0} :end {:line 3 :character 9}}
:newText "::a/click-now"}
{:range {:start {:line 5 :character 0} :end {:line 5 :character 22}}
:newText ":rename.single-a/click-now"}]}}
{:range {:start {:line 5 :character 0} :end {:line 5 :character 34}}
:newText ":sample-test.rename.single-a/click-now"}]}}
(lsp/request! (fixture/rename-request "rename/single_a.clj" "::click-now" 2 0))))

(testing "Renaming require alias"
Expand All @@ -110,7 +110,7 @@
(h/assert-submap
{:changes
{(keyword (h/source-path->uri "rename/b.cljc"))
[{:range {:start {:line 1 :character 36} :end {:line 1 :character 43}}
[{:range {:start {:line 1 :character 48} :end {:line 1 :character 55}}
:newText "your-func"}
{:range {:start {:line 3 :character 3} :end {:line 3 :character 10}}
:newText "your-func"}
Expand All @@ -123,4 +123,4 @@
:newText "your-func"}
{:range {:start {:line 8 :character 1} :end {:line 8 :character 8}}
:newText "your-func"}]}}
(lsp/request! (fixture/rename-request "rename/b.cljc" "your-func" 1 40)))))
(lsp/request! (fixture/rename-request "rename/b.cljc" "your-func" 1 52)))))
9 changes: 0 additions & 9 deletions integration-test/sample-test/fixtures/api/clean_ns/a.clj

This file was deleted.

13 changes: 0 additions & 13 deletions integration-test/sample-test/fixtures/api/format/a.clj

This file was deleted.

10 changes: 0 additions & 10 deletions integration-test/sample-test/fixtures/api/rename/b.cljc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns sample-test.api.clean-ns.a
(:require
[sample-test.api.clean-ns.b :refer [a b c]]))

a
b
c

(ns sample-test.api.clean-ns.a.other)
13 changes: 13 additions & 0 deletions integration-test/sample-test/fixtures/sample_test/api/format/a.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns sample-test.api.format.a
(:require
[sample-test.api.format.b :refer [b c a]]))

a b
c

(defn ^:private foo
[a
b]
(+ 2 4))

(ns sample-test.api.format.a.other)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns rename.a
(ns sample-test.rename.a
(:require [clojure.spec.alpha :as s]))

(defn your-func [a b]
Expand All @@ -15,4 +15,4 @@

::click

:rename.a/click
:sample-test.rename.a/click
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns sample-test.rename.b
(:require [sample-test.rename.a :as a :refer [your-func]]))

(a/your-func 5 6)

(your-func 7 8)

::a/click

:sample-test.rename.a/click
10 changes: 0 additions & 10 deletions integration-test/sample-test/src/api/clean_ns/a.clj

This file was deleted.

14 changes: 0 additions & 14 deletions integration-test/sample-test/src/api/format/a.clj

This file was deleted.

12 changes: 0 additions & 12 deletions integration-test/sample-test/src/definition/b.clj

This file was deleted.

Loading

0 comments on commit 1647ff1

Please sign in to comment.