Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writer-json: do not needlessly duplicate messages in SARIF #77

Closed
wants to merge 1 commit into from

Conversation

lzaoral
Copy link
Member

@lzaoral lzaoral commented Aug 23, 2022

... when we have only one.

@lzaoral lzaoral requested review from kdudka and jamacku August 23, 2022 10:37
@lzaoral lzaoral self-assigned this Aug 23, 2022
Comment on lines 46 to 49
"nestingLevel": 0,
"kinds": [
"warning"
]
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that we will lose also these nodes. However, they are not documented in GitHub's SARIF manual [1] so I guess it's harmless?

[1] https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#location-object

Copy link
Member

Choose a reason for hiding this comment

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

This is fine as long as the output of csgrep --mode=sarif | csgrep --mode=json stays unchanged. For defects with more than one event, the kinds.warning field is important for csgrep to preserve data. But such defects should be unaffected by this change.

sarifEncodeComment(&relatedLocs, def, i);
else
sarifEncodeEvt(&flowLocs, def, i);
if (def.events.size() > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Please write this as 1U < def.events.size(). The source code of csdiff always puts lower operand to left for consistency.

Copy link
Member

@jamacku jamacku left a comment

Choose a reason for hiding this comment

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

Hmm, it looks like GitHub doesn't care if "codeFlows" message is missing. It duplicates it anyway.

Screenshot from 2022-08-23 14-06-01

But SARIF generated by csdiff looks correctly
{
    "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "ShellCheck",
                    "version": "2.6.0.20220823.123456.g064f632.pr_77",
                    "informationUri": "https://github.com/csutils/csdiff"
                }
            },
            "results": [
                {
                    "ruleId": "SHELLCHECK_WARNING: note[SC2086]",
                    "locations": [
                        {
                            "id": 0,
                            "physicalLocation": {
                                "artifactLocation": {
                                    "uri": "src/index.sh"
                                },
                                "region": {
                                    "startLine": 9,
                                    "startColumn": 6
                                }
                            }
                        }
                    ],
                    "message": {
                        "text": "Double quote to prevent globbing and word splitting."
                    }
                },
                {
                    "ruleId": "SHELLCHECK_WARNING: warning[SC1090]",
                    "locations": [
                        {
                            "id": 0,
                            "physicalLocation": {
                                "artifactLocation": {
                                    "uri": "src/index.sh"
                                },
                                "region": {
                                    "startLine": 11,
                                    "startColumn": 3
                                }
                            }
                        }
                    ],
                    "message": {
                        "text": "ShellCheck can't follow non-constant source. Use a directive to specify location."
                    }
                },
                {
                    "ruleId": "SHELLCHECK_WARNING: note[SC2086]",
                    "locations": [
                        {
                            "id": 0,
                            "physicalLocation": {
                                "artifactLocation": {
                                    "uri": "src/index.sh"
                                },
                                "region": {
                                    "startLine": 11,
                                    "startColumn": 3
                                }
                            }
                        }
                    ],
                    "message": {
                        "text": "Double quote to prevent globbing and word splitting."
                    }
                },
                {
                    "ruleId": "SHELLCHECK_WARNING: note[SC2250]",
                    "locations": [
                        {
                            "id": 0,
                            "physicalLocation": {
                                "artifactLocation": {
                                    "uri": "src/index.sh"
                                },
                                "region": {
                                    "startLine": 120,
                                    "startColumn": 13
                                }
                            }
                        }
                    ],
                    "message": {
                        "text": "Prefer putting braces around variable references even when not strictly required."
                    }
                },
                {
                    "ruleId": "SHELLCHECK_WARNING: note[SC2250]",
                    "locations": [
                        {
                            "id": 0,
                            "physicalLocation": {
                                "artifactLocation": {
                                    "uri": "src/index.sh"
                                },
                                "region": {
                                    "startLine": 122,
                                    "startColumn": 6
                                }
                            }
                        }
                    ],
                    "message": {
                        "text": "Prefer putting braces around variable references even when not strictly required."
                    }
                }
            ]
        }
    ]
}

Copy link
Member

@jamacku jamacku left a comment

Choose a reason for hiding this comment

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

LGTM

@lzaoral
Copy link
Member Author

lzaoral commented Sep 14, 2022

I'll mark this as a WIP since the messages are still duplicated in the visualised output.

@lzaoral lzaoral marked this pull request as draft September 14, 2022 14:34
@lzaoral
Copy link
Member Author

lzaoral commented Sep 14, 2022

@jamacku, aren't the duplicities actually absent with #68? Maybe the second line is always sourced from the rule metadata and duplicated only when it's missing.

@lzaoral
Copy link
Member Author

lzaoral commented Sep 16, 2022

That theory is debunked by redhat-plumbers-in-action/differential-shellcheck#117, so the search continues...

... when we have only one.

Reported-by: Jan Macku <[email protected]>
@lzaoral
Copy link
Member Author

lzaoral commented Feb 7, 2023

Hmm, this PR seems to be stuck since it is out of date with actual contents of https://github.com/lzaoral/csdiff/tree/dont-duplicate-messages and I've already tried pushing few times.

@lzaoral lzaoral changed the title json-writer: do not needlessly duplicate messages in SARIF writer-json: do not needlessly duplicate messages in SARIF Feb 7, 2023
@lzaoral lzaoral marked this pull request as ready for review February 7, 2023 13:50
@lzaoral lzaoral marked this pull request as draft February 7, 2023 13:50
@jamacku jamacku force-pushed the dont-duplicate-messages branch from e335308 to 74996c8 Compare February 7, 2023 13:55
@lzaoral lzaoral force-pushed the dont-duplicate-messages branch from 74996c8 to e335308 Compare February 7, 2023 14:00
@lzaoral
Copy link
Member Author

lzaoral commented Sep 12, 2023

@jamacku Could you please create a issue to track the problem depicted in #77 (review), if it is still present? Thank you!

@lzaoral
Copy link
Member Author

lzaoral commented Sep 12, 2023

After discussion with @jamacku and @kdudka, we have decided to close this PR because it does not introduce any visible improvements for Differential ShellCheck.

@lzaoral lzaoral closed this Sep 12, 2023
@lzaoral lzaoral deleted the dont-duplicate-messages branch September 12, 2023 12:51
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