Skip to content
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

Error when linting files with tagged literals #222

Closed
pedro-w opened this issue Jun 1, 2017 · 10 comments · Fixed by #328
Closed

Error when linting files with tagged literals #222

pedro-w opened this issue Jun 1, 2017 · 10 comments · Fixed by #328

Comments

@pedro-w
Copy link

pedro-w commented Jun 1, 2017

I am getting an error when using Eastwood on files that use tagged literals.
For example,

File: src/ewe/core.clj

(ns ewe.core
  (:gen-class))

(defn ereader [x] (str "Make my " x ))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println #ewe/E "day"))

File: src/data_readers.clj

{ewe/E ewe.core/ereader}

which runs OK with lein run but with lein eastwood gives:

== Linting ewe.core ==
Linting failed:
ExceptionInfo No reader function for tag E
        clojure.core/ex-info (core.clj:4617)
	clojure.core/ex-info (core.clj:4617)
	eastwood.copieddeps.dep10.clojure.tools.reader.reader-types/reader-error (reader_types.clj:391)
	eastwood.copieddeps.dep10.clojure.tools.reader.reader-types/reader-error (reader_types.clj:387)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-tagged (reader.clj:824)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-tagged (reader.clj:811)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-dispatch (reader.clj:71)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-dispatch (reader.clj:66)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:889)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:870)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-delimited (reader.clj:195)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-delimited (reader.clj:188)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-list (reader.clj:208)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-list (reader.clj:204)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:889)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:870)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-delimited (reader.clj:195)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-delimited (reader.clj:188)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-list (reader.clj:208)
	eastwood.copieddeps.dep10.clojure.tools.reader/read-list (reader.clj:204)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:889)
	eastwood.copieddeps.dep10.clojure.tools.reader/read* (reader.clj:870)
	eastwood.copieddeps.dep10.clojure.tools.reader/read (reader.clj:938)
	eastwood.copieddeps.dep10.clojure.tools.reader/read (reader.clj:915)
	eastwood.analyze-ns/analyze-file (analyze_ns.clj:281)
	eastwood.analyze-ns/analyze-file (analyze_ns.clj:222)
	eastwood.analyze-ns/analyze-ns (analyze_ns.clj:343)
	eastwood.analyze-ns/analyze-ns (analyze_ns.clj:321)
	eastwood.lint/lint-ns (lint.clj:601)
	eastwood.lint/lint-ns (lint.clj:593)
	eastwood.lint/eastwood-core/fn--6826 (lint.clj:1089)
	eastwood.lint/eastwood-core (lint.clj:1088)
	eastwood.lint/eastwood-core (lint.clj:1005)
	eastwood.lint/eastwood (lint.clj:1206)
	eastwood.lint/eastwood (lint.clj:1187)
	eastwood.lint/eastwood-from-cmdline (lint.clj:1219)
	eastwood.lint/eastwood-from-cmdline (lint.clj:1218)
	clojure.lang.Var.invoke (Var.java:379)
	eastwood.versioncheck/run-eastwood (versioncheck.clj:15)
	eastwood.versioncheck/run-eastwood (versioncheck.clj:9)
	user/eval21 (form-init3987123842392494274.clj:1)
	user/eval21 (form-init3987123842392494274.clj:1)
	clojure.lang.Compiler.eval (Compiler.java:6927)
	clojure.lang.Compiler.eval (Compiler.java:6917)
	clojure.lang.Compiler.load (Compiler.java:7379)
	clojure.lang.Compiler.loadFile (Compiler.java:7317)
	clojure.main/load-script (main.clj:275)
	clojure.main/init-opt (main.clj:277)
	clojure.main/init-opt (main.clj:277)
	clojure.main/initialize (main.clj:308)
	clojure.main/null-opt (main.clj:342)
	clojure.main/null-opt (main.clj:339)
	clojure.main/main (main.clj:421)
	clojure.main/main (main.clj:384)
	clojure.lang.Var.invoke (Var.java:383)
	clojure.lang.Var.applyTo (Var.java:700)
	clojure.main.main (main.java:37)

Using clojure 1.8.0, lein 2.7.1, eastwood 0.2.4

@pedro-w
Copy link
Author

pedro-w commented Jun 1, 2017

@jafingerhut
Copy link
Collaborator

Thanks for the references to other issues. They do look relevant.

@pedro-w
Copy link
Author

pedro-w commented Jun 2, 2017

At a very crude level I was able to stop the error by binding *default-data-reader-fn* so as to prevent tools.reader from interpreting any tagged literals while reading (see patch below).

This assumes that none of the lints need to know the actual value of a tagged literal after processing. I do not know if this is valid. Also I am not sure where best to put the binding; certainly it doesn't work in leiningen.eastwood (and I don't know why).

The 'full' solution would be to locate the classpath roots of the linted code and the data_reader.clj files therein but I don't understand eastwood well enough to suggest how to do this.

Hope that helps,

diff --git a/src/eastwood/lint.clj b/src/eastwood/lint.clj
index 7ad6d73..a5160c4 100644
--- a/src/eastwood/lint.clj
+++ b/src/eastwood/lint.clj
@@ -591,6 +591,7 @@ curious." eastwood-url))
 
 
 (defn lint-ns [ns-sym linters opts warning-count exception-count]
+  (binding [eastwood.copieddeps.dep10.clojure.tools.reader/*default-data-reader-fn* (constantly nil)]
   (let [cb (:callback opts)
         error-cb (util/make-msg-cb :error opts)
         note-cb (util/make-msg-cb :note opts)
@@ -641,7 +642,7 @@ curious." eastwood-url))
 Lint results may be incomplete.  If there are compilation errors in
 your code, try fixing those.  If not, check above for info on the
 exception."))
-        exception))))
+        exception)))))
 
 
 (declare last-options-map-adjustments)

@lenw
Copy link

lenw commented Jun 9, 2017

This also happens when datomic is used. The #db/id in datomic transactions causes the same error.

@pedro-w
Copy link
Author

pedro-w commented Jun 12, 2017

The following patch does, at least on my test project, load up the data_readers.clj and allow eastwood to run.

diff --git a/src/eastwood/lint.clj b/src/eastwood/lint.clj
index 7ad6d73..1cf6681 100644
--- a/src/eastwood/lint.clj
+++ b/src/eastwood/lint.clj
@@ -591,6 +591,8 @@ curious." eastwood-url))
 
 
 (defn lint-ns [ns-sym linters opts warning-count exception-count]
+  (#'clojure.core/load-data-readers)
+  (binding [eastwood.copieddeps.dep10.clojure.tools.reader/*data-readers* *data-readers*]
   (let [cb (:callback opts)
         error-cb (util/make-msg-cb :error opts)
         note-cb (util/make-msg-cb :note opts)
@@ -641,7 +643,7 @@ curious." eastwood-url))
 Lint results may be incomplete.  If there are compilation errors in
 your code, try fixing those.  If not, check above for info on the
 exception."))
-        exception))))
+        exception)))))
 
 
 (declare last-options-map-adjustments)

Any comments welcomed. (@lenw I've never used datomic so can't comment, I assume it's the same issue)

Also I believe that the contents of dep10 are an older version of tools.reader and AFAICS won't work with namespaced maps, when clojure 1.9 comes out.

@jafingerhut
Copy link
Collaborator

@pedro-w Thanks for the tested patch! Good to have some working code to start from when creating a change to handle this case in Eastwood. I do not know when that might be, but if @divergentdave has any interest in making such changes, it is very likely he would beat me to it.

Agreed that Eastwood's copied-in version of tools.reader will need an update to handle Clojure 1.9's namespaced maps.

@divergentdave
Copy link
Collaborator

divergentdave commented Jun 12, 2017 via email

@pedro-w
Copy link
Author

pedro-w commented Jun 15, 2017

Thanks, both. Let me know if I can help.

Basically the core reader will load up the data readers automatically (code in https://github.com/clojure/clojure/blob/964232c7bf442787740fa0200b289b3495b1ec09/src/clj/clojure/core.clj#L7712 ) but tools.reader won't (by design), so my patch just does what the core reader would do and then binds the result where tools.reader can see it (sorry if that explanation was obvious!).

I'm not sure, though, if the way that the data_readers.clj files are located will always be correct for what we want. The innards of clojure itself are a bit mysterious to me...

@gabrielmaldi
Copy link

Has there been any progress on this? Or perhaps a way to modify the source code so Eastwood doesn't crash? We use lots of Datomic's #db/id and this prevents us from linting our project.

Thanks!

@valerauko
Copy link
Contributor

Is there any reason @pedro-w's working patch isn't making it into the code? This issue prevents Eastwood from linting any project with tagged literals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants