Skip to content

Commit 7b67510

Browse files
committed
Allow printing the list of issues without colours.
1 parent 89b55c5 commit 7b67510

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Options:
3333
- `--log_level[=<arg>]`: Control verbosity by passing a number from 0 (most verbose) to 2 (least verbose, only errors).
3434
- `--ignore_space_changes`: Whitespace changes will be ignored when git is used to produce the diff.
3535
- `--sniff_unstaged`: Inspect unstaged changes in the working directory against the latest commit (HEAD). `--start_revision` and `--end_revision` will be ignored in this case.
36+
- `--no_colours`: Do not use coloured output when printing the list of issues.
3637

3738
Limitations:
3839

bin/phpcs-diff

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ $getopt = new \GetOpt\GetOpt(
4141
[ 'log_level' ],
4242
[ 'ignore_space_changes', \GetOpt\GetOpt::NO_ARGUMENT ],
4343
[ 'sniff_unstaged', \GetOpt\GetOpt::NO_ARGUMENT ],
44+
[ 'no_colours', \GetOpt\GetOpt::NO_ARGUMENT ],
4445
]
4546
);
4647

@@ -76,13 +77,24 @@ $end_revision = $getopt->getOption( 'end_revision' );
7677
$phpcs_standard = $getopt->getOption( 'standard' );
7778
$log_level = $getopt->getOption( 'log_level' );
7879
$ignore_space_changes = $getopt->offsetExists( 'ignore_space_changes' );
80+
$no_colours = $getopt->offsetExists( 'no_colours' );
7981

8082
$sniff_unstaged = $getopt->offsetExists( 'sniff_unstaged' );
8183
if( $sniff_unstaged ) {
8284
$start_revision = 'HEAD';
8385
$end_revision = Backends\Git::UNSTAGED;
8486
}
8587

88+
global $colour_primary, $colour_secondary;
89+
90+
if( $no_colours ) {
91+
$colour_primary = '';
92+
$colour_secondary = '';
93+
} else {
94+
$colour_primary = COLOR_PRIMARY;
95+
$colour_secondary = COLOR_SECONDARY;
96+
}
97+
8698
$logger = new Log\ShellLogger( (int) $log_level );
8799
$options = [ 'ignore-space-change' => $ignore_space_changes ];
88100
$version_control = new Backends\Git( '', $logger, $options );
@@ -104,9 +116,10 @@ try {
104116

105117

106118
function render_line( $filename, $line, $column, $message, $source ) {
107-
return OUTPUT_BOLD . COLOR_PRIMARY . "* " . $filename . ":" . $line . ':' . $column . OUTPUT_UNBOLD . PHP_EOL
119+
global $colour_primary, $colour_secondary;
120+
return OUTPUT_BOLD . $colour_primary . "* " . $filename . ":" . $line . ':' . $column . OUTPUT_UNBOLD . PHP_EOL
108121
. "\t" . $source . ": " . PHP_EOL
109-
. "\t" . COLOR_SECONDARY . $message . OUTPUT_RESET;
122+
. "\t" . $colour_secondary . $message . OUTPUT_RESET;
110123
}
111124

112125
$blockers = $warnings = $notes = [];
@@ -127,11 +140,13 @@ foreach ( $found_issues as $filename => $issues ) {
127140
}
128141

129142
function echo_chapter( $title, $items ) {
143+
global $colour_primary;
144+
130145
if( empty( $items ) ) {
131146
return;
132147
}
133148

134-
echo OUTPUT_REVERSE . OUTPUT_BOLD . COLOR_PRIMARY . "### " . $title . OUTPUT_RESET . PHP_EOL . PHP_EOL;
149+
echo OUTPUT_REVERSE . OUTPUT_BOLD . $colour_primary . "### " . $title . OUTPUT_RESET . PHP_EOL . PHP_EOL;
135150
foreach ( $items as $item ) {
136151
echo $item . PHP_EOL;
137152
}

0 commit comments

Comments
 (0)