Skip to content

Guideline statistics bugs - #5188

Open
gulyasgergely902 wants to merge 2 commits into
Ericsson:masterfrom
gulyasgergely902:guideline-statistics-bugs
Open

gulyasgergely902 wants to merge 2 commits into
Ericsson:masterfrom
gulyasgergely902:guideline-statistics-bugs

Conversation

@gulyasgergely902

@gulyasgergely902 gulyasgergely902 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

fixes CODECHKR-7158

This change fixes a bug and adds an enhancement in the guideline statistics feature.

  • The exported CSV contains now all the rules exists in the given guideline not just the ones which has a checker to it.
  • The rule titles which have commas in them are now encapsulated in quotation marks to prevent word splitting.

@bruntib

bruntib commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

I have some "none" checkers in the exported CSV:

sei-cert-c,arr32-c,,core.VLASize,High,Enabled in all selected runs,0,0
sei-cert-c,arr36-c,,security.PointerSub,High,Enabled in all selected runs,0,0
sei-cert-c,arr36-c,,cppcheck-subtractPointers,High,Not enabled in all selected runs,0,0
sei-cert-c,arr36-c,,gcc-analyzer-undefined-behavior-ptrdiff,Unspecified,Not enabled in all selected runs,0,0
sei-cert-c,arr37-c,,none,,,,
sei-cert-c,arr38-c,,unix.StdCLibraryFunctions,High,Enabled in all selected runs,0,2
sei-cert-c,arr38-c,,gcc-analyzer-out-of-bounds,Unspecified,Not enabled in all selected runs,0,0
sei-cert-c,arr38-c,,gcc-analyzer-use-of-uninitialized-value,Unspecified,Not enabled in all selected runs,0,0
sei-cert-c,arr39-c,,clang-diagnostic-array-bounds-pointer-arithmetic,Medium,Enabled in all selected runs,0,0
sei-cert-c,arr39-c,,misc-sizeof-expression,Unspecified,Not enabled in all selected runs,0,0
sei-cert-c,arr39-c,,gcc-analyzer-out-of-bounds,Unspecified,Not enabled in all selected runs,0,0
sei-cert-c,con30-c,,none,,,,
sei-cert-c,con31-c,,none,,,,
sei-cert-c,con32-c,,none,,,,
sei-cert-c,con33-c,,concurrency-mt-unsafe,Medium,Not enabled in all selected runs,0,0
sei-cert-c,con34-c,,none,,,,

Also, couldn't we use some csv library in JS instead of manually escaping csv characters?

@gulyasgergely902

Copy link
Copy Markdown
Collaborator Author

Since the only job here is to escape the CSV, I don't think it is worth using any lib here. The function is simple enough to be used IMHO.

Guideline statistics export does not contain rules which does not have
an attached rule to it. This change adds them just like in the gui table.
@gulyasgergely902
gulyasgergely902 force-pushed the guideline-statistics-bugs branch from 7d6aced to 2631408 Compare November 25, 2026 11:49
function escapeCSVField(value) {
const _str = value === null || value === undefined ? "" : String(value);

if (/[",\n\r]/.test(_str)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using double quotes only if there are these special characters in the string. I think we should always use double quotes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification of CSV format (RFC 4180) does not explicitly say that every field should or should not be enclosed in quotes although what they say is that if the fields are not enclosed in quotes then there may not be any inside the field either. I'm not against using quotes for every field to make them homologous.

const _str = value === null || value === undefined ? "" : String(value);

if (/[",\n\r]/.test(_str)) {
return `"${_str.replace(/"/g, "\"\"")}"`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use
return "${_str.replaceAll('"', '""')}";

it just easier to read.

stat.guidelineName,
stat.guidelineRule,
stat.guidelineRuleTitle,
"",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use "none" instead of empty string to match what we have in the GUI table?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue came up previously on this PR, where the result of the dicussion was to simly omit the none word and use the empty string instead. I see your point to make the CSV similar to the UI but whilst UI is for humans, CSV will be read by code and it is easier to distiguish between string or "" than a string or another string. Also currently all other columns also have the none word on the UI whereas the CSV does not.

If the rule title contains a comma, it breaks the exported JSON thus
encapsulating it in quotation marks to prevent breaking of titles with
commas in them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants