Android与Jetpack Compose中reviewdog配置及相关问题咨询
Android + Jetpack Compose 中 Reviewdog 配置疑问解答
以下是你的GitHub Actions配置代码:
name: reviewdog on: [ pull_request ] jobs: ktlint: name: Ktlint Check Code Quality runs-on: ubuntu-latest steps: - name: Clone repo uses: actions/checkout@main with: fetch-depth: 1 - name: ktlint uses: ScaCap/action-ktlint@master with: github_token: ${{ secrets.github_token }} reporter: github-pr-review android: true fail_on_error: true level: warning detekt: name: Check Code Quality runs-on: ubuntu-latest steps: - name: Clone repo uses: actions/checkout@v2 with: fetch-depth: 1 ref: ${{ github.head_ref }} - name: detekt uses: alaegin/Detekt-Action@v1.22.0 with: github_token: ${{ secrets.github_token }} detekt_config: detekt-config.yml # Change config path
执行结果如下:
182 kotlin files were analyzed. Complexity Report: - 11,105 lines of code (loc) - 9,579 source lines of code (sloc) - 6,240 logical lines of code (lloc) - 223 comment lines of code (cloc) - 669 cyclomatic complexity (mcc) - 247 cognitive complexity - 0 number of total code smells - 2% comment source ratio - 107 mcc per 1,000 lloc - 0 code smells per 1,000 lloc Project Statistics: - number of properties: 794 - number of functions: 414 - number of classes: 156 - number of packages: 54 - number of kt files: 182
疑问解答
1. 0个代码异味是否存在问题?
是,大概率存在配置异常,导致Detekt未启用任何代码规则检查。常见原因包括:
- 指定的
detekt-config.yml文件不存在,此时Detekt会使用空配置(无规则生效) - 配置文件中未启用任何代码异味检查规则,或所有规则被设为禁用状态
- 扫描范围未覆盖业务代码目录,比如未指定
app/src/main/java这类核心代码路径
2. detekt-config.yml 是由reviewdog生成还是需要自行创建?
detekt-config.yml需要你自行创建,它是Detekt的规则配置文件,与reviewdog无关:
- 可以基于Detekt官方默认配置模板生成基础文件,再根据项目需求调整规则的启用状态、阈值等
- 若不指定该文件,Detekt会使用内置默认规则;但如果Action中指定了不存在的配置文件,就会出现无规则运行的情况
内容的提问来源于stack exchange,提问作者c-an
相关产品推荐
相关产品推荐

