-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce semgrep rule to warn about use of TypeAdapter
We had several performance regressions in the past because of the use of TypeAdapter in often called code paths. We now add this rule to warn developers about the use of TypeAdapter. After careful review, checking the performance aspect, the developer can add an annotation next to the TypeAdapter call to suppress the warning. Besides the nature of the rule, this is also introducing the first semgrep rule to the code base. The idea is to replace some of our custom pylint checkers with semgrep rules in the near future. We will also integrate semgrep with our CI in the next steps. CMK-19526 Change-Id: Id464a5de0e06f13cd3141c5c671ea49cfae0b27b
- Loading branch information
1 parent
48edbbe
commit 086862a
Showing
8 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
rules: | ||
- id: type-adapter-detected | ||
patterns: | ||
- pattern: | | ||
TypeAdapter(...) | ||
- pattern-inside: | | ||
def $FUNC(...): ... | ||
message: >- | ||
Detected the use of TypeAdapter(). Executing TypeAdapter() is a costly operation which can | ||
lead to a major performance issue if used wrong. Its use may be acceptable when invoked | ||
only once, e.g. during program startup. Ensure it does not impact performance of your | ||
program negatively. Add "# nosemgrep: type-adapter-detected" to acknowledge this | ||
warning. | ||
languages: [python] | ||
severity: WARNING |