-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint: wrap long lines that include RegExp when possible #14586
Comments
Calling dibs if this hasn't been taken yet ^_^ |
@refack Would this be good way to go about it ? Or did you have a better solution in mind for
to
|
The main motivation is the keep thing as readable as possible. assert.throws(() => url.origin = 'http://foo.bar.com:22',
/TypeError: Cannot set property origin of \[object URL\] which has only a getter$/); assert.throws(
() => url.origin = 'http://foo.bar.com:22',
/TypeError: Cannot set property origin of \[object URL\] which has only a getter$/
); We do end up with a line that 85 chars long, but it's still better than before.
|
@refack We do not advise strings as error arguments here: https://nodejs.org/api/assert.html#assert_assert_throws_block_error_message (see notes in the chapter end). |
That is wrong (although, to be clear, the API is at fault, not you). A string as the second argument will be the message printed if the code does not throw. Avoid it entirely because everyone makes this mistake. It is an unfortunate legacy issue in the API. |
IMO https://github.com/nodejs/node/blob/master/test/parallel/test-whatwg-url-properties.js#L47 could be left as is and removed from the list. If you want to marginally improve it, then the indentation modification option suggested by @refack is the way to go: assert.throws(
() => url.origin = 'http://foo.bar.com:22',
/TypeError: Cannot set property origin of \[object URL\] which has only a getter$/
); You could also consider replacing the regexp with a function, but going that route solely to avoid some line-wrapping seems misguided to me. |
(mixed up IMHO wrapping will be the best, and also if we're touching this I believe the |
@refack
Scnearios where the string can be made into a constant but that would make matters worse as defining the constant would hog more characters than the current state : And when the text is already a constant and exceeds the limit, can't do anything about it, can we?
Yes I'm aware this looks like a long list of complaints but I'm just voicing out my thoughts. |
@adityaanandmc for the first two and last two, IMHO simply wrapping will look nicer: const expected = /^TypeError: "buffer" argument must be a string, Buffer, TypedArray, or DataView$/;
...
{
client: client_unix,
send: '(function(a, a, b) { "use strict"; return a + b + c; })()',
expect: /\bSyntaxError: Duplicate parameter name not allowed in this context/
}, to: const expected =
/^TypeError: "buffer" argument must be a string, Buffer, TypedArray, or DataView$/;
...
{
client: client_unix,
send: '(function(a, a, b) { "use strict"; return a + b + c; })()',
expect:
/\bSyntaxError: Duplicate parameter name not allowed in this context/
}, Same trick can be done for https://github.com/nodejs/node/blob/master/test/parallel/test-v8-serdes.js#L143 even just before the block scope to save two indentation chars (but add a comment why it's there). This issue turns out to be an exercise in creative typography 😉 |
Format commit wrapping lines containing RegEx and exceeding 80 chars. Fixes: nodejs#14586
Format commit wrapping lines containing RegEx and exceeding 80 chars. PR-URL: #14607 Fixes: #14586 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
There are several places in the codebase where lines are longer than 80 characters but could be wrapped.
Possible solutions:
Mitigations:
The text was updated successfully, but these errors were encountered: