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

skip warnings on commented out and empty lines #178

Merged
merged 7 commits into from
Feb 1, 2021

Conversation

sfenman
Copy link

@sfenman sfenman commented Feb 1, 2021

Q A
πŸ› Bug fix? no
πŸš€ New feature? no
⚠ Deprecations? no
❌ BC Break no
πŸ”— Related issues #157
❓ Documentation no

Description

Created a condition to skip empty or commented out (starting with # lines) from checking.

@sfenman sfenman requested a review from a team as a code owner February 1, 2021 10:35
@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #178 (d9d1d01) into main (4e486b3) will increase coverage by 0.03%.
The diff coverage is 8.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   69.68%   69.71%   +0.03%     
==========================================
  Files         190      190              
  Lines        4364     4379      +15     
==========================================
+ Hits         3041     3053      +12     
- Misses       1082     1086       +4     
+ Partials      241      240       -1     
Impacted Files Coverage Ξ”
pkg/cmd/scan.go 79.04% <0.00%> (-0.96%) ⬇️
pkg/remote/aws/db_instance_supplier.go 66.66% <0.00%> (ΓΈ)
pkg/remote/aws/db_subnet_group_supplier.go 65.51% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_ami_supplier.go 66.66% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_ebs_snapshot_supplier.go 74.35% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_ebs_volume_supplier.go 72.22% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_eip_association_supplier.go 68.75% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_eip_supplier.go 68.75% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_instance_supplier.go 73.68% <0.00%> (ΓΈ)
pkg/remote/aws/ec2_key_pair_supplier.go 62.96% <0.00%> (ΓΈ)
... and 35 more

continue
}
if nbArgs == 2 { // We want to ignore a resource (type.id)
if nbArgs == 0 || strings.HasPrefix(line, "#") {
Copy link
Contributor

Choose a reason for hiding this comment

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

nbArgs == 0 is not exactly the check we want to ignore, we want to check if the line is empty

Your if directive should be moved just after line := scanner.Text().
We do not want to call readDriftIgnoreLine for ignored lines.

You can also remove the else directive as you put a continue.

Something like below should do the job :

line := scanner.Text()
+if line == "" || strings.HasPrefix(line, "#") {
+  logrus.WithFields(logrus.Fields{
+    "line": line,
+  }).Debug("Skipped comment or empty line")
+  continue
+}
typeVal := readDriftIgnoreLine(line)

@eliecharra
Copy link
Contributor

Hi @sfenman thanks a lot for this PR πŸ˜ƒ , could you update the test suite to reflect your changes too ? πŸ™πŸ»

@sfenman
Copy link
Author

sfenman commented Feb 1, 2021

Hi @eliecharra, thank you for the comments, I will update it shortly. I guess a new testing function is needed to test about empty and commented out lines explicitly right?

@eliecharra
Copy link
Contributor

eliecharra commented Feb 1, 2021

Hi @eliecharra, thank you for the comments, I will update it shortly. I guess a new testing function is needed to test about empty and commented out lines explicitly right?

I think you just have to update drift_ignore_valid/.driftignore by adding empty lines and comment.

We do not want to test that no warning are send at the moment as it will imply to use and inject a custom logger in driftignore logic to be able to mock it. So don't spend too much time on this πŸ˜ƒ

@eliecharra eliecharra linked an issue Feb 1, 2021 that may be closed by this pull request
@eliecharra eliecharra added this to the v0.4.0 milestone Feb 1, 2021
@eliecharra eliecharra added the kind/enhancement New feature or improvement label Feb 1, 2021
@sfenman
Copy link
Author

sfenman commented Feb 1, 2021

I've made the changes based on your comments, but I couldn't omit the else directive because without it, the comments and the empty lines are still being passed to readDriftIgnoreLine .

@eliecharra
Copy link
Contributor

I've made the changes based on your comments, but I couldn't omit the else directive because without it, the comments and the empty lines are still being passed to readDriftIgnoreLine .

You are missing the continue directive below in your if after the debug log, it will skip the line without the need for an else statement.

image

It will make the code more readable and avoid unnecessary else nesting.

Copy link
Contributor

@eliecharra eliecharra left a comment

Choose a reason for hiding this comment

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

Awesome, thanks a lot for this fix @sfenman πŸ™πŸ»

@eliecharra eliecharra merged commit c6e5f96 into snyk:main Feb 1, 2021
@wbeuil
Copy link
Contributor

wbeuil commented Feb 3, 2021

@all-contributors please add @sfenman for code

@allcontributors
Copy link
Contributor

@wbeuil

I've put up a pull request to add @sfenman! πŸŽ‰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable warning in driftignore parsing
3 participants