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

🐛 Avoid reading every file searching for sonar configs #3929

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

spencerschrock
Copy link
Contributor

What kind of change does this PR introduce?

bug fix

What is the current behavior?

Every file's whole contents are read. But for any file not called pom.xml this is wasted work.

What is the new behavior (if this is a feature change)?**

  • File content is only read once we know the file is called pom.xml
  • Changed strings/bytes comparison functions to avoid allocating extra strings.
  • Tests for the changes have been added (for bug fixes/features)

(should be covered by existing tests)

Which issue(s) this PR fixes

Related to #3831 (SAST won't run locally, but this will hopefully save time in the cron)

Special notes for your reviewer

Does this PR introduce a user-facing change?

For user-facing changes, please add a concise, human-readable release note to
the release-note

(In particular, describe what changes users might need to make in their
application as a result of this pull request.)

NONE

if the filename doesn't match we don't use the file content.

Signed-off-by: Spencer Schrock <sschrock@google.com>
we don't save the line, just the offset.
using the bytes versions avoids allocating new strings

Signed-off-by: Spencer Schrock <sschrock@google.com>
@spencerschrock spencerschrock requested a review from a team as a code owner March 7, 2024 18:47
@spencerschrock spencerschrock requested review from naveensrinivasan and justaugustus and removed request for a team March 7, 2024 18:47
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Merging #3929 (80aa12c) into main (db234bb) will increase coverage by 1.93%.
The diff coverage is 66.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3929      +/-   ##
==========================================
+ Coverage   66.64%   68.57%   +1.93%     
==========================================
  Files         234      234              
  Lines       15877    15881       +4     
==========================================
+ Hits        10581    10891     +310     
+ Misses       4640     4296     -344     
- Partials      656      694      +38     

@spencerschrock spencerschrock enabled auto-merge (squash) March 7, 2024 19:05
@spencerschrock spencerschrock merged commit f401d79 into ossf:main Mar 7, 2024
38 checks passed
@spencerschrock spencerschrock deleted the sast-reader branch March 7, 2024 19:19
fhoeborn pushed a commit to fhoeborn/scorecard that referenced this pull request Apr 1, 2024
* use reader instead of contents

if the filename doesn't match we don't use the file content.

Signed-off-by: Spencer Schrock <sschrock@google.com>

* compare bytes to avoid allocations

we don't save the line, just the offset.
using the bytes versions avoids allocating new strings

Signed-off-by: Spencer Schrock <sschrock@google.com>

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants