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

feat: add support for skipcq comments to ignore issues #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MashyBasker
Copy link
Collaborator

@MashyBasker MashyBasker commented Mar 1, 2025

This PR introduces support for skipcq comments to ignore specific issues in the source code.

Checklist

  • Implement support for basic skipcq functionality (ignores all checkers)
  • Improve this feature to skip specific checkers by adding their namespace to the comment
  • Add unit tests

Related to #135

Copy link

vercel bot commented Mar 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
globstar ⬜️ Ignored (Inspect) Visit Preview Mar 3, 2025 9:58am

@MashyBasker
Copy link
Collaborator Author

Current behavior

Testing with checkers/python/weak-ssl-version.yml

Test file (without skipcq comment)

import ssl
from pyOpenSSL import SSL

# <expect-error>
ssl.wrap_socket(ssl_version=ssl.PROTOCOL_SSLv2)
# <expect-error>
SSL.Context(method=SSL.SSLv2_METHOD)
# <expect-error>
SSL.Context(method=SSL.SSLv23_METHOD)

Globstar logs

image

Test file (with skipcq comment)

import ssl
from pyOpenSSL import SSL

# <expect-error>
ssl.wrap_socket(ssl_version=ssl.PROTOCOL_SSLv2)
# <expect-error>
SSL.Context(method=SSL.SSLv2_METHOD)
# <expect-error>
SSL.Context(method=SSL.SSLv23_METHOD) # skipcq

Globstar logs

image

@MashyBasker MashyBasker marked this pull request as ready for review March 3, 2025 09:59
@MashyBasker
Copy link
Collaborator Author

Current behaviour

  • Using only skipcq ignores all checkers
  • Using skipcq with checker namespace ignores only the checker whose name is provided
    • checkers with same but for different languages will be identified as separate checkers
    • language prefix for the checker is the file extension of the language. Eg. py for Python (a better way for name lookup needs to be added)

@MashyBasker MashyBasker changed the title feat: add support for skipcq comments to ignore checkers feat: add support for skipcq comments to ignore issues Mar 3, 2025
Copy link
Contributor

@sourya-deepsource sourya-deepsource left a comment

Choose a reason for hiding this comment

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

Checking for skipcq can be done as a post-processor, after all the analysis has run.

It'd be best if you could add unit tests as well.

// utility function to check if a node or its line has a skipcq comment
// Format for the skipcq directive:
// `// skipcq: <language>:<checker_name>`
func HasSkipCQComment(source []byte, node *sitter.Node, checker YamlChecker) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of regex-based search for a comment, I'd recommend using tree-sitter to search for all comments, and then using a function like this to match if it is a valid skipcq comment.

var directive string
var found bool

commentFormats := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment identifier should be based on the language.

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.

2 participants