Reputation: 1655
I have a C# background so am spoilt by pressing F5 in Visual Studio and having a fantastic debug experience.
I would like to get into OSS and as I use ESLint a lot thought I'd try to give back.
I've followed http://eslint.org/docs/developer-guide/development environment successfully but am now stuck.
How do I run a rule through a debugger so I can set a breakpoint and inspect the AST, context etc?
I presume lots of console.log
statements aren't the way forward.
Upvotes: 7
Views: 8906
Reputation: 2942
I create my custom rules with eslint-plugin-rulesdir
plugin.
Once in vscode i can debug my rules with simple console.log
Example of rules
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Example,
category: 'Best Practices',
recommended: true,
},
schema: [],
},
create(context) {
return {
TryStatement(node) {
console.log('DEBUG 22', node.block.body);
},
};
},
};
Then you can inspect your log with following step
Upvotes: -1
Reputation: 4501
With webstorm you can:
node_modules/eslint/bin/eslint.js file-your-want-to-lint.ts --fix
custom rule code your want to debug add debugger
keyword
run your new configuration with debug button(not a just run)
Upvotes: 0
Reputation: 11266
You have a lot of options for debugging NodeJS applications. Some that come to mind are Visual Studio Code, WebStorm, Visual Studio + NodeJS Tools, IronNode, Node Inspector. All of them will allow the same workflow that you are used to, pressing F5 to start the process and attach to it. But with NodeJS, most of them would require some configuration. Specifically to ESLint, debugging unittests is a bit problematic, since ESLint provides a wrapper around Mocha syntax to DRY unittests. Your best bet is setup your debugger to run mocha on a single file, and setup breakpoint in the rule's code, instead of unittests itself, since unittests are just arrays of objects, you can't add a breakpoint there.
Upvotes: 4