Skip to content

Commit 0263841

Browse files
authored
Merge pull request zaantar#2 from kmgalanakis/master
Allow to exclude from the testing files with an invalid extension by using the "excluded_exts" argument with a comma-separated list of excluded extensions.
2 parents f7a4c3c + 27a15e6 commit 0263841

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.idea/
12
/vendor/
23
/standards/VariableAnalysis
34
/standards/WordPress

bin/phpcs-diff

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ $getopt = new \GetOpt\GetOpt(
4444
[ 'no_colours', \GetOpt\GetOpt::NO_ARGUMENT ],
4545
[ 'colour_primary', \GetOpt\GetOpt::REQUIRED_ARGUMENT ],
4646
[ 'colour_secondary', \GetOpt\GetOpt::REQUIRED_ARGUMENT ],
47+
[ 'excluded_exts', \GetOpt\GetOpt::OPTIONAL_ARGUMENT ],
4748
]
4849
);
4950

@@ -73,6 +74,7 @@ $phpcs_standard = $getopt->getOption( 'standard' );
7374
$log_level = $getopt->getOption( 'log_level' );
7475
$ignore_space_changes = $getopt->offsetExists( 'ignore_space_changes' );
7576
$no_colours = $getopt->offsetExists( 'no_colours' );
77+
$excluded_exts = $getopt->getOption( 'excluded_exts' );
7678

7779
$sniff_unstaged = $getopt->offsetExists( 'sniff_unstaged' );
7880
if( $sniff_unstaged ) {
@@ -127,7 +129,7 @@ $controller = new Main( $version_control, $logger, $options );
127129
$controller->set_phpcs_standard( $phpcs_standard );
128130

129131
try {
130-
$found_issues = $controller->run( $start_revision, $end_revision, '' );
132+
$found_issues = $controller->run( $start_revision, $end_revision, '', $excluded_exts );
131133
} catch ( \Exception $e ) {
132134
$logger->log(
133135
LoggerInterface::ERROR,

inc/Main.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public function set_phpcs_standard( $standard ) {
6565
}
6666

6767
public function set_excluded_extensions( $excluded_exts ) {
68-
if ( false === is_array( $excluded_exts) ) {
68+
if ( false === is_array( $excluded_exts ) ) {
6969
$excluded_exts = explode( ',', $excluded_exts );
7070
}
7171
$this->excluded_extensions = $excluded_exts;
7272
}
7373

74-
public function run( $oldest_rev, $newest_rev, $directory = '' ) {
74+
public function run( $oldest_rev, $newest_rev, $directory = '', $excluded_exts = '' ) {
7575

7676
if ( true !== $this->nocache ) {
7777
$found_issues = false; //wp_cache_get( $cache_key, $cache_group );
@@ -80,6 +80,10 @@ public function run( $oldest_rev, $newest_rev, $directory = '' ) {
8080
}
8181
}
8282

83+
if ( '' !== $excluded_exts ) {
84+
$this->set_excluded_extensions( $excluded_exts );
85+
}
86+
8387
$diff = trim( $this->version_control->get_diff( $directory, $newest_rev, $oldest_rev, [] ) );
8488

8589
$this->stop_the_insanity();
@@ -146,7 +150,13 @@ private function process_file( $filename, $oldest_rev, $newest_rev, $is_new_file
146150
}
147151

148152
foreach( $this->excluded_extensions as $excluded_ext ) {
149-
if ( function_exists( 'wp_endswith' ) && wp_endswith( $filename, $excluded_ext ) ) {
153+
if (
154+
(
155+
function_exists( 'wp_endswith' ) &&
156+
wp_endswith( $filename, $excluded_ext )
157+
) ||
158+
$excluded_ext === pathinfo( $filename, PATHINFO_EXTENSION )
159+
) {
150160
return false;
151161
}
152162
}

0 commit comments

Comments
 (0)