oakmac / standard-clojure-style-js

Standard Clojure Style in JavaScript
ISC License
80 stars 1 forks source link

bug: formatter deletes file contents if `ns` form is unclosed #150

Open alexandercampbell opened 2 weeks ago

alexandercampbell commented 2 weeks ago

This came up when I was editing imports in a namespace and deleted the closing paren by mistake.

Example input:

(ns example
  (:require
   [clojure.math :as math])

(doseq [i (range 100)]
  (println {:a i}))

Formatter output:

(ns example
  (:require
   [clojure.math :as math]))

From what I can tell, this bug will happily delete thousands of lines of source code.

This occurred on version v0.12.0 of the formatter.

oakmac commented 2 weeks ago

Thank you for the report: this is definitely not great behavior or user experience. Similar to Issue #59, I think the tool should throw an error and communicate to the user that it encountered invalid code in cases like this.