运行一个脚本,检查项目的代码质量 v0.3.0

2017-09-29 19:33:26 +08:00
 xcatliu

GitHub: https://github.com/xcatliu/cqc


之前做了个工具可以检查源代码行数,代码重复率和圈复杂度。收到很多好评

前帖: https://www.v2ex.com/t/392337

这次版本更新,添加了很多新功能,也可以方便的添加进 git hooks 或者构建程序中啦!

简单介绍

cqc ( Code Quality Checker )是一个代码质量检查工具,可以通过运行一个脚本来获取项目的源代码行数,代码重复率和圈复杂度。目前支持的文件类型有 js, jsx, css, less, scss, sass, styl

# 安装
npm i cqc -g

# 运行
cqc src/**/*.js

# 输出
Number of files:        10
Source lines of code:   647
Duplicate rate:         3.46%
High complexity rate:   0.00%
Max complexity:         10

更新内容

增加或重写了很多选项

允许使用 API 调用

例如:

const CodeQualityChecker = require('cqc');
const codeQualityChecker = new CodeQualityChecker();

// This will return a checkerResult object which include the check result
const cqcResult = codeQualityChecker.check([
    'src/**/*.js',
    'src/**/*.jsx'
], {
    ignorePath: '.gitignore,.eslintignore',
    ignorePattern: 'src/vendor/**/*.js,src/third-party/**/*.js',
    filterPattern: 'src/path/to/filterPattern',

    jscpdMinLines: 5,
    jspcdMinTokens: 70,
    complexityMax: 10,

    disableBase: false,
    disableSloc: false,
    disableJscpd: false,
    disableComplexity: false,

    format: undefined,
    verbose: true,
    thresholdJscpd: 3,
    thresholdComplexity: 10
});

// Calling report function will console.log result like cli did
cqcResult.report({
    format: undefined,
    verbose: true,
    thresholdJscpd: 3,
    thresholdComplexity: 10
});

增加了测试

没有测试真是太难开发了,添加了测试之后增加了很多开发效率,也增加了很大的安全感。 现在的测试覆盖率有 94% 了。

3143 次点击
所在节点    分享创造
8 条回复
GPIO
2017-09-29 19:38:34 +08:00
有计划支持 C、Python 吗?
xcatliu
2017-09-29 19:42:23 +08:00
@GPIO python 目前可以计算出代码重复度,还没有计划做复杂度的检查。
dyxang
2017-09-29 21:41:24 +08:00
小工具






mobi.css 的中文……
xcatliu
2017-09-29 21:51:12 +08:00
@dyxang 是在求中文文档吗?
dyxang
2017-09-29 22:28:16 +08:00
@xcatliu 😣是的
xcatliu
2017-09-29 23:47:54 +08:00
@dyxang 现在的精力实在有限了😢翻译的优先级还是排在很后面的。。。
dyxang
2017-10-01 21:16:16 +08:00
@xcatliu 没事,能有这个就已经很好了😁
这个是对电脑也适配的吧?
xcatliu
2017-10-01 22:55:09 +08:00
@dyxang 嗯,对主流浏览器和 ie10 以上都支持

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/394682

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX