Skip to content

Commit 972b267

Browse files
committed
Make semgrep helper script easier to use in different situations. Add missing id
1 parent 9a8ba05 commit 972b267

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
rules:
2+
- id: directory-entry-wrong-extension
3+
languages: [generic]
4+
message: >-
5+
Directory entry files must use the .yaml extension, not .yml.
6+
Rename this file to use .yaml instead.
7+
(add [skip style guide checks] to commit message to skip)
8+
severity: MEDIUM
9+
paths:
10+
include:
11+
- "/src/content/directory/*.yml"
12+
patterns:
13+
# Match the name field — every directory entry has one, so this fires
14+
# once per .yml file to flag the wrong extension.
15+
- pattern-regex: "^name: "
16+
17+
- id: directory-entry-missing-id
18+
languages: [yaml]
19+
message: >-
20+
Directory entry is missing a required id field.
21+
Run tools/directory-entry-ids to generate one automatically.
22+
(add [skip style guide checks] to commit message to skip)
23+
severity: MEDIUM
24+
paths:
25+
include:
26+
- "/src/content/directory/*.yaml"
27+
- "/src/content/directory/*.yml"
28+
patterns:
29+
- pattern: |
30+
name: $NAME
31+
- pattern-not-inside: |
32+
id: ...
33+
...
34+
35+
- id: directory-entry-invalid-id
36+
languages: [generic]
37+
message: >-
38+
Directory entry has an invalid id. The id must be exactly 6 characters
39+
composed only of: abcdefghijkmnopqrstuvwxyzACDEFGHJKLMNPQRTUVWXY34679.
40+
Run tools/directory-entry-ids to generate a valid id.
41+
(add [skip style guide checks] to commit message to skip)
42+
severity: MEDIUM
43+
paths:
44+
include:
45+
- "/src/content/directory/*.yaml"
46+
- "/src/content/directory/*.yml"
47+
patterns:
48+
- pattern-regex: "^id: "
49+
- pattern-not-regex: "^id: [abcdefghijkmnopqrstuvwxyzACDEFGHJKLMNPQRTUVWXY34679]{6}$"

src/content/directory/cloudflare-agent.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
id: kj7Wuc
12

23
name: Cloudflare Agent
34
entry:

tools/semgrep-repo-rules

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@ repo_root_dir="$(git rev-parse --show-toplevel)"
55

66
pushd "${repo_root_dir}" > /dev/null || return
77

8+
scan_all=false
9+
scan_path=""
10+
while [[ $# -gt 0 ]]; do
11+
case "$1" in
12+
--all) scan_all=true; shift ;;
13+
--path) scan_path="$2"; shift 2 ;;
14+
*) shift ;;
15+
esac
16+
done
17+
18+
if [ -n "$scan_path" ]; then
19+
echo "Scanning all files in ${scan_path}..."
20+
docker run --rm -v "${PWD}:/src" semgrep/semgrep \
21+
semgrep scan \
22+
--config .semgrep --metrics=off \
23+
--include "*.mdx" --include "*.md" --include "*.html" --include "*.htm" --include "*.yaml" --include "*.yml" \
24+
--error \
25+
"$scan_path"
26+
semgrep_return_code=$?
27+
echo "return code: $semgrep_return_code"
28+
exit $semgrep_return_code
29+
fi
30+
31+
if [ "$scan_all" = true ]; then
32+
echo "Scanning all files..."
33+
docker run --rm -v "${PWD}:/src" semgrep/semgrep \
34+
semgrep scan \
35+
--config .semgrep --metrics=off \
36+
--include "*.mdx" --include "*.md" --include "*.html" --include "*.htm" --include "*.yaml" --include "*.yml" \
37+
--error
38+
semgrep_return_code=$?
39+
echo "return code: $semgrep_return_code"
40+
exit $semgrep_return_code
41+
fi
42+
843
base_commit=$(git merge-base HEAD origin/production)
944
git diff $base_commit... --diff-filter=ACMRT --name-only | grep -E '\.(htm|html|yaml|yml|md|mdx)$' > tools/relevant_changed_files.txt || true
1045

0 commit comments

Comments
 (0)