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?

Answers


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:

  1. Install EditorConfig plugin (if you do not have it installed yet)
  2. 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
  3. Add rule for *.php files only -- property to use would be insert_final_newline

Example:

[*.php]
insert_final_newline = true

Links:


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.


Need Your Help

Run grunt-preprocess before grunt serve

javascript gruntjs

I need to run grunt-preprocess before grunt serve task is executed in order to have an index.html updated with development settings.

Chrome 49 - display flex issue in windows 10 when scrolling

css google-chrome scroll rendering flexbox

When scrolling, I noticed a rendering issue after updating Google Chrome. It seems like it is rendering the page too slow.