@@ -380,7 +380,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
380380 $ has_content = $ this ->check_string_has_translatable_content ( $ matched_content , $ param_name , $ param_info );
381381 if ( true === $ has_content ) {
382382 $ this ->check_string_has_no_html_wrapper ( $ matched_content , $ param_name , $ param_info );
383- $ this ->check_string_has_no_leading_trailing_spaces ( $ matched_content , $ param_name , $ param_info );
383+ $ this ->check_string_has_no_leading_trailing_whitespace ( $ matched_content , $ param_name , $ param_info );
384384 }
385385 }
386386 }
@@ -806,9 +806,9 @@ private function check_string_has_no_html_wrapper( $matched_content, $param_name
806806 }
807807
808808 /**
809- * Check if a translatable string has leading or trailing spaces .
809+ * Check if a translatable string has leading or trailing whitespace .
810810 *
811- * @since 3.2 .0
811+ * @since 3.4 .0
812812 *
813813 * @param string $matched_content The token content (function name) which was matched
814814 * in lowercase.
@@ -818,97 +818,24 @@ private function check_string_has_no_html_wrapper( $matched_content, $param_name
818818 *
819819 * @return void
820820 */
821- private function check_string_has_no_leading_trailing_spaces ( $ matched_content , $ param_name , $ param_info ) {
822- // Strip surrounding quotes.
821+ private function check_string_has_no_leading_trailing_whitespace ( $ matched_content , $ param_name , $ param_info ) {
823822 $ content_without_quotes = TextStrings::stripQuotes ( $ param_info ['clean ' ] );
824823 $ first_non_empty = $ this ->phpcsFile ->findNext ( Tokens::$ emptyTokens , $ param_info ['start ' ], ( $ param_info ['end ' ] + 1 ), true );
825824
826- // Define regex patterns.
827- $ pattern_leading_spaces = '/^[\x20]+/u ' ;
828- $ pattern_trailing_spaces = '/[\x20]+$/u ' ;
829- $ pattern_leading_tabs = '/^\x09+/u ' ;
830- $ pattern_trailing_tabs = '/\x09+$/u ' ;
831- $ pattern_leading_vtabs = '/^\x0B+/u ' ;
832- $ pattern_trailing_vtabs = '/\x0B+$/u ' ;
833- $ pattern_leading_newlines = '/^\x0A+/u ' ;
834- $ pattern_trailing_newlines = '/\x0A+$/u ' ;
835-
836- // Check for leading spaces.
837- if ( preg_match ( $ pattern_leading_spaces , $ content_without_quotes ) ) {
838- $ this ->phpcsFile ->addError (
839- 'Translatable string should not have leading spaces. Found: %s ' ,
840- $ first_non_empty ,
841- 'LeadingSpaces ' ,
842- array ( $ param_info ['clean ' ] )
843- );
844- }
845-
846- // Check for trailing spaces.
847- if ( preg_match ( $ pattern_trailing_spaces , $ content_without_quotes ) ) {
848- $ this ->phpcsFile ->addError (
849- 'Translatable string should not have trailing spaces. Found: %s ' ,
850- $ first_non_empty ,
851- 'TrailingSpaces ' ,
852- array ( $ param_info ['clean ' ] )
853- );
854- }
855-
856- // Check for leading tabs.
857- if ( preg_match ( $ pattern_leading_tabs , $ content_without_quotes ) ) {
858- $ this ->phpcsFile ->addError (
859- 'Translatable string should not have leading tabs. Found: %s ' ,
860- $ first_non_empty ,
861- 'LeadingTabs ' ,
862- array ( $ param_info ['clean ' ] )
863- );
864- }
865-
866- // Check for trailing tabs.
867- if ( preg_match ( $ pattern_trailing_tabs , $ content_without_quotes ) ) {
825+ if ( preg_match ( '/^\s+/u ' , $ content_without_quotes ) ) {
868826 $ this ->phpcsFile ->addError (
869- 'Translatable string should not have trailing tabs . Found: %s ' ,
827+ 'Translatable string should not have leading whitespace . Found: %s ' ,
870828 $ first_non_empty ,
871- 'TrailingTabs ' ,
872- array ( $ param_info ['clean ' ] )
873- );
874- }
875-
876- // Check for leading vertical tabs.
877- if ( preg_match ( $ pattern_leading_vtabs , $ content_without_quotes ) ) {
878- $ this ->phpcsFile ->addError (
879- 'Translatable string should not have leading vertical tabs. Found: %s ' ,
880- $ first_non_empty ,
881- 'LeadingVTabs ' ,
882- array ( $ param_info ['clean ' ] )
883- );
884- }
885-
886- // Check for trailing vertical tabs.
887- if ( preg_match ( $ pattern_trailing_vtabs , $ content_without_quotes ) ) {
888- $ this ->phpcsFile ->addError (
889- 'Translatable string should not have trailing vertical tabs. Found: %s ' ,
890- $ first_non_empty ,
891- 'TrailingVTabs ' ,
829+ 'LeadingWhiteSpace ' ,
892830 array ( $ param_info ['clean ' ] )
893831 );
894832 }
895833
896- // Check for leading new lines.
897- if ( preg_match ( $ pattern_leading_newlines , $ content_without_quotes ) ) {
898- $ this ->phpcsFile ->addError (
899- 'Translatable string should not have leading new lines. Found: %s ' ,
900- $ first_non_empty ,
901- 'LeadingNewLines ' ,
902- array ( $ param_info ['clean ' ] )
903- );
904- }
905-
906- // Check for trailing new lines.
907- if ( preg_match ( $ pattern_trailing_newlines , $ content_without_quotes ) ) {
834+ if ( preg_match ( '/\s+$/u ' , $ content_without_quotes ) ) {
908835 $ this ->phpcsFile ->addError (
909- 'Translatable string should not have trailing new lines . Found: %s ' ,
836+ 'Translatable string should not have trailing whitespace . Found: %s ' ,
910837 $ first_non_empty ,
911- 'TrailingNewLines ' ,
838+ 'TrailingWhiteSpace ' ,
912839 array ( $ param_info ['clean ' ] )
913840 );
914841 }
0 commit comments