Browse Source

OS-7998 jsstyle/cstyle still emit 'unescaped brace in regex' warnings

Reviewed by: John Levon <john.levon@joyent.com>
Approved by: John Levon <john.levon@joyent.com>
release-not-a-release-testing-OS-7985
Tim Foster 4 years ago
parent
commit
4dd1ea34fa
  1. 44
      tools/cstyle
  2. 18
      tools/jsstyle/jsstyle

44
tools/cstyle

@ -135,6 +135,11 @@ my %old2posix = (
'u_short' => 'ushort_t',
'u_long' => 'ulong_t',
'u_char' => 'uchar_t',
'u_int8_t' => 'uint8_t',
'u_int16_t' => 'uint16_t',
'u_int32_t' => 'uint32_t',
'u_int64_t' => 'uint64_t',
'u_quad_t' => 'uint64_t',
'quad' => 'quad_t'
);
@ -384,7 +389,7 @@ line: while (<$filehandle>) {
# is this the beginning or ending of a function?
# (not if "struct foo\n{\n")
if (/^{$/ && $prev =~ /\)\s*(const\s*)?(\/\*.*\*\/\s*)?\\?$/) {
if (/^\{$/ && $prev =~ /\)\s*(const\s*)?(\/\*.*\*\/\s*)?\\?$/) {
$in_function = 1;
$in_declaration = 1;
$in_function_header = 0;
@ -392,7 +397,7 @@ line: while (<$filehandle>) {
$prev = $line;
next line;
}
if (/^}\s*(\/\*.*\*\/\s*)*$/) {
if (/^\}\s*(\/\*.*\*\/\s*)*$/) {
if ($prev =~ /^\s*return\s*;/) {
err_prev("unneeded return at end of function");
}
@ -402,7 +407,7 @@ line: while (<$filehandle>) {
next line;
}
if ($in_function_header && ! /^ (\w|\.)/ ) {
if (/^{}$/) {
if (/^\{\}$/) {
$in_function_header = 0;
$function_header_full_indent = 0;
} elsif ($picky && ! (/^\t/ && $function_header_full_indent != 0)) {
@ -421,7 +426,7 @@ line: while (<$filehandle>) {
$function_header_full_indent = 1;
}
}
if ($in_function_header && /^{$/) {
if ($in_function_header && /^\{$/) {
$in_function_header = 0;
$function_header_full_indent = 0;
$in_function = 1;
@ -430,7 +435,7 @@ line: while (<$filehandle>) {
$in_function_header = 0;
$function_header_full_indent = 0;
}
if ($in_function_header && /{$/ ) {
if ($in_function_header && /\{$/ ) {
if ($picky) {
err("opening brace on same line as function header");
}
@ -646,14 +651,14 @@ line: while (<$filehandle>) {
if (/\S\{/ && !/\{\{/) {
err("missing space before left brace");
}
if ($in_function && /^\s+{/ &&
if ($in_function && /^\s+\{/ &&
($prev =~ /\)\s*$/ || $prev =~ /\bstruct\s+\w+$/)) {
err("left brace starting a line");
}
if (/}(else|while)/) {
if (/\}(else|while)/) {
err("missing space after right brace");
}
if (/}\s\s+(else|while)/) {
if (/\}\s\s+(else|while)/) {
err("extra space after right brace");
}
if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
@ -699,25 +704,26 @@ line: while (<$filehandle>) {
# try to detect old non-POSIX types.
# POSIX requires all non-standard typedefs to end in _t,
# but historically these have been used.
if (/\b(unchar|ushort|uint|ulong|u_int|u_short|u_long|u_char|quad)\b/) {
my $types = join '|', keys %old2posix;
if (/\b($types)\b/) {
err("non-POSIX typedef $1 used: use $old2posix{$1} instead");
}
}
if ($heuristic) {
# cannot check this everywhere due to "struct {\n...\n} foo;"
if ($in_function && !$in_declaration &&
/}./ && !/}\s+=/ && !/{.*}[;,]$/ && !/}(\s|)*$/ &&
!/} (else|while)/ && !/}}/) {
/\}./ && !/\}\s+=/ && !/\{.*\}[;,]$/ && !/\}(\s|)*$/ &&
!/\} (else|while)/ && !/\}\}/) {
err("possible bad text following right brace");
}
# cannot check this because sub-blocks in
# the middle of code are ok
if ($in_function && /^\s+{/) {
if ($in_function && /^\s+\{/) {
err("possible left brace starting a line");
}
}
if (/^\s*else\W/) {
if ($prev =~ /^\s*}$/) {
if ($prev =~ /^\s*\}$/) {
err_prefix($prev,
"else and right brace should be on same line");
}
@ -803,8 +809,8 @@ process_indent($)
# skip over enumerations, array definitions, initializers, etc.
if ($cont_off <= 0 && !/^\s*$special/ &&
(/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*)){/ ||
(/^\s*{/ && $prev =~ /=\s*(?:\/\*.*\*\/\s*)*$/))) {
(/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*))\{/ ||
(/^\s*\{/ && $prev =~ /=\s*(?:\/\*.*\*\/\s*)*$/))) {
$cont_in = 0;
$cont_off = tr/{/{/ - tr/}/}/;
return;
@ -827,14 +833,14 @@ process_indent($)
return if (/^\s*\}?$/);
return if (/^\s*\}?\s*else\s*\{?$/);
return if (/^\s*do\s*\{?$/);
return if (/{$/);
return if (/}[,;]?$/);
return if (/\{$/);
return if (/\}[,;]?$/);
# Allow macros on their own lines
return if (/^\s*[A-Z_][A-Z_0-9]*$/);
# cases we don't deal with, generally non-kosher
if (/{/) {
if (/\{/) {
err("stuff after {");
return;
}
@ -903,7 +909,7 @@ process_indent($)
#
next if (@cont_paren != 0);
if ($cont_special) {
if ($rest =~ /^\s*{?$/) {
if ($rest =~ /^\s*\{?$/) {
$cont_in = 0;
last;
}

18
tools/jsstyle/jsstyle

@ -58,8 +58,8 @@ my $usage =
"Usage: jsstyle [-h?vcC] [-t <num>] [-f <path>] [-o <config>] file ...
Check your JavaScript file for style.
See <https://github.com/davepacheco/jsstyle> for details on config options.
Report bugs to <https://github.com/davepacheco/jsstyle/issues>.
See <https://github.com/joyent/jsstyle> for details on config options.
Report bugs to <https://github.com/joyent/jsstyle/issues>.
Options:
-h print this help and exit
@ -672,12 +672,12 @@ line: while (<$filehandle>) {
if (/^\s*\(void\)[^ ]/) {
err("missing space after (void) cast");
}
if (/\S\{/ && !/({|\(){/ &&
if (/\S\{/ && !/(\{|\()\{/ &&
# Allow a brace in a regex quantifier.
!/\/.*?\{\d+,?\d*\}.*?\//) {
err("missing space before left brace");
}
if ($in_function && /^\s+{/ &&
if ($in_function && /^\s+\{/ &&
($prev =~ /\)\s*$/ || $prev =~ /\bstruct\s+\w+$/)) {
err("left brace starting a line");
}
@ -790,8 +790,8 @@ process_indent($)
# skip over enumerations, array definitions, initializers, etc.
if ($cont_off <= 0 && !/^\s*$special/ &&
(/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*)){/ ||
(/^\s*{/ && $prev =~ /=\s*(?:\/\*.*\*\/\s*)*$/))) {
(/(?:(?:\b(?:enum|struct|union)\s*[^\{]*)|(?:\s+=\s*))\{/ ||
(/^\s*\{/ && $prev =~ /=\s*(?:\/\*.*\*\/\s*)*$/))) {
$cont_in = 0;
$cont_off = tr/{/{/ - tr/}/}/;
return;
@ -814,14 +814,14 @@ process_indent($)
return if (/^\s*\}?$/);
return if (/^\s*\}?\s*else\s*\{?$/);
return if (/^\s*do\s*\{?$/);
return if (/{$/);
return if (/\{$/);
return if (/}[,;]?$/);
# Allow macros on their own lines
return if (/^\s*[A-Z_][A-Z_0-9]*$/);
# cases we don't deal with, generally non-kosher
if (/{/) {
if (/\{/) {
err("stuff after {");
return;
}
@ -935,7 +935,7 @@ process_indent($)
$cont_in = 0;
last;
}
if ($rest =~ /^\s*special/) {
if ($rest =~ /^\s*$special/) {
err("if/for/while/switch not started ".
"on its own line");
}

Loading…
Cancel
Save