简体   繁体   English

在开发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. 我有C#背景,因此在Visual Studio中按F5并具有出色的调试体验会损坏它。

I would like to get into OSS and as I use ESLint a lot thought I'd try to give back. 我想进入OSS,当我使用ESLint时,以为我会尽力回馈。

I've followed http://eslint.org/docs/developer-guide/development environment successfully but am now stuck. 我已经成功地遵循了http://eslint.org/docs/developer-guide/development环境,但现在陷入困境。

How do I run a rule through a debugger so I can set a breakpoint and inspect the AST, context etc? 如何通过调试器运行规则,以便设置断点并检查AST,上下文等?

I presume lots of console.log statements aren't the way forward. 我认为很多console.log语句都console.log

You have a lot of options for debugging NodeJS applications. 您有很多调试NodeJS应用程序的选项。 Some that come to mind are Visual Studio Code, WebStorm, Visual Studio + NodeJS Tools, IronNode, Node Inspector. 我想到的一些是Visual Studio代码,WebStorm,Visual Studio + NodeJS工具,IronNode,节点检查器。 All of them will allow the same workflow that you are used to, pressing F5 to start the process and attach to it. 所有这些都将允许您使用与以前相同的工作流程,请按F5键开始该过程并将其附加。 But with NodeJS, most of them would require some configuration. 但是,使用NodeJS时,大多数都需要一些配置。 Specifically to ESLint, debugging unittests is a bit problematic, since ESLint provides a wrapper around Mocha syntax to DRY unittests. 特别是对ESLint而言,调试单元测试有点麻烦,因为ESLint提供了围绕Mocha语法的包装器来对DRY单元测试进行包装。 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. 最好的选择是设置调试器以在单个文件上运行mocha,并在规则代码中设置断点,而不是单元测试本身,因为单元测试只是对象数组,因此不能在其中添加断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM