-
Notifications
You must be signed in to change notification settings - Fork 59
tests: check: ast-grep: add static analysis rules #545
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
Open
pzmarzly
wants to merge
17
commits into
facebook:main
Choose a base branch
from
pzmarzly:push-muppwpwwukvo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
be54032
tests: check: ast-grep: integrate with build and CI
pzmarzly 9b9adde
tests: check: ast-grep: add assert-pointer-params rule
pzmarzly ed87540
tests: check: ast-grep: add bf-prefix-public-functions rule
pzmarzly f83d855
tests: check: ast-grep: add double-pointer-output rule
pzmarzly aa60e80
tests: check: ast-grep: add doxygen-prefer-backticks rule
pzmarzly fef0071
tests: check: ast-grep: add doxygen-public-functions rule
pzmarzly 1d12817
tests: check: ast-grep: add enum-bf-prefix rule
pzmarzly 07397a2
tests: check: ast-grep: add enum-sentinel-format rule
pzmarzly eafcf52
tests: check: ast-grep: add fd-init-minus-one rule
pzmarzly 8fb423d
tests: check: ast-grep: add free-function-pattern rule
pzmarzly f722aa8
tests: check: ast-grep: add negative-errno-returns rule
pzmarzly 9efbdd3
tests: check: ast-grep: add no-direct-free rule
pzmarzly 1939157
tests: check: ast-grep: add no-fprintf-stderr rule
pzmarzly bd69105
tests: check: ast-grep: add no-ifndef-guards rule
pzmarzly 96edf73
tests: check: ast-grep: add single-line-comment-style rule
pzmarzly 54a0e2d
tests: check: ast-grep: add spdx-license-header rule
pzmarzly 0b9abfb
tests: check: ast-grep: add struct-bf-prefix rule
pzmarzly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ RUN dnf --disablerepo=* --enablerepo=fedora,updates --nodocs --setopt=install_we | |
| libgit2-devel \ | ||
| libpfm-devel \ | ||
| libtool \ | ||
| pipx \ | ||
| procps-ng \ | ||
| python3-breathe \ | ||
| python3-dateutil \ | ||
|
|
@@ -37,3 +38,6 @@ RUN dnf --disablerepo=* --enablerepo=fedora,updates --nodocs --setopt=install_we | |
| sed \ | ||
| xxd && \ | ||
| dnf clean all -y | ||
|
|
||
| RUN pipx install --global ast-grep-cli && \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already use pip for Ubuntu containers, why not using it too here? |
||
| ast-grep --version | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
62 changes: 62 additions & 0 deletions
62
tests/check/ast-grep/rule-tests/__snapshots__/assert-pointer-params-snapshot.yml
This file contains hidden or 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,62 @@ | ||
| id: assert-pointer-params | ||
| snapshots: | ||
| ? | | ||
| int bf_chain_add_rule(struct bf_chain *chain, struct bf_rule *rule) | ||
| { | ||
| return 0; | ||
| } | ||
| : labels: | ||
| - source: |- | ||
| int bf_chain_add_rule(struct bf_chain *chain, struct bf_rule *rule) | ||
| { | ||
| return 0; | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 85 | ||
| - source: '*chain' | ||
| style: secondary | ||
| start: 38 | ||
| end: 44 | ||
| - source: struct bf_chain *chain | ||
| style: secondary | ||
| start: 22 | ||
| end: 44 | ||
| - source: (struct bf_chain *chain, struct bf_rule *rule) | ||
| style: secondary | ||
| start: 21 | ||
| end: 67 | ||
| - source: bf_chain_add_rule(struct bf_chain *chain, struct bf_rule *rule) | ||
| style: secondary | ||
| start: 4 | ||
| end: 67 | ||
| ? | | ||
| void bf_rule_free(struct bf_rule **rule) | ||
| { | ||
| return; | ||
| } | ||
| : labels: | ||
| - source: |- | ||
| void bf_rule_free(struct bf_rule **rule) | ||
| { | ||
| return; | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 56 | ||
| - source: '**rule' | ||
| style: secondary | ||
| start: 33 | ||
| end: 39 | ||
| - source: struct bf_rule **rule | ||
| style: secondary | ||
| start: 18 | ||
| end: 39 | ||
| - source: (struct bf_rule **rule) | ||
| style: secondary | ||
| start: 17 | ||
| end: 40 | ||
| - source: bf_rule_free(struct bf_rule **rule) | ||
| style: secondary | ||
| start: 5 | ||
| end: 40 |
30 changes: 30 additions & 0 deletions
30
tests/check/ast-grep/rule-tests/__snapshots__/bf-prefix-public-functions-snapshot.yml
This file contains hidden or 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,30 @@ | ||
| id: bf-prefix-public-functions | ||
| snapshots: | ||
| ? | | ||
| int my_func(void) | ||
| { | ||
| return 0; | ||
| } | ||
| : labels: | ||
| - source: |- | ||
| int my_func(void) | ||
| { | ||
| return 0; | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 35 | ||
| ? | | ||
| void process_packet(struct pkt *p) | ||
| { | ||
| return; | ||
| } | ||
| : labels: | ||
| - source: |- | ||
| void process_packet(struct pkt *p) | ||
| { | ||
| return; | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 50 |
24 changes: 24 additions & 0 deletions
24
tests/check/ast-grep/rule-tests/__snapshots__/double-pointer-output-snapshot.yml
This file contains hidden or 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,24 @@ | ||
| id: double-pointer-output | ||
| snapshots: | ||
| ? | | ||
| int bf_chain_new(struct bf_chain *chain) | ||
| { | ||
| return 0; | ||
| } | ||
| : labels: | ||
| - source: |- | ||
| int bf_chain_new(struct bf_chain *chain) | ||
| { | ||
| return 0; | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 58 | ||
| - source: bf_chain_new | ||
| style: secondary | ||
| start: 4 | ||
| end: 16 | ||
| - source: bf_chain_new(struct bf_chain *chain) | ||
| style: secondary | ||
| start: 4 | ||
| end: 40 |
36 changes: 36 additions & 0 deletions
36
tests/check/ast-grep/rule-tests/__snapshots__/doxygen-prefer-backticks-snapshot.yml
This file contains hidden or 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,36 @@ | ||
| id: doxygen-prefer-backticks | ||
| snapshots: | ||
| ? | | ||
| /** | ||
| * @brief Free a map object. | ||
| * | ||
| * @param map @ref bf_map object to free. | ||
| */ | ||
| void bf_map_free(struct bf_map **map); | ||
| : labels: | ||
| - source: |- | ||
| /** | ||
| * @brief Free a map object. | ||
| * | ||
| * @param map @ref bf_map object to free. | ||
| */ | ||
| style: primary | ||
| start: 0 | ||
| end: 81 | ||
| ? | | ||
| /** | ||
| * @brief Manage BPF object references. | ||
| * | ||
| * @ref bf_handle is used to manage references. | ||
| */ | ||
| int bf_handle_new(void); | ||
| : labels: | ||
| - source: |- | ||
| /** | ||
| * @brief Manage BPF object references. | ||
| * | ||
| * @ref bf_handle is used to manage references. | ||
| */ | ||
| style: primary | ||
| start: 0 | ||
| end: 98 |
17 changes: 17 additions & 0 deletions
17
tests/check/ast-grep/rule-tests/__snapshots__/doxygen-public-functions-snapshot.yml
This file contains hidden or 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,17 @@ | ||
| id: doxygen-public-functions | ||
| snapshots: | ||
| ? | | ||
| // This is not a Doxygen comment | ||
| int bf_set_add(struct bf_set *set, int value); | ||
| : labels: | ||
| - source: int bf_set_add(struct bf_set *set, int value); | ||
| style: primary | ||
| start: 33 | ||
| end: 79 | ||
| ? | | ||
| int bf_rule_free(void); | ||
| : labels: | ||
| - source: int bf_rule_free(void); | ||
| style: primary | ||
| start: 0 | ||
| end: 23 |
42 changes: 42 additions & 0 deletions
42
tests/check/ast-grep/rule-tests/__snapshots__/enum-bf-prefix-snapshot.yml
This file contains hidden or 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,42 @@ | ||
| id: enum-bf-prefix | ||
| snapshots: | ||
| ? | | ||
| enum filter_type | ||
| { | ||
| FILTER_ACCEPT, | ||
| _FILTER_MAX, | ||
| }; | ||
| : labels: | ||
| - source: |- | ||
| enum filter_type | ||
| { | ||
| FILTER_ACCEPT, | ||
| _FILTER_MAX, | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 56 | ||
| - source: filter_type | ||
| style: secondary | ||
| start: 5 | ||
| end: 16 | ||
| ? | | ||
| enum hook | ||
| { | ||
| HOOK_XDP, | ||
| _HOOK_MAX, | ||
| }; | ||
| : labels: | ||
| - source: |- | ||
| enum hook | ||
| { | ||
| HOOK_XDP, | ||
| _HOOK_MAX, | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 42 | ||
| - source: hook | ||
| style: secondary | ||
| start: 5 | ||
| end: 9 |
58 changes: 58 additions & 0 deletions
58
tests/check/ast-grep/rule-tests/__snapshots__/enum-sentinel-format-snapshot.yml
This file contains hidden or 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,58 @@ | ||
| id: enum-sentinel-format | ||
| snapshots: | ||
| ? | | ||
| enum bf_chain_type | ||
| { | ||
| BF_CHAIN_TYPE_FILTER, | ||
| BF_CHAIN_TYPE_NAT, | ||
| }; | ||
| : labels: | ||
| - source: |- | ||
| enum bf_chain_type | ||
| { | ||
| BF_CHAIN_TYPE_FILTER, | ||
| BF_CHAIN_TYPE_NAT, | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 71 | ||
| - source: bf_chain_type | ||
| style: secondary | ||
| start: 5 | ||
| end: 18 | ||
| - source: |- | ||
| { | ||
| BF_CHAIN_TYPE_FILTER, | ||
| BF_CHAIN_TYPE_NAT, | ||
| } | ||
| style: secondary | ||
| start: 19 | ||
| end: 71 | ||
| ? | | ||
| enum bf_hook | ||
| { | ||
| BF_HOOK_XDP, | ||
| BF_HOOK_TC_INGRESS, | ||
| }; | ||
| : labels: | ||
| - source: |- | ||
| enum bf_hook | ||
| { | ||
| BF_HOOK_XDP, | ||
| BF_HOOK_TC_INGRESS, | ||
| } | ||
| style: primary | ||
| start: 0 | ||
| end: 57 | ||
| - source: bf_hook | ||
| style: secondary | ||
| start: 5 | ||
| end: 12 | ||
| - source: |- | ||
| { | ||
| BF_HOOK_XDP, | ||
| BF_HOOK_TC_INGRESS, | ||
| } | ||
| style: secondary | ||
| start: 13 | ||
| end: 57 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude: suggestion:
ast-grep-cliis installed without a version pin (pipx install --global ast-grep-cli). A breaking change in ast-grep's rule syntax or--offflag behavior could cause CI failures across all branches simultaneously. Consider pinning to a specific version (e.g.pipx install --global ast-grep-cli==0.38.0) and updating periodically via a dedicated PR. Same applies to all other Dockerfiles (Fedora via pipx, Ubuntu via pip).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, it'd be nice to see failures introduced in new version immediately, not "whenever we remember to bump hardcoded versions". I think fetching the latest version should be fine.