Tools to automatically format PHP, JavaScript and CSS files

Good writeup by Freek on how to get PHP-CS-Fixer and Prettier up and running.

When working on a project with other people, it’s important to pick a coding standard. Agreeing on a coding standard makes the code more readable for all developers that need to touch the project.

It’s easy to make mistakes against those formatting rules and bit cumbersome to fix all small formatting errors. Luckily there are many tools available that can automatically format this code. In this blog post, I’ll show you how to automatically format PHP, JavaScript and CSS files in a Laravel project. Not using Laravel? No problem! Most of this can be applied to any PHP project.

Addtionally I’d recommend to let these linters run in a precommit hook. That way no “faulty” code can be committed, and everyone is forced to adhere to the standards (Although: git commit -n …).

Tools to automatically format PHP, JavaScript and CSS files →

At the end of his post, Freek mentions that you can use Prettier to format your PHP code. The folks at Made With Love have a post on how to use Prettier with PHP.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.