Skip to content

Commit

Permalink
Merge remote-tracking branch 'metaodi/option-for-anon-functions'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Pacheco committed Dec 13, 2013
2 parents cf9c12c + 5e96dad commit 07d4f68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -67,6 +67,9 @@ configurability.
blank-after-open-comment
Boolean option, set to 0 to disable the
"missing blank after open comment" check. `/* */`
no-blank-for-anon-function
Boolean option, set to 1 to allow anonymous
functions without blank before paren. `function() { ... }`
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
Expand Down
11 changes: 9 additions & 2 deletions jsstyle
Expand Up @@ -109,6 +109,7 @@ my %config = (
"literal-string-quote" => "single", # 'single' or 'double'
"blank-after-start-comment" => 1,
"blank-after-open-comment" => 1,
"no-blank-for-anon-function" => 0,
"continuation-at-front" => 0,
"leading-right-paren-ok" => 0,
"strict-indent" => 0
Expand Down Expand Up @@ -144,7 +145,8 @@ sub add_config_var ($$) {
$name eq "whitespace-after-left-paren-ok" ||
$name eq "strict-indent" ||
$name eq "blank-after-open-comment" ||
$name eq "blank-after-start-comment") {
$name eq "blank-after-start-comment" ||
$name eq "no-blank-for-anon-function") {

if ($value != 1 && $value != 0) {
die "$scope: invalid '$name': don't give a value";
Expand Down Expand Up @@ -606,7 +608,12 @@ line: while (<$filehandle>) {
}
# 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)\(/) {
if (!$config{"no-blank-for-anon-function"} && /(?<!\.)\bfunction\(/) {
err("missing space between 'function' and paren");
} elsif ($config{"no-blank-for-anon-function"} && /(?<!\.)\bfunction\s+\(/) {
err("space between 'function' and paren");
}
if (/(?<!\.)\b(delete|typeof|instanceof|throw|with|catch|new|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,}/) {
Expand Down

0 comments on commit 07d4f68

Please sign in to comment.