eslint

How to debug during development of ESLint rules


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.


Solution

  • 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.