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