-
Notifications
You must be signed in to change notification settings - Fork 30k
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
tools: enable (sensible) additional eslint rules #16243
Conversation
@@ -1149,3 +1151,4 @@ if (typeof Symbol !== 'undefined') { | |||
} | |||
|
|||
assert.doesNotThrow(() => util.inspect(process)); | |||
/* eslint-enable accessor-pairs */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, but this line seems not needed since there is no code left for linting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was my thinking but I've noticed a bunch of our test files do this so I just followed the convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, maybe this is some over-caution for possible future code addition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. If someone does know, I would love to know the reason. Or maybe we're all just following the lead of the first person that did this... 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main reason is to try to limit the deactivation for any rule to the minimum required lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in many tests such enabling comments are inserted in the middle of the code. But as the last line, they may be a bit confusing. However, they can have the same role as trailing commas in arrays and objects: safety device for future additions.
A memo for a lander: all the commits may need to be squashed before landing to be self-sufficing. |
@@ -26,6 +26,8 @@ const JSStream = process.binding('js_stream').JSStream; | |||
const util = require('util'); | |||
const vm = require('vm'); | |||
|
|||
/* eslint-disable accessor-pairs */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a good idea to comment why:
// this test uses unmatched accessors to try and trip up `inspect`
AFAICT we mark linting changes as |
lib/_stream_readable.js
Outdated
// userland ones. NEVER DO THIS. This is here only because this code needs | ||
// to continue to work with older versions of Node.js that do not include | ||
// the prependListener() method. The goal is to eventually remove this hack. | ||
else if (!emitter._events || !emitter._events[event]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this could be an if
instead of else if
as there is a return
statement in the previous if
body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I'll update this later today.
Funny enough, there's actually a rule I want to introduce that deals with that but it requires changing more files (around 80 total instances, can't recall how many files) so I wanted to keep it for a separate PR in case there was push back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force pushed to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be a case for Code And Learn (nodejs/code-and-learn#72 (comment))
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description
dfc4e66
to
99fe59e
Compare
@@ -128,16 +128,14 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |||
if (isWs) | |||
continue; | |||
lastPos = start = i; | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this spot makes more sense without the change, fwiw
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Fix all instances of no-lonely-if in lib & test and disable accessor-pairs in test-util-inspect. PR-URL: nodejs#16243 Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in 3c0ebf5 Sorry, @Fishrock123 I was already done by the time I saw your note. 😓 |
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Fix all instances of no-lonely-if in lib & test and disable accessor-pairs in test-util-inspect. PR-URL: #16243 Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Fix all instances of no-lonely-if in lib & test and disable accessor-pairs in test-util-inspect. PR-URL: nodejs/node#16243 Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Should this be backported to This should likely come with an update to ESLint |
Enable additional rules that node either already adheres to or it makes sense to do so going forward: for-direction, accessor-pairs, no-lonely-if and symbol-description. Fix all instances of no-lonely-if in lib & test and disable accessor-pairs in test-util-inspect. PR-URL: nodejs/node#16243 Refs: https://eslint.org/docs/rules/for-direction Refs: https://eslint.org/docs/rules/accessor-pairs Refs: https://eslint.org/docs/rules/no-lonely-if Refs: https://eslint.org/docs/rules/symbol-description Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This PR proposes enabling some additional rules that the project either already follows or probably should follow. Here’s the full overview:
no-lonely-if
This one required some fix ups in existing code but IMO it's a good rule to have. Often these end up being a result of refactoring where the maintainer doesn't spot that the inner conditional block can be pulled out into an
else if
. (I personally had this come up on a recent PR.)https://eslint.org/docs/rules/no-lonely-if
for-direction
I don't think this is particularly controversial. If someone tries to write code that does go against this rule they should probably refactor or it'll be hard/impossible to follow in the future.
https://eslint.org/docs/rules/for-direction
accessor-pairs
Again, not something that's an issue currently and if someone does do this, it's very likely an error or they should just go ahead and override.
https://eslint.org/docs/rules/accessor-pairs
symbol-description
This one is only enabled for
lib
since I don't think we particularly care about this fordoc
ortest
. We already follow it but will be good to have for any potential future contributors.https://eslint.org/docs/rules/symbol-description
(Side-note: is this
tools
,build
or something else? Had no clue what to label the commit with.)Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
doc, lib, test, tools