Sonascanner错误“文件中的行超出范围”

2024-10-05 14:32:04 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我正在正常地执行django项目,然后,当我在formulas.py中重构函数名时,我突然从SonarScanner中得到了这个错误(只是,我没有调整sonar.properties和ci.yml文件):

java.lang.IllegalStateException: Line 308 is out of range in the file dietela_quiz/formulas.py (lines: 306)

然后我决定添加更多的空白,使其达到308行,但从那时起,错误一直存在,当我添加更多空白,甚至创建了一个伪函数(以合法地增加文件长度)时,错误模式如下所示:

java.lang.IllegalStateException: Line n+1 is out of range in the file dietela_quiz/formulas.py (lines: n)

其中n是formulas.py中的实际行数

这是我的yml文件:

stages:
  - test
  - sonar-scanner
  - deploy

UnitTest:
  image: python:3.6.5
  stage: test
  before_script:
    - pip install -r requirements.txt
    - python manage.py makemigrations
    - python manage.py migrate
    - python manage.py collectstatic --no-input
    - python manage.py runserver 8000 &
  when: on_success
  script:
    - echo "Starting linter..."
    - sh linter.sh
    - echo "Starting tests..."
    - coverage erase
    - DATABASE_URL=$TEST_DATABASE_URL coverage run --include="./dietela_quiz/*","./nutritionists/*","./dietela_program/*" manage.py test --keepdb
    - coverage xml -i
    - coverage report -m
  artifacts:
    paths:
      - coverage.xml

SonarScanner:
  image:
    name: addianto/sonar-scanner-cli:latest
    entrypoint: [""]
  stage: sonar-scanner
  script:
    - sonar-scanner
      -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
      -Dsonar.login=$SONARQUBE_TOKEN
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY

DeploymentStaging:
  image: ruby:2.4
  stage: deploy
  before_script:
    - gem install dpl
    - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
  script:
    - dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
    - export HEROKU_API_KEY=$HEROKU_APIKEY
    - heroku run --app $HEROKU_APPNAME migrate
  environment:
    name: staging
    url: $HEROKU_APP_HOST
  only:
    - staging

我该怎么办


Tags: 文件pytestimageherokumanageshcoverage