crospt.blogg.se

Phpstorm format code
Phpstorm format code











phpstorm format code

So ok, Javascript and a bunch of other front-end languages (CSS, HTML, GraphQL, etc.) have this tool, but this is Serious Enterprise PHP™ we have Serious Enterprise Tools™ to take care of our code style and PSRs and RFCs and all that – we don’t just type code until it’s pretty. Once you go without them though, you will realise how much time they take up. These distractions take up much more of your day than people realise because those are micro interruptions that are scattered and as such feel inconsequential. You stop thinking about indentation, manually adding commas, or placing things for maximum readability and such. You can type code in one disgusting line, press save, and the result is nicely formatted code. The more you trust Prettier, the more you can stop worrying about formatting altogether. This may sound counter-intuitive but it tremendously reduces friction when writing code. You can pass a few basic options to Prettier (indentation, max width, the basics) but other than that it takes your whole code and reformats it from scratch, disregarding any formatting decision you may have previously taken. Prettier, however, is currently one of the most popular code formatters out there, and it has spread to a lot of different languages already for one simple reason: it gives zero fucks about how you think your code should be formatted. There are code formatters for many languages even Javascript has quite a few of them. Find out more details in the new features for PHPStorm 2021.2 post.Originally from the Javascript ecosystem, Prettier is a code formatter which means it takes your code and makes it – as its name suggests – prettier. The team at Jetbrains reached out and brought to my attention that PHPStorm 2021.2 actually has a new feature too - "Actions on Save" - which is able to do the same thing, without using a Macro. So in that regard, 2021.2 actually fixed the issue.īut regardless, if you’re a Format and Save fan like me, tweak your Macro to keep the formatting love on every save. While this feels like a bug given it has only cropped up with PHPStorm 2021.2, it actually is more a sign of an earlier bug with 2021.1 and earlier: moving the caret up and down when the entire text is selected does actually make sense to move to the top and down one line. So now rather than touching the caret at all, a simple Escape deselects all of the content too, and leaves the caret in place. In PHPStorm 2021.2, I have re-recorded a Macro, with 4 steps – and to be honest, I feel should actually work in earlier versions: This actually meant that on every save, I was actually moved back to Line 2 of every file. Steps 1-3 are all fine, but…Ĥ moved the caret to the top of the document Those last two steps allowed the caret to stay in the same position, and to have all of the content de-selected (after step 1’s Select All).īut in PHPStorm 2021.2, the caret behaviour of selected text has changed, and steps 4 and 5 here led to some undesirable behaviour.

phpstorm format code

In PHPStorm 2021.1, this Macro had 5 steps:

phpstorm format code

While reformatting on every save may be overkill, it does mean that my code does remain clean, neat and consistent. I’ve been using a Macro for years in PHPStorm that, when I hit Cmd+S, reformatted my code based on the project’s settings.













Phpstorm format code