Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various sniffs: simplify skipping the rest of the file #2506

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions WordPress/Sniffs/Files/FileNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function process_token( $stackPtr ) {
// Usage of `stripQuotes` is to ensure `stdin_path` passed by IDEs does not include quotes.
$file = TextStrings::stripQuotes( $this->phpcsFile->getFileName() );
if ( 'STDIN' === $file ) {
return;
return $this->phpcsFile->numTokens;
}

$class_ptr = $this->phpcsFile->findNext( \T_CLASS, $stackPtr );
Expand All @@ -163,7 +163,7 @@ public function process_token( $stackPtr ) {
* This rule should not be applied to test classes (at all).
* @link https://github.com/WordPress/WordPress-Coding-Standards/issues/1995
*/
return;
return $this->phpcsFile->numTokens;
}

// Respect phpcs:disable comments as long as they are not accompanied by an enable.
Expand All @@ -184,7 +184,7 @@ public function process_token( $stackPtr ) {

if ( false === $i ) {
// The entire (rest of the) file is disabled.
return;
return $this->phpcsFile->numTokens;
}
}
}
Expand All @@ -204,7 +204,7 @@ public function process_token( $stackPtr ) {
}

// Only run this sniff once per file, no need to run it again.
return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function process_token( $stackPtr ) {
if ( ! is_string( $this->new_text_domain )
|| '' === $this->new_text_domain
) {
return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

if ( isset( $this->old_text_domain ) ) {
Expand All @@ -403,7 +403,7 @@ public function process_token( $stackPtr ) {
if ( ! is_array( $this->old_text_domain )
|| array() === $this->old_text_domain
) {
return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}
}

Expand All @@ -421,7 +421,7 @@ public function process_token( $stackPtr ) {
array( $this->new_text_domain )
);

return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

if ( preg_match( '`^[a-z0-9-]+$`', $this->new_text_domain ) !== 1 ) {
Expand All @@ -432,14 +432,14 @@ public function process_token( $stackPtr ) {
array( $this->new_text_domain )
);

return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

// If the text domain passed both validations, it should be considered valid.
$this->is_valid = true;

} elseif ( false === $this->is_valid ) {
return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

if ( isset( $this->tab_width ) === false ) {
Expand Down Expand Up @@ -685,7 +685,7 @@ public function process_comments( $stackPtr ) {
if ( isset( $this->phpcsFile->tokenizerType ) && 'CSS' === $this->phpcsFile->tokenizerType ) {
if ( 'style.css' !== $file_name && ! defined( 'PHP_CODESNIFFER_IN_TESTS' ) ) {
// CSS files only need to be examined for the file header.
return ( $this->phpcsFile->numTokens + 1 );
return $this->phpcsFile->numTokens;
}

$regex = $this->theme_header_regex;
Expand Down
Loading