Skip to content

Commit 643cbf9

Browse files
authored
Adds notices-as-warnings option (#69)
1 parent 0ed0967 commit 643cbf9

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

cs2pr

100644100755
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $version = '1.5.1-dev';
2121
// options
2222
$colorize = false;
2323
$gracefulWarnings = false;
24+
$noticeAsWarning = false;
2425

2526
// parameters
2627
$params = array();
@@ -34,6 +35,9 @@ foreach ($argv as $arg) {
3435
case 'colorize':
3536
$colorize = true;
3637
break;
38+
case 'notices-as-warnings':
39+
$noticeAsWarning = true;
40+
break;
3741
default:
3842
echo "Unknown option ".$option."\n";
3943
exit(9);
@@ -55,6 +59,7 @@ if (count($params) === 1) {
5559
echo "Supported options:\n";
5660
echo " --graceful-warnings Don't exit with error codes if there are only warnings.\n";
5761
echo " --colorize Colorize the output (still compatible with Github Annotations)\n";
62+
echo " --notices-as-warnings Convert notices to warnings (Github does not annotate notices otherwise).\n";
5863
exit(9);
5964
}
6065

@@ -87,7 +92,7 @@ foreach ($root as $file) {
8792
$line = (string) $error['line'];
8893
$message = (string) $error['message'];
8994

90-
$annotateType = annotateType($type);
95+
$annotateType = annotateType($type, $noticeAsWarning);
9196
annotateCheck($annotateType, relativePath($filename), $line, $message, $colorize);
9297

9398
if (!$gracefulWarnings || $annotateType === 'error') {
@@ -125,12 +130,12 @@ function relativePath($path)
125130
return str_replace(getcwd().'/', '', $path);
126131
}
127132

128-
function annotateType($type)
133+
function annotateType($type, $noticeAsWarning)
129134
{
130135
if (in_array($type, array('error', 'failure'))) {
131136
return 'error';
132137
}
133-
if (in_array($type, array('info', 'notice'))) {
138+
if (!$noticeAsWarning && in_array($type, array('info', 'notice'))) {
134139
return 'notice';
135140
}
136141
return 'warning';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
::warning file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password.
2+
::warning file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar.
3+
::warning file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly.

tests/errors/notices.expect

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
::notice file=redaxo\src\addons\2factor_auth\boot.php,line=6::Call to static method getInstance() on an unknown class rex_one_time_password.
2+
::notice file=redaxo\src\addons\2factor_auth\boot.php,line=9::Call to static method getInstance() on an unknown class rex_minibar.
3+
::notice file=redaxo\src\addons\2factor_auth\lib\one_time_password.php,line=0::Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly.

tests/errors/notices.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<checkstyle>
3+
<file name="redaxo\src\addons\2factor_auth\boot.php">
4+
<error line="6" column="1" severity="notice" message="Call to static method getInstance() on an unknown class rex_one_time_password." />
5+
<error line="9" column="1" severity="notice" message="Call to static method getInstance() on an unknown class rex_minibar." />
6+
</file>
7+
<file name="redaxo\src\addons\2factor_auth\lib\one_time_password.php">
8+
<error line="0" column="1" severity="notice" message="Class rex_one_time_password was not found while trying to analyse it - autoloading is probably not configured properly." />
9+
</file>
10+
</checkstyle>

tests/tests.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ function testXml($xmlPath, $expectedExit, $expectedOutput = null, $options = '')
4949
testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed.expect'), '--graceful-warnings');
5050
testXml(__DIR__.'/errors/warning-only.xml', 0, file_get_contents(__DIR__.'/errors/warning-only.expect'), '--graceful-warnings');
5151

52+
testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices.expect'));
53+
testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices-as-warnings.expect'), '--notices-as-warnings');
54+
5255
testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed-colors.expect'), '--colorize');
5356

5457
testXml(__DIR__.'/noerrors/only-header.xml', 0, file_get_contents(__DIR__.'/noerrors/only-header.expect'));

0 commit comments

Comments
 (0)