cljfmt icon indicating copy to clipboard operation
cljfmt copied to clipboard

Is it true that cljfmt can't compute alias map when used as a CLJS library?

Open lread opened this issue 5 years ago • 3 comments

I'm currently reviewing aspects of namespace handling for rewrite-cljc and came to cljfmt to review how it handles namespaces.

Under docs for alias-map we have:

:alias-map - a map of namespace alias strings to fully qualified namespace names. This option is unnecessary in almost all cases, because cljfmt can compute the alias map from an ns declaration.

However, it can't do that when used as a CLJS library, or when indenting something with no ns declaration like an EDN file.

After reviewing the code, I might be missing something or maybe I have a blind spot, but I'm not sure why cljfmt would not be able to parse out alias maps from a ns declaration when used as a CLJS library. Is that maybe a historical, rather than current, limitation?

If it is no longer a CLJS limitation, and with the understanding that :alias-map is still useful in other cases, I am happy to update the docs and tests accordingly.

lread avatar Aug 02 '20 18:08 lread

PR #109 has an explanation. At the time, rewrite-cljs didn't have the capabilities required. That may have changed, but I haven't checked.

weavejester avatar Aug 02 '20 19:08 weavejester

Oh that's a wonderful PR description, thanks @weavejester (and @MatthewDarling). It states that the limitation is due to the current version of rewrite-cljs not being able to handle namespaced keywords #106 as evidenced here.

I am (oh so slowly) creating a successor for rewrite-cljs and rewrite-clj in rewrite-cljc, which should benefit tools like cljfmt.

I am hoping you are good with leaving this issue open while I work to reproduce an example of the limitation of parsing alias-maps from namespace declarations in cljfmt when using rewrite-cljs and then verify that is (or can be) resolved in rewrite-cljc.

lread avatar Aug 03 '20 17:08 lread

Yep, I'm fine with leaving it open.

weavejester avatar Aug 03 '20 18:08 weavejester