Skip to content

Commit 6166ea4

Browse files
committed
Allow not passing a --standard argument and use the default configuration instead.
1 parent 7b67510 commit 6166ea4

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Options:
2929
- `--start_revision=<arg>`: First (older) revision number/commit hash
3030
- `--end_revision=<arg>`: Second (newer) revision number/commit hash
3131
- `--tolerance[=<arg>]`: Last level of issues that will be tolerated. Accepted values are blockers | warnings | notes | none.
32-
- `--standard[=<arg>]`: Name of the phpcs standard to use: 'WordPress', 'WordPress-VIP', 'WordPress-Core', 'WordPress-Docs', 'WordPress-Extra', 'Toolset'
32+
- `--standard[=<arg>]`: Name of the phpcs standard to use: 'WordPress', 'WordPress-VIP', 'WordPress-Core', 'WordPress-Docs', 'WordPress-Extra' or 'Toolset'.
33+
If you omit this argument, a [default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file)
34+
will be used.
3335
- `--log_level[=<arg>]`: Control verbosity by passing a number from 0 (most verbose) to 2 (least verbose, only errors).
3436
- `--ignore_space_changes`: Whitespace changes will be ignored when git is used to produce the diff.
3537
- `--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.

bin/phpcs-diff

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ $getopt->getOption( 'standard', true )
5656
->setMode( \GetOpt\GetOpt::OPTIONAL_ARGUMENT )
5757
->setValidation( function( $value ) {
5858
return in_array( $value, [ 'WordPress', 'WordPress-VIP', 'WordPress-Core', 'WordPress-Docs', 'WordPress-Extra', 'Toolset' ] );
59-
} )
60-
->setDefaultValue( 'WordPress' );
59+
} );
6160

6261
$getopt->getOption( 'log_level', true )
6362
->setMode( \GetOpt\GetOpt::OPTIONAL_ARGUMENT )

inc/Main.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ private function parse_phpcs_results( $phpcs_results ) {
166166
}
167167

168168
private function diff_results_for_two_revs( $new_rev_results, $old_rev_results, LineMapping $line_mapping ) {
169-
170169
$new_rev_results = $this->parse_phpcs_results( $new_rev_results );
171170
$old_rev_results = $this->parse_phpcs_results( $old_rev_results );
172171

172+
if( empty( $old_rev_results ) ) {
173+
// Nothing to compare against. All issues in the new revision are new issues.
174+
return $new_rev_results;
175+
}
176+
173177
$last_old_line_number = max( array_keys( $old_rev_results ) );
174178
$line_mapping->build_mapping( $last_old_line_number );
175179

inc/backends/Git.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,17 @@ public function run_phpcs_for_file_at_revision( $filename, $revision, $phpcs_com
189189
);
190190
}
191191

192+
if( null !== $phpcs_standard ) {
193+
$phpcs_standard_arg = sprintf( '--standard=%s', escapeshellarg( $phpcs_standard ) );
194+
} else {
195+
$phpcs_standard_arg = '';
196+
}
197+
192198
$phpcs_command = sprintf(
193-
'%s --report=json --runtime-set installed_paths %s --standard=%s --stdin-path=%s -',
199+
'%s --report=json --runtime-set installed_paths %s %s --stdin-path=%s -',
194200
escapeshellcmd( $phpcs_command ),
195201
escapeshellarg( $standards_location ),
196-
escapeshellarg( $phpcs_standard ),
202+
$phpcs_standard_arg,
197203
escapeshellarg( $filename )
198204
);
199205

inc/resultparser/ResultParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ public function parse( $raw_phpcs_output ) {
2626

2727
$file = array_pop( $phpcs_json['files'] );
2828

29-
if( ! array_key_exists( 'messages', $file ) || ! is_array( $file['messages'] ) ) {
29+
if( ! is_array( $file ) || ! array_key_exists( 'messages', $file ) ) {
30+
// Happens for perfect code :)
31+
return [];
32+
}
33+
34+
if( ! is_array( $file['messages'] ) ) {
3035
throw new \RuntimeException( 'Unable to parse the phpcs output: ' . $raw_phpcs_output );
3136
}
3237

0 commit comments

Comments
 (0)