|
1 | 1 | (ns formatting-stack.linters.eastwood |
2 | 2 | (:require |
3 | | - [clojure.java.io :as io] |
| 3 | + [clojure.set :as set] |
4 | 4 | [clojure.string :as str] |
5 | 5 | [eastwood.lint] |
6 | 6 | [formatting-stack.linters.eastwood.impl :as impl] |
7 | 7 | [formatting-stack.protocols.linter :as linter] |
| 8 | + [formatting-stack.protocols.spec :as protocols.spec] |
8 | 9 | [formatting-stack.util :refer [ns-name-from-filename silence]] |
9 | 10 | [medley.core :refer [assoc-some deep-merge]] |
10 | | - [nedap.utils.modular.api :refer [implement]]) |
| 11 | + [nedap.speced.def :as speced] |
| 12 | + [nedap.utils.modular.api :refer [implement]] |
| 13 | + [nedap.utils.spec.api :refer [check!]]) |
11 | 14 | (:import |
12 | 15 | (java.io File))) |
13 | 16 |
|
|
16 | 19 | (assoc :rethrow-exceptions? true))) |
17 | 20 |
|
18 | 21 | (defn lint! [{:keys [options]} filenames] |
| 22 | + {:post [(do |
| 23 | + (assert (check! (speced/fn [^::protocols.spec/reports xs] |
| 24 | + (let [output (->> xs (keep :filename) (set))] |
| 25 | + (set/subset? output (set filenames)))) |
| 26 | + %) |
| 27 | + "The `:filename`s returned from Eastwood should be a subset of this function's `filenames`. |
| 28 | +Otherwise, it would mean that our filename absolutization out of Eastwood reports is buggy.") |
| 29 | + true)]} |
19 | 30 | (let [namespaces (->> filenames |
20 | 31 | (remove #(str/ends-with? % ".edn")) |
21 | 32 | (keep ns-name-from-filename)) |
22 | 33 | reports (atom nil) |
23 | 34 | exceptions (atom nil)] |
24 | | - |
| 35 | + |
25 | 36 | (silence |
26 | 37 | (try |
27 | 38 | (-> options |
|
37 | 48 | :level :warning |
38 | 49 | :source (keyword "eastwood" (name linter)) |
39 | 50 | :warning-details-url warning-details-url |
40 | | - :filename (if (string? uri-or-file-name) |
41 | | - uri-or-file-name |
42 | | - (-> ^File uri-or-file-name .getCanonicalPath))))) |
| 51 | + :filename (speced/let [^::speced/nilable ^String s (when (string? uri-or-file-name) |
| 52 | + uri-or-file-name) |
| 53 | + ^File file (or (some-> s File.) |
| 54 | + uri-or-file-name)] |
| 55 | + (-> file .getCanonicalPath))))) |
43 | 56 | (into (impl/exceptions->reports @exceptions))))) |
44 | 57 |
|
45 | 58 | (defn new [{:keys [eastwood-options] |
|
0 commit comments