One of the things you’ll find annoying if you’re trying to adhere to the PSR standards is that it’s hard to notice things like extra spaces at the end of lines and that you don’t have a blank line at the end of your file. You can run something like phpcbf to fix the file before you commit (and that’s a perfect option which will discuss in another article) but it’s nice to have sublime clean up whenever possible before you save.
Install the Plug-in
Step one is to install the plug-in. You should already have Package Control installed from earlier so we’re going to use the nice process of:
- Type “Package Control: Install Package” (or you can copy and paste what I just typed)
- Type “EditorConfig”
- Press “Return”
Add a .editorconfig
To do this we’re going to create a new file named “.editorconfig” at the root of our project and paste in the following:
Now when we work on .php files the editor will automatically indent using 4 spaces (indent_style and indent_size), use Unix style end of lines (end_of_line), keep an empty line at the end of the file (insert_final_newline), save using utf-8 (charset), and remove any extra whitespace at the end of a line (trim_trailing_whitespace).
Generally, I try to stick to to these same standards for my JS and SASS files so normally I’ll do:
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around his house with his loving partner.