Skip to content

Update all dependencies to use tree-sitter v0.20 - #812

Closed
BrainBuzzer wants to merge 6 commits into
mozilla:masterfrom
hyperlog-core:master
Closed

BrainBuzzer wants to merge 6 commits into
mozilla:masterfrom
hyperlog-core:master

Conversation

@BrainBuzzer

@BrainBuzzer BrainBuzzer commented Mar 31, 2022 •

Copy link
Copy Markdown

Updated all dependencies to use tree-sitter v0.20. This PR includes:

  1. Regenerated grammar rules for all languages
  2. Java has changed the Comment type to LineComment and BlockComment
  3. Fixes for JavaScript tests (added more about this in the commit description)

There are some issues with tests for the rust repository. It seems that unlike the previous version where functions in macros were detected and counted towards metrics are not detected anymore due to changes in how the tree-sitter parses code. The following metrics are broken depending on macros used in rust code:

  • Cyclomatic
  • Cognitive
  • Halstead
  • MI
  • NOM

Note - Python is using the GitHub repo's master branch because v0.19.1 from crates.io for tree-sitter-python was not up to date and was producing more errors than expected. It might be a good idea to fork and tag the repo to the latest commit.

JavaScript and Mozjs tests in the previous version had wrong code provided. The code that was provided previously was in the typescript style. With tree-sitter v0.19, it created an extra `expression_statement` and due to that, the false positive saying the `lloc` is 7 was provided.
@BrainBuzzer

Copy link
Copy Markdown
Author

Related discussions: #674 #789

@marco-c marco-c linked an issue Mar 31, 2022 that may be closed by this pull request
@BrainBuzzer

Copy link
Copy Markdown
Author

After investigating in the test cases, found following:

  1. ExpressionStatement was declared before every Statement, leading to almost double lloc.
  2. The previous version of the tree-sitter used to give false positives, which led to a higher number of operators and operands. This in turn, was also affecting the metrics related to halstead. An example of this is in the file library/proc_macro/src/lib.rs#L994, you can see that in the comment there is a dash. In the previous version, this dash was being counted as an operator. Perhaps it's time to update rca-output repo once this PR manages to produce proper results.
  3. It also seems that the cyclomatic complexity for rust code is incorrect. The cyclomatic compute function for RustCode utilizes two questionable node types. For and QMARK. Say there's a line as follows:
impl<T: ?Sized> UnwindSafe for Mutex<T> {}

Do we want to count the cyclomatic complexity of the above code as 2?

Investigating further problems with Cognitive, NOM, and MI. cc @marco-c @marco-ballario

@BrainBuzzer

Copy link
Copy Markdown
Author

After checking through the rest of the metrics, I'm 99% certain that the previous metrics were giving a lot of false positives, and that's why most of them have an error margin of ~1-2%. This PR otherwise seems ready to me for merging.

@BrainBuzzer
BrainBuzzer marked this pull request as ready for review April 15, 2022 14:33
@Luni-4 Luni-4 self-assigned this May 10, 2022
@tjbell

tjbell commented Jun 14, 2022 •

Copy link
Copy Markdown

I was curious if there was any movement on this pull request? It looks like the main tree-sitter-java grammar was just updated to 0.20.0.

@Luni-4

Luni-4 commented Jun 16, 2022 •

Copy link
Copy Markdown
Collaborator

@tjbell

Yeah, the grammar has been updated but not on crates.io which is still at 0.19. We are trying to come up with a solution here if you are interested in the conversation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update tree-sitter and grammars to version 0.20

3 participants