atom / language-clojure

Clojure package for Atom
Other
49 stars 48 forks source link

Any form of [namespace/]def* to define entity.global.clojure #65

Closed tonsky closed 7 years ago

tonsky commented 7 years ago

Description of the Change

It’s a convention in Clojure to use macros whose name starts with def to define something. Libraries often define their own custom macros for this:

Another problem is that many people like to use def* macros from external libraries with namespace aliases (enlive/deftemplate, rum/defc). Sometimes you just have to, as in Clojure Spec or Prismatic Schema whose names conflict with clojure.core equivalents.

This PR adds regular expression that treats all forms whose name starts with def (with optional namespace) similarly.

Alternate Designs

The old way (before change) was whitelisting only def macros from clojure.core. It wasn’t working because it will detect standard vars and functions but will fail to detect custom def*-like macros.

Benefits

Detect and highlight more entities from custom def-like macros.

Possible Drawbacks

Mistakenly detect as entity definition a macro which isn’t entity definition but whose name starts with def (highly unlikely)

Applicable Issues

This convention is very well established so it shouldn’t hurt anyone.

50Wliu commented 7 years ago

Can you add some specs to cover this change please?

tonsky commented 7 years ago

How do I run specs locally?

tonsky commented 7 years ago

Done. Added some specs

50Wliu commented 7 years ago

Cool, thanks!