Threat old code as new code

Hello,
My team choosed to fix old code issues as we code (and only on modified files) but SonarCloud is only reporting issues on new Code.
I tried setting the “New Code” config as “Specific date” to a date older than the creation of the repository (01/01/2012), but the old issues are still not reported.

Context:

  • GitHub Repository
  • Language: Apex
  • External Scanner: PMD
  • Config
    GitHub Workflow snippet:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          
      - name: Generate diff file
        run: |
          git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > diff.txt
          
      - name: Install PMD
        run: |
          curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.47.0/pmd-bin-6.47.0.zip" -o pmd-bin-6.47.0.zip
          unzip pmd-bin-6.47.0.zip
          rm pmd-bin-6.47.0.zip
      
      - name: Run static analysis
        run: pmd-bin-6.47.0/bin/run.sh pmd --rulesets pmd/ruleset-all.xml --file-list diff.txt --format xml --report-file pmd.xml --short-names --fail-on-violation false
          
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          SONAR_TOKEN: "${{ secrets.SONAR_TOKEN }}"
        with:
          args: >
            -Dsonar.apex.pmd.reportPaths=pmd.xml
            -Dsonar.test.exclusions=**/*
            -Dsonar.coverage.exclusions=**/*
            -Dsonar.cpd.exclusions=**/*

sonar-project.properties

# sonar-project.properties
sonar.projectKey=XXXXXX
sonar.organization=XXXXXX

# sonar.sources property to limit the scope of the analysis to certain directories.
sonar.sources=./src

sonar.language=apex
sonar.sourceEncoding=UTF-8

Hey there.

In the context of a Pull Request / short-lived branch Analysis – you will only ever see issues on changed lines of changed files, no matter how you adjust the New Code Period.

On your main branch (and long-lived branches), however, you should see all issues reported (and on the dashboard of the branch, the results split into New Code and Overall Code

Would it then work if i set all branches as long-lived branches ? and why does SonarCloud impose a Code Quality strategy instead of leaving it up to the users to set their own ?

A Clean as You Code strategy would definitely work for new projects but not for older ones were teams are trying to fix existing issues and vulnerabilities

Hello again @Colin, just found out i’m not the only one wanting this feature

It’s insane how a feature so wanted by users since 2019 is still not available, can you please lead me to any possible workaround?