Sonarqube:行超出范围,因为与主文件合并后文件缩小 [英] Sonarqube: line out of range since file shrinks after merge with master

查看:227
本文介绍了Sonarqube:行超出范围,因为与主文件合并后文件缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主计算机上有一个 fileA (假设它包含1000行)

There is a fileA on master (say it consists of 1000 lines)

我们在 feature_branch 上,其中 fileA 的长度为1050行。

We are on feature_branch, where fileA has length of say 1050 lines.

在我们的CI管道上,我们正在运行 coverage (这是一个Python项目),它产生的 coverage.xml ,用作SQ的cov输入。

On our CI pipeline, we are running coverage (it is a Python project) and it produces coverage.xml, to be used as cov input to SQ.

我们的SQ预览阶段如下:

Our SQ preview stage is as follows:

    - git config --global user.name "SonarQube"
    - git config --global user.email "sonarqube@somedomain.com"
    - git checkout origin/master
    - git merge $CI_BUILD_REF --no-commit --no-ff
    - sonar-scanner -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.login=$SONARQUBE_TOKEN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
  except:
   - master@mainprojectnamespace

问题如下:

之后合并后,文件A 最终(再次)有1000行

AFTER the merge, fileA ends up having (again) 1000 lines

但是承保范围在合并之前(在以前的工作中)运行之前因此它包含了行数大于1000的结果(这是合并后 fileA 的长度)

HOWEVER, coverage was run BEFORE the merge (in a previous job) so it includes results for lines > 1000 (which is fileA's length after the merge)

我相信)以下错误:

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Line 1040 is out of range in the file path/to/fileA.py (lines: 1000)

怎么办

推荐答案

SonarPython像所有导入覆盖率报告的代码分析器一样,要求被分析的源代码与用于生成覆盖率报告的那个。
首先,您应该挑战在运行声纳扫描仪之前合并分支的需求。
而且,如果您确实需要在与master合并的分支上运行声纳扫描仪,则还需要在与master合并的同一分支上运行覆盖率分析。

SonarPython, like all code analyzers that import coverage report, requires that analyzed source code is strictly identical to the one used to generate the coverage report. First, you should challenge the need to merge your branch before running sonar-scanner. And, if you really need to run sonar-scanner on a branch merged with master, you also need to run the coverage analysis on the same branch merged with master.

这篇关于Sonarqube:行超出范围,因为与主文件合并后文件缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆