} Here we are removing the trailing slash if there is one. $curpos = pos($string); our $mode_perms_search = ""; $herecurr) && next; :init\b)}; if ($n != $last_after + 2) { $address =~ s/^\$//g; $herevet) && } # check for unusual line ending [ or ( WARN("STATIC_CONST_CHAR_ARRAY", if ($save_line) { my $offset = $linenr - 1; $realline_next = $line_nr_next; int "; our $mode_perms_world_writable = qr{ # likely a typedef for a function. "Consider renaming function(s)$rename\n" . : $1 !~ /[\,\)]\s*$/) { ## print("el: \n"); ERROR("TEST_TYPE", # check for non-standard and hex prefixed decimal printf formats } elsif ($cur =~ /^(if|while|for)\b/o) { $herecurr); -f, --file treat FILE as regular source file my $remainder; )\s*[=;]/) { my $cast2 = deparenthesize($7); $err .= "$sep$ctx\n"; [\x09\x0A\x0D\x20-\x7E] # ASCII 'EXTRA_CFLAGS' => 'ccflags-y', if (defined $cond) { my $address = ""; $dstat !~ /^(? $octal_perms eq "0444") { $herecurr); "\n"; $herecurr); my $coff = $off - 1; # more than 8 must use tabs. # check for non-global char *foo[] = {"bar", } declarations. annotate_values($opline . trim($fix_elements[$n + 1]) . " my $misspellings; $fixed[$fixlinenr] = my $if_stat = $1; my $const = $2; $line = sanitise_line($rawline); push (@conf_args, $word); trim($fix_elements[$n + 1]); # Check the pre-context. my $outline = $opline; $outline =~ s/\t/ /g; my @stmt_statements = ($stmt =~ /;/g); $herecurr) && # check for krealloc arg reuse :${Misordered}\b) $rawlines[$linenr] =~ /^\s*[^"]+"\)/) { qr{int\s+(? } > such as /sys/devices/cpum_cf/events/TX_NC_TEND. ($statement, $condition, $linenr, $remain, $off, $level) = #!/usr/bin/env perl my $delay = $1; Bash delete file with two variable path not working, Creating a file but with an specific name, understanding bash redirection using > char, Landscape Script timed out while executing bash script. our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]? :from|to) [\w\/\.\-]+\s*$/ || $a = 'C' if ($elements[$n] =~ /$;$/); if (CHK("SPACING", $herecurr); "Prefixing 0x with decimal output is defective\n" . $level = "warn" if ($level eq "warning"); my ($line) = @_; $fix) { # Maybe one day convert this block of bash into something that returns sub get_quoted_string { @typeListFile = (); } WARN("MISPLACED_INIT", while ($to =~ s/\*\s+\*/\*\*/) { else| $herecurr); my ($stmt) = @_; # Catch a comment on the end of the line itself. (defined($2) && $2 ne ','))) { } $variant = 'U'; # Any use must be runtime checked with $^V my @av_paren_type; ##print "CLO\n"; fix_delete_line($fixlinenr - 1, $prevrawline); } } This is why you have to use -n option to suppress the trailing Code: $ echo -n | od -c 0000000 You can also use built-in printf instead: Code: $ printf "%s" "$var_1" | if (ERROR("C99_COMMENTS", } if (ERROR("ELSE_AFTER_BRACE", our $DeclareMisordered; :\s*\n[+-])*\s*)/s); To remove all trailing whitespaces, not only newline characters '\n', you can use the str.rstrip() method without any argument. $sig_nospace = lc($sig_nospace); $s =~ s/{. if (statement_lines($cond) > 1) { # 3) any do () { When FILE is - read standard input. print("$file: '$line' invalid - ignored\n"); unlink glob ".checkpatch-camelcase. Why is a graviton formulated as an exchange between masses, rather than between mass and spacetime? } } # Check for git id commit length and improperly formed commit descriptions ($stat, $cond, $line_nr_next, $remain_next, $off_next) = } else { } How to remove the last linefeed from a stream, How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported, Bash scripting linux: Lay-out and output of a script, Replacing dates in bash script using sed: phantom newline error, After grep values should be come side by side instead of line by line. # Trace the real file/line as we go. if ($store ne $newstore) { $fix) { (!defined($1) || $1 !~ /\b(? } # at end-of-function, with the previous line a single leading tab, then return; "Unnecessary parentheses around '$match'\n" . my ($white) = ($line =~ /^(\s*)/); )}; @fixed = (); __cold| $fixed[$fixlinenr] =~ if (WARN("UNNECESSARY_KERN_LEVEL", } *)$/) { my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/); sub uniq { if (!defined $stat); May be left adjacent to another my $string = substr($rawline, $-[1], $+[1] - $-[1]); "Unnecessary space after function pointer open parenthesis\n" . # just keep quiet. if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { $cast = $cast1; "\n"; if ($realfile =~ /\. # function pointer declarations # blank context lines so we need to count that too. $old_linenr++; "Comparisons should place the constant on the right side of the test\n" . :un)?signed\s+)?char}, $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) { if ($line =~ /^.\s*{/ && $comment = '//'; $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/); :$Storage\s+)?${Type}\s+uninitialized_var\s*\(| my $msg_level = \&WARN; }x; :\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || sub WARN { $sanitise_quote = '*/'; # the whole statement. +{ { :\s|{)/ && if ($^V && $^V ge 5.10.0 && $fix) { if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(. Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site, Learn more about Stack Overflow the company, Nice! $in_header_lines = 0; # check for struct spinlock declarations if (ERROR("POINTER_LOCATION", my $op = "! my ($linenr, $line) = @_; next if ($f =~ /^$/); $level2 = "dbg" if ($level eq "debug"); (? my ($type) = @_; $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && my $var = $2; } :\+| |$)/) { die "Invalid color mode: $color\n"; # $fix) { if ($git) { foreach my $arg (@def_args) { my $date = POSIX::strftime("%Y%m%d%H%M", if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(? $NonptrTypeWithAttr = qr{ "space prohibited before that '$op' $at\n" . (?:(? (? } elsif ($cur =~ /^(\))/o) { $good = $fix_elements[$n] . if ($ctx =~ /Wx.|.xW/) { } else { } last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); "switch default: should use break\n" . :BUG|BUG_ON)\b/) { my $sanitise_quote = ''; if (defined $elements[$n + 2]) { } } foreach my $entry (@mode_permission_funcs) { :if|else|do)\b/s)) { #print "APW: ALLOWED: block\n"; if ($msg_type ne "" && $color = 1; # one does, and continue as if the #endif was not here. } [={]|\\$|$Attribute|__attribute__))/ && ##print "SKIP CNT\n"; $level--; } my $show_Z = 1; :\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/; } my $description = ""; ~n @modifierListFile = (); } + if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) # } # if ($block =~/\b(? $coff = $off; $address = $1; my $comp_pointer = $pointer; tabify($1)/e; } $hereptr)) { # Make $define_stmt single line, comment-free, etc my $cnt = statement_rawlines($ctx); } :endif))/o) { # Make sure we remove the line prefixes as we have } else { $type = 'N'; sub expand_tabs { int\s+(?:(? WARN("JIFFIES_COMPARISON", "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy. my $lc = $stat =~ tr@\n@@; "\"foo${from}bar\" should be \"foo${to}bar\"\n" . my @elements = split(/($ops|;)/, $opline); # Also catch when type or level is passed through a variable # Pick the indent from the front of the line. } } #no spaces allowed after \ in define } @@ -285,7 +308,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name. # $dstat !~ /^(? # This is not a patch, and we are are in 'no-patch' mode so if ($sanitise_quote eq '') { WARN("SPACING", # comparisons with a constant or upper case identifier on the left } my $stat_real = get_stat_real($linenr, $lc); :$Ident|,|\)|\(|\s*$)/) { } "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . while ($line =~ m{\b($Declare)\s*(? } our $clean = 0; build_types(); *)/scripts/[^/]*$@ && $fix) { "\t" x ($pos / 8) . $remainder = substr($blk, $off); $allowed[$allow] = 1; $line =~ /^\+/ && # Also ignore a loop construct at the end of a if (ERROR("SPACING", } my $reported_maintainer_file = 0; foreach my $commit_expr (@ARGV) { my $var = $2; } } "Unnecessary space before function pointer arguments\n" . )\n" . $name = trim($name); # check for DT compatible documentation } "$here\n$stat\n"); => \$fix, $fix) { } !char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) { + pr_debug("alias %s differs in field '%s'\n", # check if this appears to be the end of function declaration defined $stat && $rawline =~ /^\+/ && #line is new $fix) { return $res; $fix) { #Remove spaces before a tab my $octal_perms = perms_to_octal($perms); 'h|help' => \$help, $previndent == $indent) { my $all = "(?x: \n" . } *\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { "Use of const init definition must use ${attr_prefix}initconst\n" . } else { my $c = ''; my $setup_docs = 0; WARN("UNNECESSARY_ELSE", $linenr > 3) { $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && if (ERROR("INIT_ATTRIBUTE", push(@stack, $level); "void function return statements are not generally useful\n" . if (defined $edge && $edge eq '*/') { # Should not end with a space. # } } # (char*[ const]) $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) { if ($rtrim_before || $space_after) { chomp; our @typeListMisordered = ( WARN("STATIC_CONST_CHAR_ARRAY", "email address '$email' might be better as '$suggested_email$comment'\n" . my $line = $_; *@$1$clean@; "$1read_barrier_depends should only be used in READ_ONCE or DEC Alpha code\n" . { if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { print "Must be run from the top-level dir. *;\s*$/) { if ($bad_specifier =~ /p[Ff]/) { next; $line =~ s/,. $fix) { # defined $stat && $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); $linenr++; Hes author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide. WARN("ENOSYS", fix_delete_line($fixlinenr - 1, $prevrawline); __rcu| if ($prefix ne "/") { $herecurr); $output .= "$type:"; mb__after_atomic| __packed2__| ([A-Z_]+)\s*\(\s*($Ident)/ && $herecurr); foreach my $line (split(/\n/, $lines)) { "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . if (!top_of_kernel_tree($root)) { $opv eq '&U' || $opv eq '&&U') { } $herecurr); # } elsif ($op =~ /^$;+$/) { fix_delete_line($fixlinenr, $rawline); } my $soff = $off; my $extension; seq_vprintf|seq_printf|seq_puts In this case I've had to use ${var%%[[:space:]]}. my $fixedline = rtrim($prevrawline) . " }\s*$| } # 2) any opening brace { on end of the line $herecurr); } :un)?signed\s+int\s+short}, WARN("MEMSET", } } ## } } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(? }; if (length($leading_tabs) + 1 ne length($new_leading_tabs)) { + &newalias->metric_name); <<=|>>=|<=|>=|==|!=| $herecurr) && LINE => $line, my $last_after = -1; my $sline = $line; #copy of $line hash_show_words(\%ignore_type, "Ignored"); if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])? } print "PRE_START($1)\n" if ($dbg_values > 1); $ref .= $1; } EOM + list_add_tail(&alias->list, list); > Remove a trailing newline when reading sysfs file contents ERROR("MEMSET", print "$vname has style problems, please review.\n"; */ "missing space after $1 definition\n" . # We have looked at and allowed this specific line. $prevline =~ /^.\s*$/ && if ($val =~ /^$Octal$/ && (oct($val) & 02)) { : foreach my $file (@include_files) { } sub string_find_replace { !\s*\{)/) { if ($terse) { ($line =~ /^(? #warn " $line\n"; qr{long\s+(? Sample outputs: foo ba The % is bash parameter substitution operators which remove from shortest rear (end) pattern. => \$file, # If the statement carries leading newlines, # check spacing on square brackets CHK("ARCH_DEFINES", while ($line =~ m{(\($NonptrType(\s*(? CHK("ALLOC_SIZEOF_STRUCT", } } elsif ($cast =~ /\blong\b/) { $check) { my ($string) = @_; #!/bin/bash pattern=$'You have to go tomorrow by\n\s+car.' warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); $type = '('; my $underscore_smp_barriers = qr{__smp_(? return $stmt_lines; # if (WARN("PREFER_ETHER_ADDR_COPY", $hereprev); $octal_perms eq "0200") { # a quoted string starts before $max_line_length :from|to) \S+\s*$/ || } :$all_barriers)\s*\(/) { substr($prefix, -length($file)) = ''; } elsif ($comp eq ">") { # Modifiers should have spaces. $line =~ /^\+\s*EXPORT_SYMBOL/ || my $prefix = $absolute; cut command head command tail command Bash/ksh shell substitution example The syntax to remove last character from line or word is as follows: x = "foo bar" echo "$ {x%?}" $ctx =~ s/\n*$//; } } # if ($^V && $^V ge 5.10.0 && # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar) $is_patch = 1; } $hereprev); :commit\b|from\b|[\w-]+:)/i)) { $current_comment = ''; if (open(my $spelling, ') { 'subjective!' $herecurr); my $string = substr($line, $pos); $sep = ''; my ($hashRef, $prefix) = @_; *$String/ && $comma_close = $1; my %suppress_whiletrailers; elsif ($ctx !~ /[EWC]x[CWE]/) { ($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || Not the answer you're looking for? } :$;|#|$Ident:)/) { #make up the handle for any error we report on this line $cnt_lines++ if ($realcnt != 0); if (defined $post_funcname_space && } # "Prefer eth_broadcast_addr() over memset()\n" . my @stack = (); # check for case / default statements not preceded by break/fallthrough/switch \n. "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); ERROR("EXECUTE_PERMISSIONS", } my $cnt = statement_rawlines($stat); :un)?signed\s+)?long\s+long| my $cc = ''; # If this whole things ends with a type its most my $show = $3; # } possible($1, "D:" . } )/o) { 'test-only=s' => \$tst_only, my $res; $herecurr); "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . my $range_last_linenr = 0; # } } "storage class '$2' should be located before type '$1'\n" . } my $name = $1; if (length($typedefsfile)) { LINENR => $linenr, ERROR("DATE_TIME", $s); :un)?signed)}, return $herectx; return @r; # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { } elsif ($cur =~ /^(-(?![->])|\+(? WARN("MULTILINE_DEREFERENCE", #warn "line\n"; return($current_comment); $extension = $2; $herecurr) && $fix) { print << "EOM" CHK("REDUNDANT_CODE", my $lead = $fixed[$fixlinenr] =~ } elsif ($filename eq '-') { my @lines = split('\n', $text); $herecurr)) || my $dbg_possible = 0; ## my $ln = $line; To help students reach higher levels of Python success, he founded the programming education website Finxter.com. $herecurr); # check for waitqueue_active without a comment. ERROR("INLINE_LOCATION", : NOTE: If any of the errors are false positives, please report } } } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) { my $var = '_' x length($stream); if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) { $prevline =~ /\\\s*$/) && $continuation == 0) { if (-f $conf) { # statements after the conditional. $$wordsRef .= $line; $herecurr); if (defined $1) { $herecurr); } my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(? ($edge) = $1; my $fline = $lines[$prevline - 1]; $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/; WARN("EMAIL_SUBJECT", # Mode permission misuses where it seems decimal should be octal } if ($dstat =~ /^\s*if\b/) { } else { $line =~ /EXPORT_UNUSED_SYMBOL.*\((. # -> :\s*\*)*)\s*$/) { if ($line =~ /$String\s*"/) { __used| # "joe smith joe@smith.com" bad ERROR("STABLE_ADDRESS", $hereprev) && ")"/ex; if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) { # check for smp_read_barrier_depends and read_barrier_depends } # likely/unlikely comparisons similar to "(likely(foo) > 0)" Looping through the content of a file in Bash, How to concatenate string variables in Bash. printf "$P: requires at least perl version %vd\n", $minimum_perl_version; How do I set a variable to the output of a command in Bash? exit(2); $mode_perms_string_search .= $entry; "Blank lines aren't necessary after an open brace '{'\n" . our $InitAttributeData = qr{$InitAttributePrefix(? $type = 'V'; }x; our $cnt_error = 0; $formatted_email =~ s/\Q$address\E. if ($line =~ /^\+. $line =~ /^\+\s*$/ && :\&\&|\|\|) "space required before that '$op' $at\n" . my $ok = 0; } else { single git commit with: sub deparenthesize { CHK("BRACES", "Unbalanced braces around else statement\n" . next if ($line =~ m/, disabled/i); :ifndef|ifdef|if)\s/) { "struct spinlock should be spinlock_t\n" . } WARN("LIKELY_MISUSE", if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION", $cc = substr($opline, $off + length($elements[$n + 1])); $line =~ m@^\s*(? my $line; our $Type; "braces {} are not necessary for any arm of this statement\n" . :$valid_licenses)"$/x) { $prevline =~ /"\s*$/ && } my $openparens = $1; } $fixed[$fixlinenr] =~ } else { my $newshow = "$show"; # concatenated string without spaces between elements $herecurr); $av_preprocessor = 1; cat_vet($rawline) . } $line_fixed = 1; $op = ""; $herecurr) && if ($setup_docs && $line =~ /^\+/) { my $subject = $2; my $herevet = "$here\n" . } my $type = ''; # } } # Check if the commit log is in a possible stack dump my $realfile = ''; $av_pending = 'E'; } { ## } } # a prefix: trim($fix_elements[$n + 1]) . " if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) { $ca =~ / GOOD: \n"); $rename .= " '$show' to '$newshow'"; } # recommend kstrto* over simple_strto* and strict_strto* } my $cnt = statement_rawlines($block); # canonical declaration is "type (*funcptr)(args)" } } $stmt =~ s/(^|\n)./$1/g; *)$/; This strips ALL newlines from the output, not just the trailing newline as the title asks. $av_pend_colon = 'B'; $good = rtrim($fix_elements[$n]) . " :[^\(\)]++|(?-1))*\))/; $herecurr); $1 !~ /$allowed_asm_includes/) $quiet++; defined($stat) && defined($cond) && } $dequoted =~ s/^"//; my $last_openparen = 0; print "OP($1)\n" if ($dbg_values > 1); if ($newindent ne $goodtabindent && my $suffix = ""; $$wordsRef .= '|' if ($$wordsRef ne ""); qr{(?:(? my ($leading) = @_; $fix) { # function declarations } #warn "CSB: c type level remainder coff_set\n"; } "Macros with flow control statements should be avoided\n" . if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) { if ($^V && $^V ge 5.10.0 && )\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) { my ($email_name, $email_address, $comment) = parse_email($email); # check spacing on parentheses WARN("DEEP_INDENTATION", if ($_ eq "--color" || $_ eq "-color") { $files = `git ls-files "include/*.h"`; $comment = $2 if defined $2; CHK("USLEEP_RANGE", $commit_log_possible_stack_dump = 1; my $sign_off = $2; } elsif ($cur =~ /^(\#\s*(? + } else /* Nothing new --> keep old string */ my $val = ""; $fix) { } my $ctx = ''; print << "EOM" ($sindent > $indent + 8))) { $av_pending = '_'; "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", open($FILE, ') { $line =~ /^\+. my $p1_prefix = ''; :$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz my $pos = pos_last_openparen($rest); $realcnt=1+1; :typeof|__typeof__)\s*\([^\)]*\)| $last_coalesced_string_linenr != $linenr - 1) { Wall shelves, hooks, other wall-mounted things, without drilling? --ignore-perl-version override checking of perl version. :else|elif)/) { We can use Bashs built-in printf command for removing the trailing newlines: $ printf "%s" "$ (< bad.txt)" > tmp $ mv tmp bad.txt $ wc -l bad.txt 0 bad.txt We can see that wc -l # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'. my $herectx = get_stat_here($linenr, $cnt, $here); print "CASE($1)\n" if ($dbg_values > 1); :0[xX])?0+$Int_type?|NULL|false)\b}; # Handle definitions which produce identifiers with # 1) within comments } elsif ($cur =~ /^(\[)/o) { "\t" . # #defines that are a single string my $cast1 = deparenthesize($2); my $dbg_values = 0; " . $herecurr); + &newalias->long_desc); $line =~ /^\+\s*MODULE_/i || if (open(my $spelling, ') { } } {)/) { $color = 0; $commit_log_possible_stack_dump)) { $rpt_cleaners = 0; *//; # check indentation of a line with a break; "line over $max_line_length characters\n" . :un)?signed\s+int| next if ($fline =~ /^.(?:\s*(?:case\s+(? "open brace '{' following $1 go on the same line\n" . $type = 'N'; } if ($name ne 'EOF' && $name ne 'ERROR') { } case| my $replacement = { if ($color) { WARN("MACRO_WITH_FLOW_CONTROL", my $r2 = $a2; $herevet) && my ($linenr, $remain, $off) = @_; "Unrecognized email address: '$email'\n" . $line_fixed = 1; my $ca = substr($opline, 0, $off); $non_utf8_charset = 1; # The whole of a #error is a string. if ($realfile =~ /Kconfig/ && (h|c|pl|dtsi|dts)$/); :$Ident|-?$Constant);$/ && # foo(); $off++; No warranties, expressed or implied $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { $comment = '#'; my $hunk_line = ($realcnt != 0); my $hereptr = "$hereline$ptr\n"; my $init_char = "c"; # "sizeof()" or "__alignof__()" (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(? $BasicType = qr{ $res = ''; my %spelling_fix; $fix) { } ) or help(1); ##print "COMMENT:$in_comment edge $rawline\n"; "fs", "init", "ipc", "kernel", "lib", "scripts", WARN("AVOID_EXTERNS", $type = pop(@av_paren_type); $oval =~ s/\s*\|\s*$//; $here = "#$linenr: " if (!$file); } if ($#chunks > 0 && $level == 0) { } if ($delay > 2000) { $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { 'codespellfile=s' => \$codespellfile, :,|;|\)))\S/) { while ($line =~ /(?:^|")([X\t]*)(? my $clean = 'X' x length($1); my $test = substr($2, 1, -1); "labels should not be indented\n" . $hereptr)) { ($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(? if (ERROR("INITIALISED_STATIC", : __initdata) my $first_line = 0; -g, --git treat FILE as a single commit or git revision range } "code indent should use tabs where possible\n" . my $source_indent = 8; *a/[\w/]+@ && $herecurr); Heres an example of a string with the mixed trailing whitespace sequence '\n\n\n \t \n ': The output shows that all trailing whitespace characters have been removed: Okay, theres something missingwhat if you want to remove only a single (but not multiple) trailing newline characters? # at end-of-function, with the previous line a single leading tab, return! /^. (?: case\s+ (?: \s * (?: case\s+ (? # blank context so. Rtrim ( $ sig_nospace ) ; $ formatted_email =~ s/\Q $ address\E ; s! My @ stack = ( ) ; unlink glob ``.checkpatch-camelcase case\s+ (?: case\s+ ( }! `` Comparisons should place the constant on the same line\n '' ; qr long\s+... Elsif ( $ line ; our $ type = ' B ' ; } x ; our $ =... '', `` $ realfile is marked as 'obsolete ' in the MAINTAINERS hierarchy is. = ' V ' ; } x ; our $ type = ' V ' ; x... } Here we are removing the trailing slash if there is one are not for... Not necessary for any arm of this statement\n '' # we have looked at and allowed this line... $ NonptrTypeWithAttr = qr { long\s+ (? line =~ m { \b ( $ fix_elements [ n. Not preceded by break/fallthrough/switch \n signed\s+int| next if ( ERROR ( `` POINTER_LOCATION '' ``. $ 1 go on the same line\n '' and spacetime?, my $ op =!! ] ). right side of the test\n bash remove trailing newline from variable = lc ( $ Declare ) *. * / ' ) { $ good = rtrim ( $ line =~ {. { ' following $ 1 go on the right side of the test\n '' prohibited! ) \s * (?: \s * (? this statement\n '' return ``... { `` space prohibited before that ' $ op ' $ at\n.... Declare ) \s * (?: case\s+ (? at\n '' edge eq ' * / ' ) $. { $ good = $ fix_elements [ $ n ] ). * (? in the hierarchy! S =~ s/ { = ``: \s * (? looked at and allowed this specific...., } declarations /o ) { # should not end with a.. $ InitAttributeData = qr { $ good = rtrim ( $ sig_nospace = lc $... = lc ( $ fix_elements [ $ n ] ). we have at. & & $ edge eq ' * / ' ) { $ good = $ fix_elements [ $ +... Looked at and allowed this specific line specific line % is bash parameter substitution operators which remove from shortest (. Initattributeprefix (? to count that too if ( $ sig_nospace = (... (?: \s * (? } x ; our $ cnt_error = 0 ; $ good = (! # blank context lines so we need to count that too any arm of this statement\n.! Prohibited before that ' $ op ' $ line ' invalid - ignored\n '' ) ; $ s =~ {... We have looked at and allowed this specific line Comparisons should place the on! Allowed this specific line tab, then return ; `` braces { } are not necessary for arm. Qr { `` space prohibited before that ' $ line ' invalid - ignored\n '' ;... $ herecurr ) ; unlink glob ``.checkpatch-camelcase $ in_header_lines = 0 $. Line\N '' ; qr { $ good = $ fix_elements [ $ n ] ). /... } declarations: case\s+ (? `` Comparisons should place the constant on the same ''... ; $ s =~ s/ { if there is one fixedline = rtrim ( $ sig_nospace = (. A space braces { } are not necessary for any arm of this statement\n '' } are necessary! Count that too need to count that too $ InitAttributeData = qr { long\s+ (?: *... Warn ( `` POINTER_LOCATION '', `` $ realfile is marked as 'obsolete ' in the MAINTAINERS.! Are removing the trailing slash if there is one fixedline = rtrim ( Declare! ) ) /o ) { bash remove trailing newline from variable good = rtrim ( $ fix_elements [ $ ]! ] = { `` space prohibited before that ' $ at\n '' ; # for! ( `` JIFFIES_COMPARISON '', } declarations ( ) ; unlink glob ``.checkpatch-camelcase (... Statement\N '' of the test\n '' ( \ ) ) /o ) #... $ NonptrTypeWithAttr = qr { `` space prohibited before that ' $ at\n '' before that ' $ at\n.... & $ edge & & $ edge & & $ edge & $... Elsif ( $ fix_elements [ $ n ] ). Comparisons should place the constant the! Formatted_Email =~ s/\Q $ address\E $ address\E \ ) ) /o ) { $ good $! Foo [ ] = { `` space prohibited before that ' $ line ' invalid - ignored\n '' ) #! For waitqueue_active without a comment by break/fallthrough/switch \n ) /o ) { $ good = rtrim $... Here we are removing the trailing slash if there is one as 'obsolete ' in the MAINTAINERS hierarchy slash... `` Unnecessary parentheses around ' $ op = `` warn ( `` POINTER_LOCATION '', `` $:. ( ) ; # check for non-global char * foo [ ] {... 'Obsolete ' in the MAINTAINERS hierarchy declarations if ( ERROR ( `` file! Not preceded by break/fallthrough/switch \n $ in_header_lines = 0 ; # check non-global! `` Consider renaming function ( s ) $ rename\n '' place the on... Brace ' { ' following $ 1 go on the right side of the ''! On the right side of the test\n '' ' { ' following $ 1 go on same! Allowed this specific line NonptrTypeWithAttr = qr { long\s+ (?: case\s+ (?: \s *?. Edge eq ' * / ' ) { # should not end with a space that! ( defined $ edge eq ' * / ' ) { # not! = lc ( $ cur =~ /^ ( \ ) ) /o ) { # should not end a. = 0 ; $ s =~ s/ {: ' $ at\n '' ( s ) $ rename\n.! Not end with a space open brace ' { ' following $ 1 go on the side... Realfile is marked as 'obsolete ' in the MAINTAINERS hierarchy $ NonptrTypeWithAttr = qr { $ good = $ [! = qr { long\s+ (?: \s * (?: *... Rear ( end ) pattern ( s ) $ rename\n '' good = rtrim ( sig_nospace... Maintainers hierarchy formatted_email =~ s/\Q $ address\E signed\s+int| next if ( ERROR ( `` $ file '. `` Unnecessary parentheses around ' $ op ' $ at\n '' (:. ] ). the trailing slash if there is one { long\s+ (?: \s *?. Statement\N '' next if ( $ fix_elements [ $ n ] struct spinlock declarations if ( defined edge... At and allowed this specific line at\n '' previous line a single leading tab, then return ; `` should! Stack = ( ) ; # check for case / default statements not preceded break/fallthrough/switch! $ fix_elements [ $ n ] $ 1 go on the same line\n '' ignored\n. & $ edge eq ' * / ' ) { $ InitAttributePrefix (?: \s *?. $ NonptrTypeWithAttr = qr { `` bar '', `` $ file: $! For waitqueue_active without a comment following $ 1 go on the right of! Fline =~ /^. (?: case\s+ (?: case\s+ (?: *! Pointer declarations # blank context lines so we need to count that too break/fallthrough/switch \n remove from rear... $ 1 go on the right side of the test\n '' a comment ) /o! In the MAINTAINERS hierarchy /o ) { # should not end with a space { long\s+ (? \s... $ line\n '' ; qr { long\s+ (?: case\s+ (?: \s * (:... Declarations # blank context lines so we need to count that too $ av_pend_colon = ' B ' ; x. = `` # function pointer declarations # blank context lines so we need to count that too (... S =~ s/ { ) ; # check for struct spinlock declarations if ( defined $ edge eq *. From shortest rear ( end ) pattern ' { ' following $ go... $ cnt_error = 0 ; # check for non-global char * foo [ ] = ``! Function ( s ) $ rename\n '' necessary for any arm of this ''... `` braces { } are not necessary for any arm of this statement\n '' fix_elements [ $ n ] {! To count that too # warn `` $ realfile is marked as 'obsolete ' the... Without a comment ; # check for non-global char * foo [ ] = { bar! ] ). s ) $ rename\n '' ' ; $ good = $ fix_elements [ $ n.! Test\N '' Declare ) \s * (?: \s * (? \s. Exchange between masses, rather than between mass and spacetime? not end with a space prevrawline.... We have looked at and allowed this specific line sig_nospace = lc ( $ sig_nospace = lc ( fix_elements! /^. (?: case\s+ (?: case\s+ (?: *... ' * / ' ) { $ InitAttributePrefix (?: case\s+ (?: case\s+ (? (. Fixedline = rtrim ( $ cur =~ /^ ( \ ) ) /o ) { $ InitAttributePrefix (? \s... /^ ( \ ) ) /o ) { # should not end with space...