Browse files

Add boolean options leading-comma-ok, uncuddled-else-ok, whitespace-a…

…fter-left-paren-ok
  • Loading branch information...
1 parent 485da03 commit 1d971bd9df915a554572cae95a0001752b50e1d4 @orlandov orlandov committed Feb 17, 2012
Showing with 22 additions and 4 deletions.
  1. +10 −0 README.md
  2. +12 −4 jsstyle
View
10 README.md
@@ -67,6 +67,16 @@ configurability.
leading-right-paren-ok Boolean option, set to 1 to allow ) to start a
line.
+ whitespace-after-left-paren-ok
+ Boolean option, allow whitespace after a (
+ character.
+
+ leading-comma-ok Boolean option to allow lines to begin with commas
+ (preceded by whitespace).
+
+ uncuddled-else-ok Boolean option to allow for an else block to begin
+ on a new line.
+
## "JSSTYLED"-comments
When you want `jsstyle` to ignore a line, you can use this:
View
16 jsstyle
@@ -133,6 +133,9 @@ sub add_config_var ($$) {
$name eq "unparenthesized-return" ||
$name eq "continuation-at-front" ||
$name eq "leading-right-paren-ok" ||
+ $name eq "leading-comma-ok" ||
+ $name eq "uncuddled-else-ok" ||
+ $name eq "whitespace-after-left-paren-ok" ||
$name eq "strict-indent" ||
$name eq "blank-after-start-comment") {
@@ -577,9 +580,14 @@ line: while (<$filehandle>) {
!/\/.*?\{\d+,?\d*\}.*?\//) {
err("comma or semicolon followed by non-blank");
}
+ # check for commas preceded by blanks
+ if ((!$config{"leading-comma-ok"} && /^\s*,/) || (!/^\s*,/ && /\s,/)) {
+ err("comma preceded by blank");
+ }
+ # check for semicolons preceded by blanks
# allow "for" statements to have empty "while" clauses
- if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
- err("comma or semicolon preceded by blank");
+ if (/\s;/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
+ err("semicolon preceded by blank");
}
if (!$config{"continuation-at-front"} && /^\s*(&&|\|\|)/) {
err("improper boolean continuation");
@@ -627,7 +635,7 @@ line: while (<$filehandle>) {
if (/\btypeof\b/ && !/\btypeof\s*\(.*\)/) {
err("unparenthesized typeof expression");
}
- if (/\(\s/) {
+ if (!$config{"whitespace-after-left-paren-ok"} && /\(\s/) {
err("whitespace after left paren");
}
# allow "for" statements to have empty "continue" clauses
@@ -673,7 +681,7 @@ line: while (<$filehandle>) {
}
if (/^\s*else\W/) {
- if ($prev =~ /^\s*}$/) {
+ if (!$config{"uncuddled-else-ok"} && $prev =~ /^\s*}$/) {
err_prefix($prev,
"else and right brace should be on same line");
}

0 comments on commit 1d971bd

Please sign in to comment.