Skip to content

Commit

Permalink
add: source-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ertugrulcetin committed Nov 9, 2020
1 parent bff242f commit 348f85a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# lein-nsort

Leiningen plugin that checks that order of namespace declarations for Clojure files
Leiningen plugin that checks that order of namespace declarations for Clojure and ClojureScript

## Usage

[![Clojars Project](https://clojars.org/lein-nsort/latest-version.svg)](https://clojars.org/lein-nsort)

### Adding the dependency to `:plugins`

Add `[lein-nsort "0.1.13"]` into the `:plugins` vector of your
Add `[lein-nsort "0.1.14"]` into the `:plugins` vector of your
`project.clj` or `~/.lein/profiles.clj`.

```clj
(defproject my-project
:plugins [[lein-nsort "0.1.13"]])
:plugins [[lein-nsort "0.1.14"]])
```

### Running the checker
Expand All @@ -24,8 +24,8 @@ Run the nsort like this:
lein nsort
```

This will check `ns` declaration forms for all Clojure source files in
the `{:nsort {:src-dir "src"}}` of your project (default `./src/`).
This will check `ns` declaration forms for all Clojure and ClojureScript source files in
the `{:nsort {:source-paths ["src"]}}` of your project (default `./src/`).

### Output
```clj
Expand Down Expand Up @@ -59,9 +59,10 @@ Add a `:nsort` key to your `project.clj` to customize the checker.

```clj
(defproject my-project
:nsort {:src-dir "src" ;;(default)
:require :asc ;;(default)
:import :desc})
:nsort {:require :asc ;;(default)
:import :desc
:source-paths ["src"] ;;(default)
})
```

There are 4 pre-defined sorting checks for `:require` and 2 for `:import`.
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject lein-nsort "0.1.13"
(defproject lein-nsort "0.1.14"

:description "Leiningen plugin that checks that order of namespace declarations for Clojure files\n\n"

Expand Down
12 changes: 9 additions & 3 deletions src/lein_nsort/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@
(ns-find/find-sources-in-dir dir platform)))


(defn- get-invalid-declarations [{:keys [src-dir]
:or {src-dir "src"} :as opts}]
(let [ns-decls (find-ns-decls-in-dir (io/file src-dir) ns-find/clj)]
(defn- find-ns-decls [source-paths]
(concat
(mapcat #(find-ns-decls-in-dir (io/file %) ns-find/clj) source-paths)
(mapcat #(find-ns-decls-in-dir (io/file %) ns-find/cljs) source-paths)))


(defn- get-invalid-declarations [{:keys [source-paths]
:or {source-paths ["src"]} :as opts}]
(let [ns-decls (find-ns-decls source-paths)]
(reduce
(fn [acc decl]
(let [{:keys [file ns-decl]} decl
Expand Down

0 comments on commit 348f85a

Please sign in to comment.