crazyfactory/php-sniffs

Too many Blank Lines are getting removed!

Closed this issue · 5 comments

The current package turns

<?php

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../df.inc.php';

df_init();

set_time_limit(0);

df_component_load('html');
df_component_load('database');
df_component_load('tex');

require_once __DIR__ . '/../../models/includes.php';

crazy_init();
$piece_id = $_REQUEST['piece_id'];
//YYY-MM-DD
$start_date = $_REQUEST['start_date'];
$end_date = $_REQUEST['end_date'];
if($piece_id&&$start_date&&$end_date)
{

    $data = crazy_piece_inout_list($piece_id, $start_date, $end_date);
    echo \CrazyFactory\Erp\Documents\Pdfs\InOutListPdf::getFileName(['piece_code' => 'bla', 'start_date' => $start_date, 'end_date' => $end_date, 'lines' => $data]);
}

into

<?php

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../df.inc.php';
df_init();
set_time_limit(0);
df_component_load('html');
df_component_load('database');
df_component_load('tex');
require_once __DIR__ . '/../../models/includes.php';
crazy_init();
$piece_id = $_REQUEST['piece_id'];
//YYY-MM-DD
$start_date = $_REQUEST['start_date'];
$end_date = $_REQUEST['end_date'];
if ($piece_id&&$start_date&&$end_date) {
    $data = crazy_piece_inout_list($piece_id, $start_date, $end_date);
    echo \CrazyFactory\Erp\Documents\Pdfs\InOutListPdf::getFileName(['piece_code' => 'bla', 'start_date' => $start_date, 'end_date' => $end_date, 'lines' => $data]);
}

This only happen when line feed after <?php tag is "\r\n" and the rest are "\n" (mixed line feed). Will find a solution for this.
image

A quick solution for this is to convert all files line feed in the project to "\n" and then run the sniff.

I'm not sure how often this will occur for this mixed line feed in one file. If we have only "\r\n" or "\n" the sniff is working correctly.

To solve your issue

Convert all EOL with sniff before running the whole sniff suite, you can follow this steps:

  1. dopr bash
  2. vendor/bin/phpcbf --standard=PSR2 --sniffs=Generic.Files.LineEndings ./src
  3. vendor/bin/phpcbf --standard=PSR2 --sniffs=Generic.Files.LineEndings ./tests
  4. exit
  5. dopr lint:fix

Note: Convert EOL for the whole project may throw out of memory error.

We should have that Sniff then in our ruleset at the beginning or not? :)