Search code examples
javascriptprettier

Why does Prettier wrap my anonymous function with another anonymous function call and how do I turn it off?


Here is the original code:

namespace.namespace2 = new function() {/* logic here*/}

After using Prettier:

namespace.namespace2 = new (function() {/* logic here*/})();

Why? I want an option to disable this, but can't find it documented anywhere.

I went into the Prettier playground area on their site, put in the code from the example above, and fiddled around with all settings, nothing worked.

I've then searched through the Prettier documentation, obviously tried to search for an answer, but I could only find posts unrelated to my issue.


Solution

  • This works as intended and was introduced with prettier v1.17.0. For more information about the reasons, see the pull request and linked issues. To summarize: It enforces a consistent syntax. There is no configuration option to change this behavior, and prettier won't add such an option, see prettier's option philosophy.