Permalink
Browse files

Add README entries for new options, rename right-parent-ok to leading…

…-right-paren-ok, add strict-indent option fix issue with keyword parens pointed out by trentm.
  • Loading branch information...
1 parent 1e31a02 commit 036ed177189e6c66e83a14ac814908c822559b6c @joshwilsdon joshwilsdon committed Feb 15, 2012
Showing with 16 additions and 6 deletions.
  1. +6 −1 README.md
  2. +10 −5 jsstyle
View
7 README.md
@@ -53,14 +53,19 @@ configurability.
This is legacy. Does anyone use this?
indent=<NUM|tab> An integer number of spaces for indentation, or
'tab' for tab indentation (the default).
+ strict-indent Boolean option, set to 1 to force indents of spaces
+ to be a multiple of indent parameter.
literal-string-quote 'single' (the default) or 'double'. Specifies
the preferred quote character for literal strings.
unparenthesized-return Boolean option, set to 0 to disable the
"unparenthesized return expression" check.
blank-after-start-comment
Boolean option, set to 0 to disable the
"missing blank after start comment" check.
-
+ continuation-at-front Boolean option, set to 1 to force continations
+ to be at the beginning rather than end of line.
+ leading-right-paren-ok Boolean option, set to 1 to allow ) to start a
+ line.
## "JSSTYLED"-comments
View
15 jsstyle
@@ -108,7 +108,8 @@ my %config = (
"literal-string-quote" => "single", # 'single' or 'double'
"blank-after-start-comment" => 1,
"continuation-at-front" => 0,
- "right-paren-ok" => 0
+ "leading-right-paren-ok" => 0,
+ "strict-indent" => 0
);
sub add_config_var ($$) {
my ($scope, $str) = @_;
@@ -131,7 +132,8 @@ sub add_config_var ($$) {
$name eq "splint" ||
$name eq "unparenthesized-return" ||
$name eq "continuation-at-front" ||
- $name eq "right-paren-ok" ||
+ $name eq "leading-right-paren-ok" ||
+ $name eq "strict-indent" ||
$name eq "blank-after-start-comment") {
if ($value != 1 && $value != 0) {
@@ -489,7 +491,8 @@ line: while (<$filehandle>) {
if (length($indent) < $config{"indent"}) {
err("indent of " . length($indent) .
" space(s) instead of " . $config{"indent"});
- } elsif (length($indent) % $config{"indent"} != 0) {
+ } elsif ($config{"strict-indent"} &&
+ length($indent) % $config{"indent"} != 0) {
err("indent is " . length($indent) .
" not a multiple of " . $config{'indent'} . " spaces");
}
@@ -586,7 +589,9 @@ line: while (<$filehandle>) {
if (/\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
err("more than one space around boolean operator");
}
- if (/\s(delete|typeof|instanceOf|throw|with|catch|new|function|in|for|if|while|switch|return|case)\(/) {
+ # We allow methods which look like obj.delete() but not keywords without
+ # spaces ala: delete(obj)
+ if (/(?<!\.)\b(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,}/) {
@@ -627,7 +632,7 @@ line: while (<$filehandle>) {
}
# allow "for" statements to have empty "continue" clauses
if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/) {
- if ($config{"right-paren-ok"} && /^\s+\)/) {
+ if ($config{"leading-right-paren-ok"} && /^\s+\)/) {
# this is allowed
} else {
err("whitespace before right paren");

0 comments on commit 036ed17

Please sign in to comment.