I'm trying to format all TS files in my repo using Prettier CLI, but I'm running into an issue. Prettier CLI and Prettier VS Code extension are formatting anonymous functions differently.
When I format the TS files using the CLI: npx prettier "**/example.ts" --write
It formats anonymous functions like this:
const test = function () {
console.log('test');
};
And then when I save the file (which formats the file with Prettier) it changes to this:
const test = function() {
console.log('test');
};
Note the space after "function" goes away.
From some digging, I've found that Prettier does NOT put a space there. This aligns with the Prettier extension. Adding the space is more like a TS/ESLint style.
Does anyone know why Prettier CLI is adding this space?
Found the answer. I had updated Prettier on my project from 1.X to 2.X.
After doing this, the Prettier CLI was using the updated version, but the VS Code extension was still using the old one.
I uninstalled and reinstalled the extension, and now they align (both use the space after function).