如何在Angular 2应用程序中使用codelyzer?

terry Angular 141

所有企业应用程序都会遵循一组编码惯例和准则,以更好的方式维护代码。Codelyzer是一个开源工具,用于运行和检查是否遵循了预定义的编码准则。Codelyzer仅对Angular和TypeScript项目进行静态代码分析。

Codelyzer运行在tslint的顶部,其编码约定通常在tslint.json文件中定义。Codelyzer可以直接通过Angularcli或npm运行。像Visual Studio Code和Atom这样的编辑器也支持codelyzer,只需要通过做一个基本的设置就能实现。

要在Visual Studio代码中设置codelyzer,我们可以在文件 – >选项 – >用户设置中添加tslint规则的路径。

{

    "tslint.rulesDirectory": "./node_modules/codelyzer",

    "typescript.tsdk": "node_modules/typescript/lib"

}

从cli中运行的代码:ng lint。 

从npm中运行的代码: npm run lint

扩展阅读:

  1. https://github.com/mgechev/codelyzer
  2. https://www.youtube.com/watch?v=bci-Z6nURgE

  • 暂无回复内容