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

Eastwood confused by core.typed annotation #63

Closed
seancorfield opened this issue Apr 3, 2014 · 6 comments
Closed

Eastwood confused by core.typed annotation #63

seancorfield opened this issue Apr 3, 2014 · 6 comments

Comments

@seancorfield
Copy link

Example:

(ann ^:no-check current-code? [PromoCode -> Boolean :filters {:then (is PromoRecord 0) :else (! PromoRecord 0)}])
(defn current-code?
  "Given a promo code result, return true if it is current (not :expired, not nil)."
  [promo]
  (map? promo))

Eastwood flags (is PromoRecord 0) as a suspicious use of clojure.test/is even tho' we don't reference clojure.test in the code.

@jafingerhut
Copy link
Collaborator

This makes sense given the way it is currently implemented in Eastwood (at least up through the latest released version 0.1.2). Will have to think about whether there is a good way to avoid this, or just document it better.

It is not trivial to avoid because today's linting runs either:

(1) on pre-analyzed source code forms (like this one), and is thus easily messed up by symbols like "is" defined in other namespaces, or part of a special language within a macro argument

or

(2) on post-analyzed ASTs, which occurs after macro-expansions, currently with little or no way to tell what the analyzed code was macro-expanded from. Thus you are left with trying to detect the presence of a macro like clojure.test/is by the "shape" of its post-macroexpanded AST.

I believe the most accurate solution would be to do (2), but include in the AST ways to tell what the original un-macroexpanded forms were, ideally through every step of macroexpansion, then look through the ASTs for occurrences of clojure.test/is.

@seancorfield
Copy link
Author

Could you do (1) but with a deeper analysis of the ns form? Then any test-related linters could just be disabled for that file if the ns doesn't require/use clojure.test perhaps.

@jafingerhut
Copy link
Collaborator

See issue #71 for a new tools.analyzer feature that might make it easier to enhance Eastwood for this issue, too.

jafingerhut added a commit that referenced this issue Jun 12, 2014
….test

and only issue :suspicious-test warnings if they are clojure.test/is.
This is becoming more important now that core.typed has defined its
own (is ...) expression, which confused the previous implementation
that only looked at forms in the source code, with no name resolution.
@jafingerhut
Copy link
Collaborator

I've committed a change that should fix this issue in the next Eastwood release. It uses approach (2), because Nicola Mometto enhanced tools.analyzer(.jvm) to make it easy to determine from the ASTs what the original forms were before macro expansion. From that it is not difficult to determine which occurrences of 'is' are from clojure.test, or other namespaces like the one in core.typed.

No set date planned for the next release, but I will update this ticket when it happens, as well as announce it on the Clojure Google group.

@jafingerhut
Copy link
Collaborator

Eastwood 0.1.4 is released. Please give it a try and let us know whether it helps to eliminate the incorrect warnings.

@seancorfield
Copy link
Author

Big thumbs up here for 0.1.4 - thank you!

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

No branches or pull requests

2 participants