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

fix(misconf): don't shift ignore rule related to code #6708

Merged
merged 2 commits into from
May 17, 2024

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented May 16, 2024

Description

This PR prevents a range shift for a rule that is on the same line as the code.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review May 16, 2024 07:53
@nikpivkin nikpivkin requested a review from simar7 as a code owner May 16, 2024 07:53
ids: []string{"rule-2"},
},
shouldIgnore: true,
},
}

for _, tt := range tests {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Since we can pass a slice of ids of rules, should we create a test case as such:

		{
			name: "multiple ignore rules on the same line",
			src: `# trivy:ignore:rule-1
# trivy:ignore:rule-2
test #trivy:ignore:rule-3
`,
			args: args{
				metadata: metadataWithLine(filename, 3),
				ids:      []string{"rule-1", "rule-2", "rule-3", "non-existing-rule"},
			},
			shouldIgnore: true,
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done c572cca

if _, exists := rule.sections["id"]; !exists {
return Rule{}, errors.New("rule section with the `ignore` key is required")
if _, exists := sections["id"]; !exists {
return nil, errors.New("rule section with the `ignore` key is required")
Copy link
Member

Choose a reason for hiding this comment

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

Are there any callers of this func that we need to add a check for when we return nil here? I only see this and it seems like this is covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I guess it is subjective as I only tend to return nil for structs that are passed around by reference. But I'm fine with this.

@simar7 simar7 self-requested a review May 17, 2024 06:09
@simar7 simar7 added this pull request to the merge queue May 17, 2024
Merged via the queue into aquasecurity:main with commit 39a746c May 17, 2024
12 checks passed
@nikpivkin nikpivkin deleted the misconf-ignore branch May 27, 2024 06:42
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.

bug(misconf): Inline filtering doesn't work anymore for avd-aws-0091
2 participants