Xcode’s built-in JavaScript formatting has been buggy for years. Rather than switch editors, I patched an existing plugin so it runs on Xcode 10.

Repository

JSFormatter-Xcode — install instructions in the README.