Skip to content

Rust: restrict line and file counts to include only extracted source files #19616

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented May 28, 2025

Should correct unexpected counts for "library" files that happen to be located in the source folder. For example source files that are excluded from extraction can still be extracted in "library" mode to aid type inference if other crates depend on them.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 28, 2025
@aibaars aibaars changed the title Rust: restrict line and file counts to include only extracted source … Rust: restrict line and file counts to include only extracted source files May 29, 2025
@aibaars aibaars marked this pull request as ready for review May 30, 2025 08:32
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 08:32
@aibaars aibaars requested a review from a team as a code owner May 30, 2025 08:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates summary queries to ensure metrics only include files extracted as source code.

  • Added a fromSource() filter to getLinesOfUserCode() to exclude non-source files.
  • Switched the file counter in NumberOfFilesExtractedWithErrors.ql to operate on ExtractedFile instead of File.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rust/ql/src/queries/summary/Stats.qll Added f.fromSource() to the LOC sum to limit to source files.
rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql Changed count(File f) to count(ExtractedFile f) to target extracted files.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Are the results of this change visible anywhere, e.g. would they show up in a (small) DCA run?

@@ -35,7 +35,7 @@ int getLinesOfCode() { result = sum(File f | f.fromSource() | f.getNumberOfLines
* Gets a count of the total number of lines of code from the source code directory in the database.
*/
int getLinesOfUserCode() {
result = sum(File f | exists(f.getRelativePath()) | f.getNumberOfLinesOfCode())
result = sum(File f | f.fromSource() and exists(f.getRelativePath()) | f.getNumberOfLinesOfCode())
Copy link
Contributor

@geoffw0 geoffw0 May 30, 2025

Choose a reason for hiding this comment

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

Can we not use ExtractedFile here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants