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

Metavariable Type Extension for Semgrep Rule Syntax #8119

Closed
ihji opened this issue Jun 23, 2023 · 3 comments
Closed

Metavariable Type Extension for Semgrep Rule Syntax #8119

ihji opened this issue Jun 23, 2023 · 3 comments

Comments

@ihji
Copy link
Contributor

ihji commented Jun 23, 2023

This issue proposes a dedicated field for annotating the type information of metavariables. By adopting this approach, instead of relying solely on language-specific casting syntax, we provide an additional way to enhance the overall usability by eliminating the need to write redundant type cast expressions for a single metavariable.

Moreover, the new syntax brings other benefits, including improved support for target languages that lack built-in casting syntax. It also promotes a unified approach to expressing type, pattern, and regex constraints for metavariables, resulting in improved consistency across rule definitions.

Current syntax:

rules:
  - id: no-string-eqeq
    severity: WARNING
    message: find errors
    languages:
      - java
    patterns:
      - pattern-not: null == (String $Y)
      - pattern: $X == (String $Y)

Proposed syntax:

rules:
  - id: no-string-eqeq
    severity: WARNING
    message: find errors
    languages:
      - java
    patterns:
      - pattern-not: null == $Y
      - pattern: $X == $Y
      - metavariable-type:
          metavariable: $Y
          type: String
@r2c-demo
Copy link
Collaborator

This issue is synced in Linear at https://linear.app/semgrep/issue/PA-2884/metavariable-type-extension-for-semgrep-rule-syntax. Note: this link is for r2c use only and is not accessible publicly.

@aryx
Copy link
Collaborator

aryx commented Jun 23, 2023

What's the purpose of this issue? Just so it could be referenced in the PR?
Should we close it then now?

@ihji
Copy link
Contributor Author

ihji commented Jun 23, 2023

What's the purpose of this issue? Just so it could be referenced in the PR?

Exactly 😄

Should we close it then now?

@ihji ihji closed this as completed Jun 23, 2023
aryx pushed a commit that referenced this issue Jun 26, 2023
Support metavariable-type field for Python.
Context: #8119 

PR checklist:

- [ ] Purpose of the code is [evident to future
readers](https://semgrep.dev/docs/contributing/contributing-code/#explaining-code)
- [ ] Tests included or PR comment includes a reproducible test plan
- [ ] Documentation is up-to-date
- [ ] A changelog entry was [added to
changelog.d](https://semgrep.dev/docs/contributing/contributing-code/#adding-a-changelog-entry)
for any user-facing change
- [ ] Change has no security implications (otherwise, ping security
team)

If you're unsure about any of this, please see:

- [Contribution
guidelines](https://semgrep.dev/docs/contributing/contributing-code)!
- [One of the more specific guides located
here](https://semgrep.dev/docs/contributing/contributing/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants