codeigniter4 / coding-standard

DEPRECATED! CodeIgniter 4 Coding Standard for PHP_CodeSniffer 3.
MIT License
68 stars 13 forks source link

phpcbf replaces indentation tab in array #41

Closed kenjis closed 2 years ago

kenjis commented 3 years ago

When I run phpcbf, it replaces indentation tab with 3 spaces in array.

command:

$ vendor/bin/phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 --encoding=utf-8 system/Language/en/RESTful.php

before:

return [
    'notImplemented' => '"{0}" action not implemented.',
];

after:

return [
   'notImplemented' => '"{0}" action not implemented.',
];
kenjis commented 3 years ago
<?php

return [
    'notImplemented' => '"{0}" action not implemented.',
];
$ ./vendor/bin/phpcs --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 system/Sample.php 

FILE: /Users/kenji/work/codeigniter/CodeIgniter4/system/Sample.php
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
 2 | ERROR | [ ] Missing file doc comment
 4 | ERROR | [x] Array key not aligned correctly; expected 0.75 tab but found 1
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 86ms; Memory: 10MB
kenjis commented 3 years ago

It seems the rule is: https://github.com/codeigniter4/coding-standard/blob/b7c6fe477264db450f8b6fbee5886b181b0eb3f1/CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php#L812

Sorry, I can't read the code...

MGatner commented 3 years ago

I've noticed this too and always have to exclude language files from the standard.

kenjis commented 3 years ago

It seems to fix this rule is difficult and time consuming. So I sent workaround PR: #44

WinterSilence commented 3 years ago

i think problem in new $data format:

$data  = [
     $expected,
     Common::pluralize('space', $expected),
     $found,
 ];
 $fix = $phpcsFile->addFixableError($error, $index['arrow'], 'ValueNotAligned', $data);

if old sniff dont have other differences, then better replace it to new native sniff.