Last active
August 30, 2023 14:30
-
-
Save dfelton/24f4122c0f5107b77f136188dcc89fbd to your computer and use it in GitHub Desktop.
Revisions
-
dfelton revised this gist
Aug 30, 2023 . 1 changed file with 31 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,18 +5,30 @@ php -r ' $contents = file_get_contents("phpcs_results"); $contents = explode(PHP_EOL, $contents); $currentFile = ""; $rules = []; foreach ($contents as $line) { if (strpos($line, "FILE: " . __DIR__) !== false) { $currentFile = trim(explode(".php", explode(basename(__DIR__) . "/", $line)[1])[0]) . ".php"; $currentFile = str_replace( [".less.php", ".html.php", ".phtml.php", ".js.php", ".css.php"], [".less", ".html", ".phtml", ".js", ".css"], $currentFile ); } $line = str_replace( [ "()", "(...)", "(7)", "(8)", "(6)", "(SHA-256, SHA-512 etc.)", "(dash)", "(underscore)", "(int)" "(string)", ], "", $line ); @@ -37,12 +49,18 @@ foreach ($contents as $line) { ksort($rules); foreach ($rules as $rule => $files) { ksort($files); if ( strpos($rule, "|") === 0 || strpos($rule, "data") === 0 || strpos($rule, "WARNING") !== false || strpos($rule, "ERROR") !== false ) { continue; } echo " <rule ref=\"$rule\">" . PHP_EOL; foreach ($files as $file) { echo " <exclude-pattern>$file</exclude-pattern>" . PHP_EOL; } echo " </rule>" . PHP_EOL; } ' > rules.xml -
dfelton created this gist
Aug 30, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #!/bin/bash ./vendor/bin/phpcs . > phpcs_results php -r ' $contents = file_get_contents("phpcs_results"); $contents = explode(PHP_EOL, $contents); $currentFile = "";$rules = []; foreach ($contents as $line) { if (strpos($line, "FILE: " . __DIR__) !== false) { $currentFile = trim(explode(".php", explode(basename(__DIR__) . "/", $line)[1])[0]) . ".php"; $currentFile = str_replace( [".less.php",".html.php",".js.php"], [".less",".html",".js"], $currentFile ); } $line = str_replace( ["()","(...)","(6)","(string)","(7)","(SHA-256, SHA-512 etc.)","(dash)","(underscore)","(8)","(int)"], "", $line ); if (strpos($line, "(") !== false && strpos($line, ")") !== false) { $rule = trim(str_replace( ["(",")"], ["",""], substr( $line, strpos($line, " (") ) )); if (!in_array($currentFile, $rules[$rule] ?? [])) { $rules[$rule][] = $currentFile; } } } ksort($rules); foreach ($rules as $rule => $files) { ksort($files); if (strpos($rule, "|") === 0 || strpos($rule, "data") === 0 || strpos($rule, "WARNING") !== false || strpos($rule, "ERROR") !== false) { continue; } echo " <rule ref=\"$rule\">" . PHP_EOL; foreach ($files as $file) { echo " <exclude-pattern>$file</exclude-pattern>" . PHP_EOL; } echo " </rule>" . PHP_EOL; }' > rules.xml