Skip to content

Formatter breaks :refer-clojure :exclude with platform-specific reader conditionals #210

@jetmind

Description

@jetmind

When a .cljc file has separate per-platform :refer-clojure forms wrapped in #?, the formatter merges them into a single :refer-clojure with #?@ splicing inside :exclude. This breaks compilation because #?@ splices the vector contents, so :exclude receives bare symbols instead of a vector.

Minimal reproduction

Create repro.cljc:

(ns repro
  #?(:cljs (:refer-clojure :exclude [juxt])
     :clj  (:refer-clojure :exclude [juxt format])))

Run fix:

$ standard-clj fix repro.cljc
standard-clj fix v0.27.0

F /repro.cljc [2.94ms]

1 file formatted with Standard Clojure Style 👍 [9.27ms]

Result in repro.cljc:

(ns repro
  (:refer-clojure
    :exclude #?@(:clj [format juxt]
                 :cljs [juxt])))

Fails to compile:

$ clojure -M -e '(load-file "repro.cljc")'
Syntax error macroexpanding clojure.core/ns at (repro.cljc:1:1).
((:refer-clojure :exclude format juxt)) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form

#?@ splices the vector contents, so Clojure sees :exclude format juxt instead of :exclude [format juxt].

Expected behavior

Either leave the two separate #?-wrapped :refer-clojure forms as-is, or use #? (without @) to preserve the vector: :exclude #?(:clj [format juxt] :cljs [juxt]).

Version

$ standard-clj --version
v0.27.0 [dc54207]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnamespacerelated to ns form parsing or printing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions