Add an empty line at end of file according to PSR-2 on PhpStorm
I use PSR-2 for code styling my code.
When I inspect a file using Codesniffer most of the times I get the following error.
332 | ERROR | [x] Expected 1 newline at end of file; 0 found
It's obvious how to fix this. What I need to know is if PhpStorm has a way to add the 1 newline at end of file
I already loaded the predefined style from Settings -> Editor -> Code Style -> PHP -> Set From -> PSR-1/PSR-2 and also used the Reformat Code to change the CS accordingly.
Everything is fixed except from the new line. Am I missing something?
You already have two answers for how to turn it on for ALL file types in IDE (in short: Settings/Preferences | Editor | General -> Ensure line feed at file end on Save).
To do this for .php files only you can try the following:
- Install EditorConfig plugin (if you do not have it installed yet)
- Create .editorconfig file in your project root (or whatever folder that would be where you want to apply such style -- it will be applied to files in this folder and below). If you have one already -- open and inspect it
- Add rule for *.php files only -- property to use would be insert_final_newline
[*.php] insert_final_newline = true
- EditorConfig site
- List of supported proerties (not sure how many of them are actually supported by PhpStorm)
In PhpStorm preferences go to:
Editor > General
Check the box "Other: Ensure line feed at file end on Save."
Just realize this affects all code files you edit in PhpStorm, not just PHP files.
someone said picture speaks louder :D
you will need to tick the Ensure line feed at file end on save box
Under Settings: Editor > General click Ensure line feed at file end on save is checked.
It will add a new line to EVERY file (.js, .css, .html), but it's the only way I've found, and it's a small hit for allowing PSR-2.