Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #10 from joshwilsdon/master

Add some accommodation for more style options
  • Loading branch information...
commit 485da030eb3536394253c065b6afa4cf32d76218 2 parents ab8f1fc + 036ed17
David Pacheco authored February 17, 2012

Showing 2 changed files with 31 additions and 7 deletions. Show diff stats Hide diff stats

  1. 7  README.md
  2. 31  jsstyle
7  README.md
Source Rendered
@@ -53,6 +53,8 @@ configurability.
53 53
                             This is legacy. Does anyone use this?
54 54
     indent=<NUM|tab>        An integer number of spaces for indentation, or
55 55
                             'tab' for tab indentation (the default).
  56
+    strict-indent           Boolean option, set to 1 to force indents of spaces
  57
+                            to be a multiple of indent parameter.
56 58
     literal-string-quote    'single' (the default) or 'double'. Specifies
57 59
                             the preferred quote character for literal strings.
58 60
     unparenthesized-return  Boolean option, set to 0 to disable the
@@ -60,7 +62,10 @@ configurability.
60 62
     blank-after-start-comment
61 63
                             Boolean option, set to 0 to disable the
62 64
                             "missing blank after start comment" check.
63  
-
  65
+    continuation-at-front   Boolean option, set to 1 to force continations
  66
+                            to be at the beginning rather than end of line.
  67
+    leading-right-paren-ok  Boolean option, set to 1 to allow ) to start a
  68
+                            line.
64 69
 
65 70
 ## "JSSTYLED"-comments
66 71
 
31  jsstyle
@@ -64,11 +64,11 @@ Report bugs to <https://github.com/davepacheco/jsstyle/issues>.
64 64
 Options:
65 65
 	-h 	print this help and exit
66 66
 	-v	verbose
67  
-	
  67
+
68 68
 	-c	check continuation indentation inside functions
69 69
 	-t	specify tab width for line length calculation
70 70
 	-C	don't check anything in header block comments
71  
-	
  71
+
72 72
 	-f PATH
73 73
 		path to a jsstyle config file
74 74
 	-o OPTION1,OPTION2
@@ -107,6 +107,9 @@ my %config = (
107 107
 	"unparenthesized-return" => 1,
108 108
 	"literal-string-quote" => "single",  # 'single' or 'double'
109 109
 	"blank-after-start-comment" => 1,
  110
+	"continuation-at-front" => 0,
  111
+	"leading-right-paren-ok" => 0,
  112
+	"strict-indent" => 0
110 113
 );
111 114
 sub add_config_var ($$) {
112 115
 	my ($scope, $str) = @_;
@@ -128,7 +131,11 @@ sub add_config_var ($$) {
128 131
 	} elsif ($name eq "doxygen" ||   # boolean vars
129 132
 		 $name eq "splint" ||
130 133
 		 $name eq "unparenthesized-return" ||
  134
+		 $name eq "continuation-at-front" ||
  135
+		 $name eq "leading-right-paren-ok" ||
  136
+		 $name eq "strict-indent" ||
131 137
 		 $name eq "blank-after-start-comment") {
  138
+
132 139
 		if ($value != 1 && $value != 0) {
133 140
 			die "$scope: invalid '$name': don't give a value";
134 141
 		}
@@ -483,7 +490,11 @@ line: while (<$filehandle>) {
483 490
 		my $indent = $1;
484 491
 		if (length($indent) < $config{"indent"}) {
485 492
 			err("indent of " . length($indent) .
486  
-				" space(s) instead of " . $config{'indent'});
  493
+				" space(s) instead of " . $config{"indent"});
  494
+		} elsif ($config{"strict-indent"} &&
  495
+			length($indent) % $config{"indent"} != 0) {
  496
+			err("indent is " . length($indent) .
  497
+				" not a multiple of " . $config{'indent'} . " spaces");
487 498
 		}
488 499
 	}
489 500
 	if (/^\t+ [^ \t\*]/ || /^\t+  \S/ || /^\t+   \S/) {
@@ -570,13 +581,17 @@ line: while (<$filehandle>) {
570 581
 	if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
571 582
 		err("comma or semicolon preceded by blank");
572 583
 	}
573  
-	if (/^\s*(&&|\|\|)/) {
  584
+	if (!$config{"continuation-at-front"} && /^\s*(&&|\|\|)/) {
574 585
 		err("improper boolean continuation");
  586
+	} elsif ($config{"continuation-at-front"} && /(&&|\|\||\+)$/) {
  587
+		err("improper continuation");
575 588
 	}
576 589
 	if (/\S   *(&&|\|\|)/ || /(&&|\|\|)   *\S/) {
577 590
 		err("more than one space around boolean operator");
578 591
 	}
579  
-	if (/\b(delete|typeof|instanceOf|throw|with|catch|new|function|in|for|if|while|switch|return|case)\(/) {
  592
+	# We allow methods which look like obj.delete() but not keywords without
  593
+	# spaces ala: delete(obj)
  594
+	if (/(?<!\.)\b(delete|typeof|instanceof|throw|with|catch|new|function|in|for|if|while|switch|return|case)\(/) {
580 595
 		err("missing space between keyword and paren");
581 596
 	}
582 597
 	if (/(\b(catch|for|if|with|while|switch|return)\b.*){2,}/) {
@@ -617,7 +632,11 @@ line: while (<$filehandle>) {
617 632
 	}
618 633
 	# allow "for" statements to have empty "continue" clauses
619 634
 	if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/) {
620  
-		err("whitespace before right paren");
  635
+		if ($config{"leading-right-paren-ok"} && /^\s+\)/) {
  636
+			# this is allowed
  637
+		} else {
  638
+			err("whitespace before right paren");
  639
+		}
621 640
 	}
622 641
 	if (/^\s*\(void\)[^ ]/) {
623 642
 		err("missing space after (void) cast");

0 notes on commit 485da03

Please sign in to comment.
Something went wrong with that request. Please try again.