Skip to content

Commit

Permalink
Honor ignored files list
Browse files Browse the repository at this point in the history
Even when passed a list of files to run against, honor the list of ignored files, since the list of files being passed may be generated and not user-supplied.

Fixes #33
  • Loading branch information
JDGrimes committed Dec 17, 2016
1 parent c45d174 commit c0c3839
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
28 changes: 28 additions & 0 deletions tests/data/with-config/ignored.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* Ignored file.
*/

function do_some_things() {

global $wpdb;

return $wpdb->get_results( 'SELECT * FROM ' . $wpdb->posts );
}

function do_some_other_stuff() {

echo 'Hello world';
echo 'Dlrow olleh';
}

function display_message() {

_e( 'Message', 'textdomain' );
func_to_ignore( 'yes' );
}

class AClass {
protected $ignored = 'parent';
}
3 changes: 2 additions & 1 deletion tests/data/with-config/wp-l10n-validator.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"textdomain":"textdomain",
"config":"wordpress",
"ignored-paths": [ "/ignored" ],
"ignored-functions": {
"func_to_ignore":true
},
Expand All @@ -10,4 +11,4 @@
"ignored-strings": [
"Dlrow olleh"
]
}
}
4 changes: 4 additions & 0 deletions tests/tests/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function test_files_passed() {
$output = $this->run_command( 'wp-l10n-validator textdomain -- other.php no-config.php', '/no-config' );
$this->assertEquals( "/no-config.php#16: Non gettexted string 'Hello world'", $output );
$this->assertEquals( 1, $this->exit_code );

$output = $this->run_command( 'wp-l10n-validator textdomain -- ignored.php with-config.php', '/with-config' );
$this->assertEquals( "/with-config.php#16: Non gettexted string 'Hello world'", $output );
$this->assertEquals( 1, $this->exit_code );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion wp-l10n-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,9 @@ public static function cli() {

if ( isset( $files ) ) {
foreach ( $files as $file ) {
$parser->parse_file( '/' . $file );
if ( ! $parser->is_ignored_file( '/' . $file ) ) {
$parser->parse_file( '/' . $file );
}
}
} else {
// Parse the project.
Expand Down

0 comments on commit c0c3839

Please sign in to comment.