Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Avoid false positives in a regex quantifier #9

Merged
merged 1 commit into from

2 participants

@trentm

Avoid false positives in a regex quantifier: 'comma or semicolon
followed by non-blank' and 'missing space before left brace'.

Also document JSSTYLED comments in readme.

$ cat foo.js 
var FIELD_REGEX = /^[a-zA-Z][\w._-]{2,}$/;
$ ./jsstyle foo.js 
foo.js: 1: comma or semicolon followed by non-blank
foo.js: 1: missing space before left brace
@trentm trentm Avoid false positives in a regex quantifier: 'comma or semicolon
followed by non-blank' and 'missing space before left brace'.

Also document JSSTYLED comments in readme.
623835a
@davepacheco davepacheco merged commit ab8f1fc into from
@trentm
/               # start regex
.*?             # anything
\{\d+,?\d*\}    # a single regex quantifier
.*?             # anything
/               # end regex

actually, that thing's not perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 10, 2012
  1. @trentm

    Avoid false positives in a regex quantifier: 'comma or semicolon

    trentm authored
    followed by non-blank' and 'missing space before left brace'.
    
    Also document JSSTYLED comments in readme.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 2 deletions.
  1. +16 −0 README.md
  2. +6 −2 jsstyle
View
16 README.md
@@ -62,6 +62,22 @@ configurability.
"missing blank after start comment" check.
+## "JSSTYLED"-comments
+
+When you want `jsstyle` to ignore a line, you can use this:
+
+ /* JSSTYLED */
+ ignore = this + line;
+
+Or for a block:
+
+ /* BEGIN JSSTYLED */
+ var here
+ , be
+ , some = funky
+ , style
+ /* END JSSTYLED */
+
## License
View
8 jsstyle
@@ -561,7 +561,9 @@ line: while (<$filehandle>) {
err("missing space around assignment operator");
}
}
- if (/[,;]\S/ && !/\bfor \(;;\)/) {
+ if (/[,;]\S/ && !/\bfor \(;;\)/ &&
+ # Allow a comma in a regex quantifier.
+ !/\/.*?\{\d+,?\d*\}.*?\//) {
err("comma or semicolon followed by non-blank");
}
# allow "for" statements to have empty "while" clauses
@@ -620,7 +622,9 @@ line: while (<$filehandle>) {
if (/^\s*\(void\)[^ ]/) {
err("missing space after (void) cast");
}
- if (/\S{/ && !/({|\(){/) {
+ if (/\S{/ && !/({|\(){/ &&
+ # Allow a brace in a regex quantifier.
+ !/\/.*?\{\d+,?\d*\}.*?\//) {
err("missing space before left brace");
}
if ($in_function && /^\s+{/ &&
Something went wrong with that request. Please try again.