codelinter [options] [dir]
options:可选配置,参考codelinter命令行配置。
dir:待检查的工程根目录,为可选参数,如不指定,默认为当前上下文目录。
[
{
"filePath": "D:\\projects\\DemoApplication\\entry\\src\\main\\module.json5",
"messages": [
{
"line": 23,
"column": 27,
"severity": "suggestion",
"message": "For faster app startup, keep the startup icon size within 256 x 256 pixels.",
"rule": "@performance/start-window-icon-check"
}
]
},
{
"filePath": "D:\\projects\\DemoApplication\\entry\\src\\main\\ets\\pages\\StackDemo.ets",
"messages": [
{
"line": 75,
"column": 13,
"severity": "warn",
"message": "For performance purposes, set keyGenerator for ForEach.",
"rule": "@performance/foreach-args-check"
}
]
}
] 字段名 | 说明 |
|---|---|
filePath | 代码文件路径 |
messages | 一个数组,每个元素对应检查到的一个问题 |
line | 问题所在代码行数 |
column | 问题所在代码列数 |
severity | 问题严重程度 |
message | 问题描述 |
rule | 问题对应的规则 |
使用命令行执行codelinter,然后把codelinter的结果传给sonar,使用--output/-o的方式将检查结果写入指定的文件,然后外部模块再从这个文件里边去读,可参考codelinter指南的--output/-o <filepath>指令说明。
可使用--format/-f选项指定检查结果文件格式,目前支持default/json/xml/html四种格式。其中,json/html格式输出与ESlint对应格式输出表现一致,如果codelinter生成的检查结果文件的格式与sonar或其他外部模块期望的导入格式不匹配,需要自己写如下脚本进行格式转换: