Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Config options: "unparenthesized-return" (default 1, i.e on),

"literal-string-quote" ('single', 'double' or 'ignore'), and
"blank-after-start-comment" (default 1).
  • Loading branch information...
commit fa6d5a345257e3500487e286499691c0ad03a861 1 parent ec362e5
Trent Mick trentm authored

Showing 1 changed file with 30 additions and 9 deletions. Show diff stats Hide diff stats

  1. +30 9 jsstyle
39 jsstyle
@@ -90,16 +90,21 @@ if (! defined($opts{'t'})) {
90 90
91 91 # Load config
92 92 my %config = (
93   - indent => "tab"
  93 + indent => "tab",
  94 + doxygen => 0, # doxygen comments: /** ... */
  95 + splint => 0, # splint comments. Needed?
  96 + "unparenthesized-return" => 1,
  97 + "literal-string-quote" => "single", # 'single', 'double' or 'ignore'
  98 + "blank-after-start-comment" => 1,
94 99 );
95 100 sub add_config_var ($$) {
96 101 my ($scope, $str) = @_;
97 102
98   - if ($str !~ /^(\w+)(?:\s*=\s*(.*?))?$/) {
  103 + if ($str !~ /^([\w-]+)(?:\s*=\s*(.*?))?$/) {
99 104 die "$scope: invalid option: '$str'";
100 105 }
101 106 my $name = $1;
102   - my $value = $2 || 1;
  107 + my $value = ($2 eq '' ? 1 : $2);
103 108 #print "scope: '$scope', str: '$str', name: '$name', value: '$value'\n";
104 109
105 110 # Validate config var.
@@ -109,10 +114,18 @@ sub add_config_var ($$) {
109 114 die "$scope: invalid '$name': must be a number (of ".
110 115 "spaces) or 'tab'";
111 116 }
112   - } elsif ($name eq "doxygen" || $name eq "splint") {
113   - if ($value != 1) {
  117 + } elsif ($name eq "doxygen" || # boolean vars
  118 + $name eq "splint" ||
  119 + $name eq "unparenthesized-return" ||
  120 + $name eq "blank-after-start-comment") {
  121 + if ($value != 1 && $value != 0) {
114 122 die "$scope: invalid '$name': don't give a value";
115 123 }
  124 + } elsif ($name eq "literal-string-quote") {
  125 + if ($value !~ /single|double|ignore/) {
  126 + die "$scope: invalid '$name': must be 'single' ".
  127 + "or 'double'";
  128 + }
116 129 } else {
117 130 die "$scope: unknown config var: $name";
118 131 }
@@ -481,7 +494,7 @@ line: while (<$filehandle>) {
481 494 !(/$lint_re/ || ($config{"splint"} && /$splint_re/))) {
482 495 err("missing blank before close comment");
483 496 }
484   - if (/\/\/\S/) { # C++ comments
  497 + if ($config{"blank-after-start-comment"} && /\/\/\S/) { # C++ comments
485 498 err("missing blank after start comment");
486 499 }
487 500 # check for unterminated single line comments, but allow them when
@@ -508,8 +521,15 @@ line: while (<$filehandle>) {
508 521 s/\s*$//;
509 522
510 523 # following checks do not apply to text in comments.
511   - if (/"/) {
512   - err("literal string using double-quote instead of single");
  524 + my $quote = $config{"literal-string-quote"};
  525 + if ($quote eq "single") {
  526 + if (/"/) {
  527 + err("literal string using double-quote instead of single");
  528 + }
  529 + } elsif ($quote eq "double") {
  530 + if (/'/) {
  531 + err("literal string using single-quote instead of double");
  532 + }
513 533 }
514 534
515 535 if (/[^=!<>\s][!<>=]=/ || /[^<>!=][!<>=]==?[^\s,=]/ ||
@@ -569,7 +589,8 @@ line: while (<$filehandle>) {
569 589 $_ = $s;
570 590 }
571 591
572   - if (/^\s*return\W[^;]*;/ && !/^\s*return\s*\(.*\);/) {
  592 + if ($config{"unparenthesized-return"} &&
  593 + /^\s*return\W[^;]*;/ && !/^\s*return\s*\(.*\);/) {
573 594 err("unparenthesized return expression");
574 595 }
575 596 if (/\btypeof\b/ && !/\btypeof\s*\(.*\)/) {

0 comments on commit fa6d5a3

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