Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNever start a line with regular expression literal #728
Comments
dcousens
added
the
question
label
Dec 23, 2016
dcousens
assigned
feross
Dec 23, 2016
This comment has been minimized.
This comment has been minimized.
ifraixedes
commented
Dec 23, 2016
|
I don't understand what you meant. Without semicolon, |
This comment has been minimized.
This comment has been minimized.
|
@ifraixedes I think @academyofzhuang means these rules: Never start a line with (, [, or ` |
This comment has been minimized.
This comment has been minimized.
|
The list is intentionally incomplete. I listed only characters that have I've seen used in actual code, and ignored characters that are usually never used. A more complete list appears later in the rules in the quote from An Open Letter to JavaScript Leaders Regarding Semicolons:
|
feross
closed this
Dec 24, 2016
This comment has been minimized.
This comment has been minimized.
|
@ifraixedes a better solution to your problem: if (/^[A-Z].+/.test(s)) console.log(s)I agree with @feross, this is a non-issue as the only use case I can see, is if you are doing what you were, which is never ideal IMHO. |
This comment has been minimized.
This comment has been minimized.
ifraixedes
commented
Dec 25, 2016
|
@dcousens I think that you ping the wrong person. I have never written something how it was expressed in the question, I prefer forms as the one that you described above. Cheers |
This comment has been minimized.
This comment has been minimized.
|
Apologies @ifraixedes, I meant @academyofzhuang |
This comment has been minimized.
This comment has been minimized.
|
I agreed with you. Using boolean shortcut to save a few key strokes isn't best practice to start with. The reason I brought up the issue is the parsing error message by js engine was cryptic: standard: Use JavaScript Standard Style (http://standardjs.com)
/Users/aoz/academyofzhuang/test/std.js:2:2: Parsing error: Unexpected token ^When I look at the code, it doesn't make any sense. var s = 'About'
/^[A-Z].+/.test(s) && console.log(s) // quick and dirty debugSince I believed, as stated in the project readme
It took me some time to realize a semicolon might be needed. I agree this is a non-issue. To quote the project readme:
Thank you for the detailed explanation and example code! |
academyofzhuang commentedDec 23, 2016
If one start a line with a regular expression, it causes parsing error, too.
Adding a semicolon before regex solved the problem.
Shall we add this exception to the rule.