Skip to content

Ruby documentation#6860

Merged
calumgrant merged 14 commits intomainfrom
ruby-docs
Oct 20, 2021
Merged

Ruby documentation#6860
calumgrant merged 14 commits intomainfrom
ruby-docs

Conversation

@calumgrant
Copy link
Copy Markdown
Contributor

The two introductory guides to Ruby analysis:

  1. Basic query for Ruby code, covering just the AST classes
  2. CodeQL library for Ruby

At the moment the content is still a little rough, but I'd appreciate early feedback on whether this level of detail is what we are looking for.

hubwriter
hubwriter previously approved these changes Oct 13, 2021
Copy link
Copy Markdown
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.

This looks good. 👍


The query will take a few moments to return results. When the query completes, the results are displayed below the project name. The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to the expression ``ifexpr`` and is linked to the location in the source code of the project where ``ifexpr`` occurs. The second column is the alert message.

➤ `Example query results <https://lgtm.com/query/1214010107827821393/>`__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

link to be replaced

@@ -0,0 +1,3 @@
- `CodeQL queries for Ruby <https://github.com/github/codeql/tree/main/ruby/ql/src>`__
- `Example queries for Ruby <https://github.com/github/codeql/tree/main/ruby/ql/examples>`__
- `CodeQL library reference for Ruby <https://codeql.github.com/codeql-standard-libraries/ruby/>`__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

links don't currently resolve correctly


There are now fewer results because ``if`` expressions with an ``else`` branch are no longer included.

➤ `See this in the query console <https://lgtm.com/query/6233102733683510530/>`__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

link to be replaced


import codeql.ruby.CFG

The CFG reasons about the control flow between statements and expressions, for example whether one expression can
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is "reason" the right verb here? It seems anthropomorphic to say that the CFG reasons.

@hubwriter hubwriter changed the base branch from main to ruby-docs-megabranch October 13, 2021 14:38
@hubwriter hubwriter changed the base branch from ruby-docs-megabranch to main October 13, 2021 14:42
@hubwriter hubwriter dismissed their stale review October 13, 2021 14:42

The base branch was changed.

@calumgrant calumgrant requested review from hmac and nickrolfe October 15, 2021 17:07
@calumgrant calumgrant marked this pull request as ready for review October 15, 2021 17:08
elsif option == "-verbose"
# nothing to do - handled earlier
else
error "unrecognized option"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be simplified, I think.

if option == "-verbose"
  # nothing to do - handled earlier
else
  error "unrecognised option"
end

It's a bit more artificial, but removes the ambiguity around which if we're talking about.

else
error "unrecognized option"

In this case, identifying the ``if`` statement with the empty ``then`` branch as redundant is a false positive. One solution to this is to modify the query to ignore empty ``then`` branches if the ``if`` statement has an ``else`` branch.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might read a bit better? Avoids "if the if", at least.

Suggested change
In this case, identifying the ``if`` statement with the empty ``then`` branch as redundant is a false positive. One solution to this is to modify the query to ignore empty ``then`` branches if the ``if`` statement has an ``else`` branch.
In this case, identifying the ``if`` statement with the empty ``then`` branch as redundant is a false positive. One solution to this is to modify the query to select ``if`` statements where both the ``then`` and ``else`` branches are empty.

---------------

The abstract syntax tree (AST) represents the elements of the source code organized into a tree. The AST viewer
in Visual Studio Code shows the AST nodes, including the relevant CodeQL classes and predicates.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,622 @@
.. codeql-library-for-ruby:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this file auto-generated at all or is it written entirely by hand? I can see the reference of AST classes getting out of date in the future if we need to manually update it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's written by hand - though much of it has been copied+pasted from the source code.

I agree it's likely to get a bit out of date, but the doc is mainly meant as an overview so it doesn't need to be comprehensive.

@calumgrant
Copy link
Copy Markdown
Contributor Author

@hmac I've addressed your feedback.

@calumgrant calumgrant merged commit ed73d9b into main Oct 20, 2021
@calumgrant calumgrant deleted the ruby-docs branch October 20, 2021 09:47
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