github / codeql-coding-standards

This repository contains CodeQL queries and libraries which support various Coding Standards.
MIT License
127 stars 58 forks source link

Missing pretty name for MISRA in report generation #667

Open g-ulli opened 2 months ago

g-ulli commented 2 months ago

Describe the bug scripts/reports/analysis_report.py fails for .sarif file containing MISRA violations.

In our project, we have C files and C++ files. We want to use MISRA C for .c and .h files and Autosar C++14 for .cpp and .hpp files. A naive way to run both queries fails in the report generation because of this incomplete array:

https://github.com/github/codeql-coding-standards/blob/6e090fe94faa0d74011b23c0aa4cc4d5c43e5b78/scripts/reports/utils.py#L185-L186

Traceback (most recent call last):
  File ".../codeql-coding-standards/scripts/reports/analysis_report.py", line 63, in <module>
    utils.generate_guideline_compliance_summary(
  File ".../codeql-coding-standards/scripts/reports/utils.py", line 187, in generate_guideline_compliance_summary
    print("**Coding Standards applied**: " + ", ".join([standard_pretty_name[standard_short_name]
  File ".../codeql-coding-standards/scripts/reports/utils.py", line 187, in <listcomp>
    print("**Coding Standards applied**: " + ", ".join([standard_pretty_name[standard_short_name]
KeyError: 'misra'

To Reproduce

codeql database analyze \
    --format=sarifv2.1.0 \
    --output=autosar-misra.sarif \
    <codeql database> \
    <path to codeql-coding-standards>/cpp/autosar/src/codeql-suites/autosar-default.qls
    <path to codeql-coding-standards>/cpp/misra/src/codeql-suites/misra-default.qls

python3.9 <path to codeql-coding-standards>/scripts/reports/analysis_report.py \
    <codeql database> \
    autosar-misra.sarif \
    autosar-misra-report

Expected behavior Normal report generation without errors

Screenshots If applicable, add screenshots to help explain your problem.

Environment

lcartey commented 2 months ago

Thanks for the bug report! We will take a look at fixing this.