DaveLiddament / sarb

Static Analysis Results Baseliner
MIT License
162 stars 17 forks source link

Add suport for php-cs-fixer #94

Closed sasezaki closed 2 years ago

sasezaki commented 3 years ago

Hi.

As feature request, I want php-cs-fixer support. https://github.com/FriendsOfPHP/PHP-CS-Fixer

sasezaki commented 3 years ago

Like cs2pr https://github.com/staabm/annotate-pull-request-from-checkstyle, checkstyle support would be get benefit as portable for other static analysis tool.

sasezaki commented 3 years ago

checkstyle support would be get benefit as portable for other static analysis tool.

I noticed, php-cs-fixer would not print Line Number. https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3601

So, currently we could not support php-cs-fixer simply via checkstyle.

$ vendor/bin/php-cs-fixer fix src/Person.php --dry-run --diff --rules=@PSR12 --format=checkstyle
Loaded config default.
Using cache file ".php-cs-fixer.cache".
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
  <file name="src/Person.php">
    <error severity="warning" source="PHP-CS-Fixer.braces" message="Found violation(s) of type: braces"/>
  </file>
</checkstyle>

line number could be get only with --diff

$ vendor/bin/php-cs-fixer fix src/Person.php --dry-run --diff --rules=@PSR12 --format=xml 1>&2 2> /dev/null
<?xml version="1.0" encoding="UTF-8"?>
<report>
  <files>
    <file id="1" name="src/Person.php">
      <diff><![CDATA[--- /mnt/d/dev/sarb-demo/src/Person.php
+++ /mnt/d/dev/sarb-demo/src/Person.php
@@ -18,5 +18,4 @@
     {
         return $this->name;
     }
-
 }
]]></diff>
    </file>
  </files>
  <time unit="s">
    <total value="0.026"/>
  </time>
  <memory value="12" unit="MB"/>
</report>
DaveLiddament commented 3 years ago

Hi @sasezaki thanks for the feature request and for links to research you've already done. I'm not sure I'll be able to add this due to issue that php-cs-fixer does not supply line number. We might have to wait until there is support from the php-cs-fixer before progressing.

I'll take a bit more of a look at this and the diffs later this evening (I'm on UK time).

DaveLiddament commented 2 years ago

Without line numbers it is not going to be possible to implement this. The relevant issue is https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3601

If a PR for this, or a similar PR that adds line numbers to an output gets merged then I'll happily create a ResultsParser for the format.

For now I'll close this issue.