diff --git a/e2e/monorepo-support/test/monorepo_support/core_test.clj b/e2e/monorepo-support/test/monorepo_support/core_test.clj index a2e07b68..420c1755 100644 --- a/e2e/monorepo-support/test/monorepo_support/core_test.clj +++ b/e2e/monorepo-support/test/monorepo_support/core_test.clj @@ -22,7 +22,7 @@ (doseq [filename all :let [file (File. filename) - absolute (-> file .getAbsolutePath)]] + absolute (-> file .getCanonicalPath)]] (is (= filename absolute) "Returns absolutized filenames, which is important for monorepo support") diff --git a/src/formatting_stack/linters/eastwood.clj b/src/formatting_stack/linters/eastwood.clj index 2d7fc3b5..594f4296 100644 --- a/src/formatting_stack/linters/eastwood.clj +++ b/src/formatting_stack/linters/eastwood.clj @@ -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 + (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] diff --git a/test/formatting_stack/test_helpers.clj b/test/formatting_stack/test_helpers.clj index 1932d0d5..d4f4ef66 100644 --- a/test/formatting_stack/test_helpers.clj +++ b/test/formatting_stack/test_helpers.clj @@ -10,7 +10,7 @@ (speced/defn filename-as-resource [^string? filename] (str "file:" (-> filename File. - .getAbsolutePath))) + .getCanonicalPath))) (defn with-mocked-diff-path "Fixture to stub the absolute path in #'util.diff/unified-diff" diff --git a/test/functional/formatting_stack/formatters/clean_ns/impl.clj b/test/functional/formatting_stack/formatters/clean_ns/impl.clj index f2d41b44..da28190c 100644 --- a/test/functional/formatting_stack/formatters/clean_ns/impl.clj +++ b/test/functional/formatting_stack/formatters/clean_ns/impl.clj @@ -7,7 +7,7 @@ (deftest has-duplicate-requires? (are [input assertion] (let [file (io/file "test" "functional" "formatting_stack" "formatters" "clean_ns" input) _ (assert (-> file .exists)) - filename (-> file .getAbsolutePath) + filename (-> file .getCanonicalPath) result (sut/has-duplicate-requires? filename)] (case assertion :has-duplicates result diff --git a/test/functional/formatting_stack/linters/eastwood.clj b/test/functional/formatting_stack/linters/eastwood.clj index 26300d3c..09466a13 100644 --- a/test/functional/formatting_stack/linters/eastwood.clj +++ b/test/functional/formatting_stack/linters/eastwood.clj @@ -4,7 +4,9 @@ [formatting-stack.linters.eastwood :as sut] [formatting-stack.protocols.linter :as linter] [matcher-combinators.matchers :as matchers] - [matcher-combinators.test :refer [match?]])) + [matcher-combinators.test :refer [match?]]) + (:import + (java.io File))) (use-fixtures :once (fn [tests] ;; prevent humongous AST representations from being printed: @@ -14,7 +16,7 @@ (deftest lint! (let [linter (sut/new {})] (are [filename expected] (match? expected - (linter/lint! linter [filename])) + (linter/lint! linter [(-> filename File. .getCanonicalPath)])) "test-resources/valid_syntax.clj" [] @@ -32,14 +34,14 @@ :line pos-int? :column pos-int? :warning-details-url "https://github.com/jonase/eastwood#reflection" - :filename "test-resources/eastwood_warning.clj"} + :filename (-> "test-resources/eastwood_warning.clj" File. .getCanonicalPath)} {:source :eastwood/def-in-def :line pos-int? :column pos-int? :warning-details-url "https://github.com/jonase/eastwood#def-in-def" - :filename "test-resources/eastwood_warning.clj"} + :filename (-> "test-resources/eastwood_warning.clj" File. .getCanonicalPath)} {:source :eastwood/wrong-pre-post :line pos-int? :column pos-int? :warning-details-url "https://github.com/jonase/eastwood#wrong-pre-post" - :filename "test-resources/eastwood_warning.clj"}])))) + :filename (-> "test-resources/eastwood_warning.clj" File. .getCanonicalPath)}])))) diff --git a/test/integration/formatting_stack/strategies/impl.clj b/test/integration/formatting_stack/strategies/impl.clj index ea16583a..595b3782 100644 --- a/test/integration/formatting_stack/strategies/impl.clj +++ b/test/integration/formatting_stack/strategies/impl.clj @@ -10,20 +10,20 @@ (are [dirname filename expected] (= expected (sut/dir-contains? dirname filename)) - "." (-> "src/formatting_stack/strategies/impl.clj" File.) true - (-> "." File. .getAbsolutePath) (File. "project.clj") true - "." (File. "project.clj") true - "." (File. "dev/user.clj") true - "dev" (File. "dev/user.clj") true - "." (File. "LICENSE") true - (-> "." File. .getAbsolutePath) (File. "LICENSE") true - "." (File. "./LICENSE") true - "dev" (File. "LICENSE") false - "dev" (File. "./LICENSE") false - (-> "." File. .getAbsolutePath) (File. "I_dont_exist") false - "." (File. "I_dont_exist") false - "dev" (File. "I_dont_exist") false - "dev" (File. "user.clj") false)) + "." (-> "src/formatting_stack/strategies/impl.clj" File.) true + (-> "." File. .getCanonicalPath) (File. "project.clj") true + "." (File. "project.clj") true + "." (File. "dev/user.clj") true + "dev" (File. "dev/user.clj") true + "." (File. "LICENSE") true + (-> "." File. .getCanonicalPath) (File. "LICENSE") true + "." (File. "./LICENSE") true + "dev" (File. "LICENSE") false + "dev" (File. "./LICENSE") false + (-> "." File. .getCanonicalPath) (File. "I_dont_exist") false + "." (File. "I_dont_exist") false + "dev" (File. "I_dont_exist") false + "dev" (File. "user.clj") false)) (deftest absolutize (are [target] (testing target diff --git a/test/unit/formatting_stack/formatters/cljfmt/impl/magic_symbols.clj b/test/unit/formatting_stack/formatters/cljfmt/impl/magic_symbols.clj index 480ac3c5..6e78d29d 100644 --- a/test/unit/formatting_stack/formatters/cljfmt/impl/magic_symbols.clj +++ b/test/unit/formatting_stack/formatters/cljfmt/impl/magic_symbols.clj @@ -17,5 +17,5 @@ false (-> (io/file "test-resources" "magic.clj") - (.getAbsolutePath)) + (.getCanonicalPath)) true))