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 upStarting lines with slashes #111
Comments
This comment has been minimized.
This comment has been minimized.
mattdesl
commented
Apr 16, 2015
|
Personally I feel the following should be disallowed at the beginning of a
They almost always appear in one-liners and clever shorthand (as in your example) that would be better suited inside an Whereas Two eslint issues that seem to be holding some of these things back: |
This comment has been minimized.
This comment has been minimized.
|
Not sure if it's currently disallowed, but I sometimes like to do: function (arg1, arg2, arg3) {
return 'https://'
+ arg1
+ '/somethingverylongthatdoesntfitononeline'
+ arg2
+ '/'
+ arg3
}alternatively it could be written as: function (arg1, arg2, arg3) {
let ret = 'https://'
ret += arg1
ret += '/somethingverylongthatdoesntfitononeline'
ret += arg2
ret += '/'
ret += arg3
return ret
}I feel the second one is a bit clunkier, but don't feel strongly about it. |
This comment has been minimized.
This comment has been minimized.
mattdesl
commented
Apr 16, 2015
|
This is all about starting statements with ASI-breaking characters, so both of your examples should be fine. The wording should be more explicit as pointed out here: |
This comment has been minimized.
This comment has been minimized.
|
While, it would be nice to throw an error on these less-common ASI-breaking cases, I don't want to add additional checks beyond what Once eslint supports the rules we need, I'm happy to enable them to make this catch more of these edge cases. In the meantime, |
feross
closed this
Apr 21, 2015
This comment has been minimized.
This comment has been minimized.
|
@feross I know this issue needs to be fixed upstream. But maybe we can keep the issue open until then? Closing this gives the impression its fixed IMHO. |
feross
reopened this
May 3, 2015
feross
added
bug
blocked
labels
May 13, 2015
This comment has been minimized.
This comment has been minimized.
|
Okay, so there's been progress on this front! As @mattdesl originally suggested, the most troublesome operators var foo = function () {}
var bar = 'baz'
/ bar(')/.test(/' / + bar) && foo(bar)I also enabled the new no-unexpected-multiline rule, which attempts to ensure that "two unrelated consecutive lines are not accidentally interpreted as a single expression". This rule also catches the above error. If you find additional gotchas, please file an eslint issue. I think this issue can finally be closed. |
ausi commentedApr 11, 2015
The readme says starting a line with
(or[is the only gotcha with omitting semicolons, but what about starting lines with/e.g. with a regular expression? The following code breaks:standarddetects the error and writesUnexpected token ., but there are cases wherestandardisn’t able to detect such errors, e.g.:standarddoesn’t find an error but the code breaks withundefined is not a function.Omitting semicolons would be nice, but how can I make sure I’m not falling into such ASI edge cases?