- SonarQube 8.9.2 (LTS)
- Goal : Get duplication to show up (>0) for Python projects
- What I’ve done:
- Read “duplication” documentation Metric Definitions | SonarQube Docs
- Duplicated a 20 lines function
I still get 0% of duplication
I still get 0% of duplication
Hello,
Can you try to analyze this open source project made of Python and JS and see if you can reproduce the same figures as me:
Analysis command:
sonar-scanner -Dsonar.projectKey=PythonDup -Dsonar.sources=.
Thanks
Alex
Thank you Alex.
I get something like this:
So yes I get a noticeable amount of duplication in this project… I don’t understand why mine doesn’t report any.
See the density report of my project you’ll see that record_orphan2()
function duplicates with record_orphan()
.
Also I’m providing the CI output for sonarqube against my project
The function you duplicated in your small 500 LOCs project doesn’t have enough Lines of Code to trigger the duplication detection.
I added some extra lines and it works:
if type(entry) is not dict:
return False
try:
with open(orphanFilePath, 'r+') as orphanFile:
_j = json.load(orphanFile)
orphanFile.seek(0)
_j['GitLabOrphan'].update(entry)
json.dump(_j, orphanFile)
with open(orphanFilePath, 'r+') as orphanFile:
_j = json.load(orphanFile)
orphanFile.seek(0)
_j['GitLabOrphan'].update(entry)
json.dump(_j, orphanFile)
except OSError as e:
logger.error('cannot update file: {}'.format(e))
except json.decoder.JSONDecodeError:
logger.error("JSON decode error")