-
Notifications
You must be signed in to change notification settings - Fork 2
Eastwood: always use absolute filenames, internally #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| (ns formatting-stack.linters.eastwood | ||
| (:require | ||
| [clojure.java.io :as io] | ||
| [clojure.set :as set] | ||
| [clojure.string :as str] | ||
| [eastwood.lint] | ||
| [formatting-stack.linters.eastwood.impl :as impl] | ||
| [formatting-stack.protocols.linter :as linter] | ||
| [formatting-stack.protocols.spec :as protocols.spec] | ||
| [formatting-stack.util :refer [ns-name-from-filename silence]] | ||
| [medley.core :refer [assoc-some deep-merge]] | ||
| [nedap.utils.modular.api :refer [implement]]) | ||
| [nedap.speced.def :as speced] | ||
| [nedap.utils.modular.api :refer [implement]] | ||
| [nedap.utils.spec.api :refer [check!]]) | ||
| (:import | ||
| (java.io File))) | ||
|
|
||
|
|
@@ -16,12 +19,20 @@ | |
| (assoc :rethrow-exceptions? true))) | ||
|
|
||
| (defn lint! [{:keys [options]} filenames] | ||
| {:post [(do | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A glorified :such-that ;p An alternative (or complementary) solution would be strengthening IIRC a very similar idea was rejected ~1y ago (can't find the link, sorry) so I'm fine with leaving things as-is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess the reasoning would be something akin to "don't have side-effecting specs". I.e. a absolute filepath is fine (i.e. leading It makes generating examples harder and makes a spec unpure / dependent on state outside of it's input |
||
| (assert (check! (speced/fn [^::protocols.spec/reports xs] | ||
| (let [output (->> xs (keep :filename) (set))] | ||
| (set/subset? output (set filenames)))) | ||
| %) | ||
| "The `:filename`s returned from Eastwood should be a subset of this function's `filenames`. | ||
| Otherwise, it would mean that our filename absolutization out of Eastwood reports is buggy.") | ||
| true)]} | ||
| (let [namespaces (->> filenames | ||
| (remove #(str/ends-with? % ".edn")) | ||
| (keep ns-name-from-filename)) | ||
| reports (atom nil) | ||
| exceptions (atom nil)] | ||
|
|
||
| (silence | ||
| (try | ||
| (-> options | ||
|
|
@@ -37,9 +48,11 @@ | |
| :level :warning | ||
| :source (keyword "eastwood" (name linter)) | ||
| :warning-details-url warning-details-url | ||
| :filename (if (string? uri-or-file-name) | ||
| uri-or-file-name | ||
| (-> ^File uri-or-file-name .getCanonicalPath))))) | ||
| :filename (speced/let [^::speced/nilable ^String s (when (string? uri-or-file-name) | ||
| uri-or-file-name) | ||
| ^File file (or (some-> s File.) | ||
| uri-or-file-name)] | ||
| (-> file .getCanonicalPath))))) | ||
| (into (impl/exceptions->reports @exceptions))))) | ||
|
|
||
| (defn new [{:keys [eastwood-options] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,5 +17,5 @@ | |
| false | ||
|
|
||
| (-> (io/file "test-resources" "magic.clj") | ||
| (.getAbsolutePath)) | ||
| (.getCanonicalPath)) | ||
| true)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Settling in using
getCanonicalPathonly seems a good idea:From memory, libs like tools.namespace favor .getCanonicalPath