Permalink
Browse files

This adds the options: continuation-at-front, right-paren-ok, fixes s…

…paced indents and allows things like VM.delete().

continuation-at-front allows:

    if (... &&
        ...) {

to be written as:

    if (...
        && ...) {

instead.  It does this for ||, && and + generating a warning if you do the other way.

right-paren-ok allows:

     callFunction(...,
         function() {
             ...
         }
     );

which without this option errors as the line starts with a ).
  • Loading branch information...
1 parent ab8f1fc commit 1e31a026b78f1e4a78135fa95d1393c53a796f15 @joshwilsdon joshwilsdon committed Feb 15, 2012
Showing with 20 additions and 6 deletions.
  1. +20 −6 jsstyle
View
@@ -64,11 +64,11 @@ Report bugs to <https://github.com/davepacheco/jsstyle/issues>.
Options:
-h print this help and exit
-v verbose
-
+
-c check continuation indentation inside functions
-t specify tab width for line length calculation
-C don't check anything in header block comments
-
+
-f PATH
path to a jsstyle config file
-o OPTION1,OPTION2
@@ -107,6 +107,8 @@ my %config = (
"unparenthesized-return" => 1,
"literal-string-quote" => "single", # 'single' or 'double'
"blank-after-start-comment" => 1,
+ "continuation-at-front" => 0,
+ "right-paren-ok" => 0
);
sub add_config_var ($$) {
my ($scope, $str) = @_;
@@ -128,7 +130,10 @@ sub add_config_var ($$) {
} elsif ($name eq "doxygen" || # boolean vars
$name eq "splint" ||
$name eq "unparenthesized-return" ||
+ $name eq "continuation-at-front" ||
+ $name eq "right-paren-ok" ||
$name eq "blank-after-start-comment") {
+
if ($value != 1 && $value != 0) {
die "$scope: invalid '$name': don't give a value";
}
@@ -483,7 +488,10 @@ line: while (<$filehandle>) {
my $indent = $1;
if (length($indent) < $config{"indent"}) {
err("indent of " . length($indent) .
- " space(s) instead of " . $config{'indent'});
+ " space(s) instead of " . $config{"indent"});
+ } elsif (length($indent) % $config{"indent"} != 0) {
+ err("indent is " . length($indent) .
+ " not a multiple of " . $config{'indent'} . " spaces");
}
}
if (/^\t+ [^ \t\*]/ || /^\t+ \S/ || /^\t+ \S/) {
@@ -570,13 +578,15 @@ line: while (<$filehandle>) {
if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
err("comma or semicolon preceded by blank");
}
- if (/^\s*(&&|\|\|)/) {
+ if (!$config{"continuation-at-front"} && /^\s*(&&|\|\|)/) {
err("improper boolean continuation");
+ } elsif ($config{"continuation-at-front"} && /(&&|\|\||\+)$/) {
+ err("improper continuation");
}
if (/\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
err("more than one space around boolean operator");
}
- if (/\b(delete|typeof|instanceOf|throw|with|catch|new|function|in|for|if|while|switch|return|case)\(/) {
+ if (/\s(delete|typeof|instanceOf|throw|with|catch|new|function|in|for|if|while|switch|return|case)\(/) {
err("missing space between keyword and paren");
}
if (/(\b(catch|for|if|with|while|switch|return)\b.*){2,}/) {
@@ -617,7 +627,11 @@ line: while (<$filehandle>) {
}
# allow "for" statements to have empty "continue" clauses
if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/) {
- err("whitespace before right paren");
+ if ($config{"right-paren-ok"} && /^\s+\)/) {
+ # this is allowed
+ } else {
+ err("whitespace before right paren");
+ }
}
if (/^\s*\(void\)[^ ]/) {
err("missing space after (void) cast");

0 comments on commit 1e31a02

Please sign in to comment.