-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: custom eslint autofix for inspector-check.js #16646
tools: custom eslint autofix for inspector-check.js #16646
Conversation
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.
See my comment in the other PR re: creating tests for these to verify they're working as expected. Thanks!
fix: (fixer) => { | ||
return fixer.insertTextAfter( | ||
node, | ||
'\n\n common.skipIfInspectorDisabled();' |
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.
What does the node
refer to in this context? I feel like this might be getting inserted in the wrong place.
Also, why the errant space after \n\n
?
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.
You are right. This inserts the correction at the end of the file. Working on inserting it below require('../common')
. Also will fix space after\n\n
.
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.
Made a new commit fixing the same. Please verify. Thanks.
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.
LGTM
This needs a rebase. |
fecdd5f
to
0a80a94
Compare
@BridgeAR Rebased with mater. |
@shobhitchittora Could you run |
I won't outright block this but I'm -1 on landing this. I really don't like the idea of auto fixing these |
7b44bfb
to
e61a79e
Compare
@addaleax I'm getting 68 errors while running |
@nodejs/collaborators PTAL |
e61a79e
to
bf946c0
Compare
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.
A few comments.
var hasInspectorCheck = false; | ||
|
||
function testInspectorUsage(context, node) { | ||
if (utils.isRequired(node, ['inspector'])) { | ||
missingCheckNodes.push(node); | ||
} | ||
|
||
if (utils.isCommonModule(node)) { | ||
commonModuleNodes.push(node); |
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.
Since there is only one required (and only one should be present) using an array here is actually not necessary and a simple assign would be enough as well.
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.
Yup correct. Fixing this.
@@ -11,16 +11,21 @@ const utils = require('./rules-utils.js'); | |||
// Rule Definition | |||
//------------------------------------------------------------------------------ | |||
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' + | |||
'test to be skippped when Node is built \'--without-inspector\'.'; | |||
'test to be skippped when Node is built \'--without-inspector\'.'; |
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: Unrelated change?
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.
Removed.
tools/eslint-rules/rules-utils.js
Outdated
expression.callee && | ||
(expression.callee.name === 'skip' || | ||
expression.callee.property && | ||
expression.callee.property.name === 'skip'); |
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: unrelated change. The same applies to the part above.
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.
removed.
'common.skipIfInspectorDisabled(); require("inspector");', | ||
`require("common"); | ||
common.skipIfInspectorDisabled(); | ||
require("inspector");` |
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.
We normally do not use multiline template strings. It will work in this case but it was very hard for me to even see that it is a template string and not three individual entries. So it would be great to change that to either a single line or +
.
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.
Done
errors: [{ message }], | ||
output: 'require("common");\n' + | ||
'common.skipIfInspectorDisabled();\n' + | ||
'require("inspector");' |
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.
@shobhitchittora is this definitely going to work and will it also insert require("common");
here? Because I do not see this happening in the fixer.
Mini-CI (enough to test this): https://ci.nodejs.org/job/node-test-commit-light/146/ |
|
Ping @shobhitchittora |
@BridgeAR I'm on it. |
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.
Made the said changes.
Same error here -
@starkwang How did you check the diffs for the test runner? |
@shobhitchittora I am not sure what your question is really about. Can you elaborate so someone else might also be able to answer that question? |
@BridgeAR I'm stuck as the test for the rule is failing, throwing -
While running - PS: I tried adding/removing |
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.
Please check the comments and I recommend to rebase. That way you get a better error output. Please also add a new test case that checks code that imported common.
errors: [{ message }], | ||
output: 'require("common");\n' + | ||
'common.skipIfInspectorDisabled();\n' + | ||
'require("inspector");' |
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.
This is very certain not the correct output as common
was not imported in the checked code.
'common.skipIfInspectorDisabled(); require("inspector");', | ||
'require("common");\n' + | ||
'common.skipIfInspectorDisabled();\n' + | ||
'require("inspector");' |
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.
Please either use a single code line (I would do that as in the example above the added one) or indent the code so the concatenated part is deeper indented than the start of the string.
1. Adds fixer method 2. Extends test 3. Fixes merge issue Refs: nodejs#16636
1. Removes extra indentation 2. Removes array to track commomModule AST node. 3. Refactored test Refs: nodejs#16636
4c93df0
to
4afc45d
Compare
Review comments + updates tests to work with fixer Refs: nodejs#16636
@BridgeAR Hope this does it. Please run the CI on this. |
tools/eslint-rules/rules-utils.js
Outdated
var commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/); | ||
module.exports.isCommonModule = function(node) { | ||
return node.callee.name === 'require' && | ||
commonModuleRegExp.test(node.arguments[0].value); |
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.
Here the access to the first argument has to be guarded. In case a node has no arguments, this will trigger an error.
So please add a node.arguments.length !== 0 &&
in the middle.
'common.skipIfInspectorDisabled(); require("inspector");' | ||
'require("common")\n' + | ||
'common.skipIfInspectorDisabled();\n' + | ||
'require("inspector")' |
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.
Can you please indent the last two lines by two spaces? :-)
rules-utils arguments check + spacing in test file Refs: nodejs#16636
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.
LGTM if CI is green
1. Adds fixer method 2. Extends test PR-URL: nodejs#16646 Refs: nodejs#16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in 5156342 🎉 Due to the other rule landing earlier there was a conflict that I resolved while landing. |
1. Adds fixer method 2. Extends test PR-URL: #16646 Refs: #16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1. Adds fixer method 2. Extends test PR-URL: #16646 Refs: #16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1. Adds fixer method 2. Extends test PR-URL: #16646 Refs: #16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1. Adds fixer method 2. Extends test PR-URL: nodejs#16646 Refs: nodejs#16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1. Adds fixer method 2. Extends test PR-URL: #16646 Refs: #16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1. Adds fixer method 2. Extends test PR-URL: #16646 Refs: #16636 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
This adds eslint fixer method for inspector-check.js. When running eslint with
--fix
flag, the fixer will addcommon.skipIfInspectorDisabled();
to the file automatically.Refs : #16636
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passespython ./tools/test.py parallel/test-eslint-inspector-check
Affected core subsystem(s)
Tools