利用TypeScript编译器修复有错误的Node.js代码片段
Using the TypeScript compiler to fix erroneous Node.js snippets
AI总结:
针对在线Node.js代码片段错误多、复用难的问题,提出结合TypeScript编译器、内置修复、定制修复及删错行的NCC方法,能检测更多错误且修复效率更高,可大幅降低NPM文档代码错误率。
摘要:
大多数在线代码片段无法运行,这意味着想要复用在线来源代码的开发者必须手动查找并修复错误。我们提出了一种自动评估并纠正Node.js代码片段中错误的方法:Node Code Correction(NCC,Node代码纠正工具)。NCC利用TypeScript编译器生成错误的能力,通过结合TypeScript内置的代码修复功能、我们自主开发的针对性修复方案以及错误行删除策略来提供代码修正指引。与使用静态代码检查工具(linters)的现有方法相比,我们的研究结果表明,NCC能够在每个代码片段中检测到更多数量的错误和更多的错误类型,并且在修复代码片段方面效率更高。我们发现NPM文档中的代码片段有73.7%存在错误;在使用NCC的修正功能后,这一比例降至25.1%。我们的评估证实,使用TypeScript编译器来指导代码修正,是助力复用在线来源代码片段的一种颇具前景的策略。
英文摘要:
Most online code snippets do not run. This means that developers looking to reuse code from online sources must manually find and fix errors. We present an approach for automatically evaluating and correcting errors in Node.js code snippets: Node Code Correction (NCC). NCC leverages the ability of the TypeScript compiler to generate errors and inform code corrections through the combination of TypeScript's built-in codefixes, our own targeted fixes, and deletion of erroneous lines. Compared to existing approaches using linters, our findings suggest that NCC is capable of detecting a larger number of errors per snippet and more error types, and it is more efficient at fixing snippets. We find that 73.7% of the code snippets in NPM documentation have errors; with the use of NCC's corrections, this number was reduced to 25.1%. Our evaluation confirms that the use of the TypeScript compiler to inform code corrections is a promising strategy to aid in the reuse of code snippets from online sources.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。