Skip to content

update the style guide on alert-messages #10405

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

Merged
merged 8 commits into from
Sep 20, 2022
Merged

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Sep 13, 2022

and add a QL-for-QL query detecting some violations of the guidance.


This updates the style guide as suggested by @felicitymay.
I've tried to write down the findings from asking about how the alert-message should look, and my own findings from revising a lot of alert-messages.


I would like a doc review on the changes to docs/query-metadata-style-guide.md, and whether the guidance seems reasonable for what an alert-message should look like.

@erik-krogh erik-krogh added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Sep 13, 2022
@erik-krogh erik-krogh marked this pull request as ready for review September 13, 2022 18:33
@erik-krogh erik-krogh requested review from a team as code owners September 13, 2022 18:33
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

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

In this case, I think a thorough documentation on each predicate is warranted, with at least one good and bad example. Then the docteam can even confirm that the query is doing the right thing.

esbena
esbena previously approved these changes Sep 13, 2022
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

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

For once, the docteam should look at the predicate documentation. See 88f1d2a in particular. Review it like this: does the docstring express the intent of the style guide?

kaeluka
kaeluka previously approved these changes Sep 14, 2022
Copy link
Contributor

@kaeluka kaeluka left a comment

Choose a reason for hiding this comment

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

Overall, looks good. Some small remarks, I'm pretty open about how you're going to address them — which is why I'm giving an approval.

One bonus comment:

I noticed that an alert message like this "Pointer arithmetic here may be done with the wrong type because of the cast $@.", source, "here" triggers two instances of the alert. I guess one for each string constants.

But an alert like "$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".", (where one string contains both flows to and here) triggers only one alert that contains both messages.

This is really minor and not worth making the query harder to read and I suspect that making this more consistent will be doable without making the implementation more complex; but I'm bringing it up in case it is possible easily.

@@ -179,8 +179,13 @@ The select clause of each alert query defines the alert message that is displaye
* The message should factually describe the problem that is being highlighted–it should not contain recommendations about how to fix the problem or value judgements.
* Program element references should be in 'single quotes' to distinguish them from ordinary words. Quotes are not needed around substitutions (`$@`).
* Avoid constant alert message strings and include some context, if possible. For example, `The class 'Foo' is duplicated as 'Bar'.` is preferable to `This class is duplicated here.`
* If a reference to the current location can't be avoided use "this location" instead of "here". For example, `Bad thing at this location.` is preferable to `Bad thing here.`.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not obvious to me why 'this location' would be better. I don't mind the rule, because consistent writing is a good thing — but can you add a half sentence to explain the reasoning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember someone suggesting it to avoid the "click here" anti-pattern, but now I can't find that review comment.

I've inserted a short sentence referencing the "click here" anti-pattern in the end.

Copy link
Contributor Author

@erik-krogh erik-krogh Sep 14, 2022

Choose a reason for hiding this comment

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

I'm wondering a bit if we should keep this line.

@aibaars suggested in a Slack comment that the "this location" phrasing got around the general "click-here" anti-pattern.
But as @smowton points out, it might not always make the text clearer: #10413 (comment)

Maybe the guidance should be that a link-text shouldn't be "here"?

Copy link
Contributor

Choose a reason for hiding this comment

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

In most cases could you just linkify the immediately preceding text, so something like

This sensitive data is written to a logfile unescaped /here/ -> This sensitive data is /written to a logfile unescaped/?

Copy link
Contributor

Choose a reason for hiding this comment

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

Then you can keep here when it refers to "[some statement, expression, argument or result on] the line of this alert" and replace it when it's referring to a second thing involved in the alert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to revise the text a bit, and moved the the parts about link-texts into a separate sub-section.

In most cases could you just linkify the immediately preceding text.

Yes, and the guide now includes that 👍


I still have the guidance about "this location" when you have an alert message without links, for when you can't get around mentioning the current location in the message.

@erik-krogh
Copy link
Contributor Author

I noticed that an alert message like this "Pointer arithmetic here may be done with the wrong type because of the cast $@.", source, "here" triggers two instances of the alert. I guess one for each string constants.

But an alert like "$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".", (where one string contains both flows to and here) triggers only one alert that contains both messages.

That's because the location I'm using is the string-constant that contains the style-violation.
In the latter case both problems are contained in the same string-constant, so the alert-location is exactly the same.
I could put the alert-location on the select, but that would break when the string-constant is outside the from-where-select.

@erik-krogh erik-krogh dismissed stale reviews from kaeluka and esbena via 8b3ba38 September 14, 2022 09:49
hubwriter
hubwriter previously approved these changes Sep 15, 2022
Copy link
Contributor

@hubwriter hubwriter left a comment

Choose a reason for hiding this comment

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

Docs team reviewer:
I've added a few (minor) comments.
👍

@hubwriter hubwriter removed the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Sep 15, 2022
Copy link
Contributor

@kaeluka kaeluka left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for the answers

@erik-krogh erik-krogh requested a review from smowton September 19, 2022 09:19
Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Style guide lgtm (haven't reviewed the ql-for-ql bit)

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.

5 participants