coala / coala-bears

Bears for coala
https://coala.io/
GNU Affero General Public License v3.0
295 stars 580 forks source link

Spaces used instead of tabs reported when no spaces present #816

Closed jayvdb closed 8 years ago

jayvdb commented 8 years ago

When use_spaces = False (and allow_trailing_whitespace = True) are enabled, "Spaces used instead of tabs." is being reported even when the line doesnt contain any spaces.

For this branch : https://github.com/jayvdb/clipdig/tree/remove-tab-inside-if Here is the log https://travis-ci.org/jayvdb/clipdig/builds/159096118

And here are the relevant examples

form/category.php
|  45| »   »   //else{»   »   »   »   send_notif("Gagal");}
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.
...
form/scrap-menu.php
|   5| »   $search»   »   =ifset('se');
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.

form/scrap-menu.php
|   8| »   $status»   »   =ifset('st');
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.

...
get/data.php
|  22| »   »   »   »   $kotkab»   ="";
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.
..
get/data.php
|  31| »   »   »   »   $kotkab»   »   ="";
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.

...
form/scrap-pivot.php
|  23| »   »   »   »   $kotkab»   ="";
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.

...
form/scrap-pivot.php
|  32| »   »   »   »   $kotkab»   »   ="";
|    | [NORMAL] SpaceConsistencyBear:
|    | Line contains following spacing inconsistencies:
|    | - Spaces used instead of tabs.

(There may be more cases in that log, but the above are hopefully enough to spot the problem. I didnt see any strange characters using bvi.)

gitmate-bot commented 8 years ago

Thanks for reporting this issue! A coalaian will look at it soon.

sils commented 8 years ago

Seems there's some bugs concerning that :/ I'm not sure if there's anyone available right now who's got time to look into this soon.

sils commented 8 years ago

Interestingly coala wants to correct this:

-»   »   //else{»   »   »   »   send_notif("Gagal");}
+»   »   //else{•»   »   »   send_notif("Gagal");}

Actually even the visualization seems to be wrong :(

sils commented 8 years ago
jayvdb commented 8 years ago

Replacing the tabs inside the statement with spaces fixes the problem. It is very bizarre that some lines are reported as errors, while nearly identical lines are considered OK. Here is my diff which works around all of the problems listed above for the assignments.

commit a19970e4984e8ea936ca858235914dbdd7cfdbb5
Author: John Vandenberg <jayvdb@gmail.com>
Date:   Sun Sep 11 23:19:35 2016 +0700

    Remove tabs before assignment for unknown reason (part II)

diff --git a/form/scrap-menu.php b/form/scrap-menu.php
index 9390c9c..80aaa00 100755
--- a/form/scrap-menu.php
+++ b/form/scrap-menu.php
@@ -2,10 +2,10 @@
 <?php
    $media      =ifset('me');
    $page       =ifset('p');
-   $search     =ifset('se');
+   $search =ifset('se');
    $tgl1       =ifset('tgl1');
    $tgl2       =ifset('tgl2');
-   $status     =ifset('st');
+   $status =ifset('st');
    $searched   =ifset('searched');
    $wilayah    =ifset('wilayah');
    $category   =ifset('category');
diff --git a/form/scrap-pivot.php b/form/scrap-pivot.php
index 72fcee6..13f8002 100755
--- a/form/scrap-pivot.php
+++ b/form/scrap-pivot.php
@@ -20,7 +20,7 @@
            $lng = strlen($wilayah);
            if($lng==2){
                $provinsi   = get_name_wilayah($wilayah);
-               $kotkab ="";
+               $kotkab ="";
            }
            elseif($lng>2 and $lng<=5){
                $wilayah    = explode(".",$wilayah);
@@ -29,7 +29,7 @@
            }
            else{
                $provinsi   ="";
-               $kotkab     ="";
+               $kotkab ="";
            }

            $kode   = $d['kode'];
diff --git a/get/data.php b/get/data.php
index b2b7cf1..f02e1e8 100755
--- a/get/data.php
+++ b/get/data.php
@@ -19,7 +19,7 @@ include ("../static/inc/function.php");
            $wilayah = $d['wilayah'];
            if(strlen($wilayah)>0 and strlen($wilayah)<=2 ){
                $provinsi   = get_name_wilayah($wilayah);
-               $kotkab ="";
+               $kotkab ="";
            }
            elseif(strlen($wilayah)>3){
                $wilayah    = explode(".",$wilayah);
@@ -28,7 +28,7 @@ include ("../static/inc/function.php");
            }
            else{
                $provinsi   ="";
-               $kotkab     ="";
+               $kotkab ="";
            }

            $kode   = $d['kode'];

https://github.com/jayvdb/clipdig/commit/a19970e4984e

While you've marked it as high priority, it isnt a high priority for me. It is easy to workaround this problem by using spaces within statements, instead of tabs, which is what most coding standards recommend.

sils commented 8 years ago

Thanks for providing further insight, I think that three of your bug reports are connected and may have the same cause, I hope someone will find some time to investigate this soon.

I think this is high prio because some people are using tabs and this is really a pretty basic algorithm. Bugs are rather high prio anyway, most of the issues in our tracker are discussions, codestyle, features and stuff.

jayvdb commented 8 years ago

Yea. Looks like this is actually a bug in the coala repo, as that is where SpacingHelper is.

jayvdb commented 7 years ago

Apparently Pygments visualizes tabs wrongly by just ignoring their position

Very annoying. Raised as https://bitbucket.org/birkenfeld/pygments-main/issues/1286/whitespace-filter-misaligns-text-following