Skip to content

Commit 59a3151

Browse files
authored
add info about local rules' IDs (#2343)
1 parent 872335b commit 59a3151

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/running-rules.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Rules can be organized in **rulesets**. Rulesets are rules related through a pro
2222

2323
The list below covers different kinds of Semgrep rules:
2424

25-
- Existing [Semgrep Registry rules](#running-semgrep-registry-rules-locally). You can also contribute to the open source Semgrep Registry, see [Contributing rules](/contributing/contributing-to-semgrep-rules-repository).
26-
- [Local rules](#creating-and-using-local-rules):
25+
- Existing [Semgrep Registry rules](#run-semgrep-registry-rules-locally). You can also contribute to the open source Semgrep Registry, see [Contributing rules](/contributing/contributing-to-semgrep-rules-repository).
26+
- [Local rules](#create-and-use-local-rules):
2727
- One-off [ephemeral rules](#ephemeral-rules) passed into the command line.
2828
- [YAML-defined rules](#yaml-defined-rules).
29-
- A combination of [local rules and Semgrep Registry rules](#running-multiple-rules-simultaneously) or a combination of multiple rules in general.
29+
- A combination of [local rules and Semgrep Registry rules](#run-multiple-rules-simultaneously) or a combination of multiple rules in general.
3030

31-
## Running Semgrep Registry rules locally
31+
## Run Semgrep Registry rules locally
3232

3333
You can run a SAST scan in your Git environment with pre-selected Semgrep Registry rules:
3434

@@ -55,15 +55,21 @@ To use Semgrep Registry continuously in your CI/CD pipeline, see the [Semgrep in
5555
5656
-->
5757

58-
## Creating and using local rules
58+
## Create and use local rules
5959

6060
Local rules can be either:
6161

6262
- [Ephemeral rules](#ephemeral-rules) with the `-e` or `--pattern` flags for use in a single command.
6363
- Configured in [YAML rule files](#yaml-defined-rules) that conform to the [Rule syntax](/writing-rules/rule-syntax) schema.
6464

65-
:::tip
66-
See [Writing rules > Getting started](/writing-rules/overview/) to learn how to write rules.
65+
To learn how to write rules, see [Writing rules > Getting started](/writing-rules/overview/).
66+
67+
:::info Rule IDs of local rules
68+
Semgrep prefixes the rule IDs of local rules with a custom value it generates using the following steps:
69+
70+
1. Get the relative path from the current working directory of the process to the directory of the rules file.
71+
2. Replace the directory separators of the relative path with dots.
72+
3. Remove any characters not allowed in a rule ID from the relative path.
6773
:::
6874

6975
### Ephemeral rules
@@ -101,7 +107,7 @@ Rules stored under a hidden directory, such as `dir/.hidden/myrule.yml`, are pro
101107

102108
For more information on defining custom rules, see [Writing rules](/writing-rules/overview/).
103109

104-
## Running multiple rules simultaneously
110+
## Run multiple rules simultaneously
105111

106112
To run multiple rules simultaneously, use `--config` before every YAML URL, or Semgrep registry entry name. This option lets you include your local rules as well as Semgrep Registry rules. See the following code example (substitute the colored values as necessary):
107113

0 commit comments

Comments
 (0)