@codacy/tools-opengrep-1 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codacy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @codacy/tools-opengrep-1
2
+
3
+ ## Table of Contents
4
+ - [Overview](#overview)
5
+ - [Rule bundling](#rule-bundling)
6
+ - [Updating patterns](#updating-patterns)
7
+ - [Updating rules](#updating-rules)
8
+ - [Updating the Opengrep version](#updating-the-opengrep-version)
9
+ - [Development](#development)
10
+ - [Notes for maintainers](#notes-for-maintainers)
11
+
12
+ ---
13
+
14
+ ## Overview
15
+
16
+ Multi-language SAST (Static Application Security Testing) scanner using the [Opengrep](https://opengrep.dev/) binary. Supports 30+ languages via YAML rule files. Uses the CLI execution strategy.
17
+
18
+ | Property | Value |
19
+ |----------|-------|
20
+ | Tool ID | `Semgrep` (legacy, for Codacy platform compatibility) |
21
+ | Display name | `Opengrep` |
22
+ | Codacy UUID | `6792c561-236d-41b7-ba5e-9d6bee0d548b` |
23
+ | Strategy | CLI |
24
+ | Languages | 30+ (Python, JavaScript, TypeScript, Java, Go, Ruby, C, C++, etc.) |
25
+ | Binary | `opengrep` |
26
+ | File patterns | `*` (auto-detects by language) |
27
+ | Pattern count | ~2500 |
28
+ | Extra dependency | `yaml` (for YAML rule config parsing/generation) |
29
+
30
+ ## Rule bundling
31
+
32
+ Opengrep uses YAML rule files for detection. The adapter bundles ~2200 rules into `src/rules.yaml`, sourced from:
33
+
34
+ 1. **semgrep/semgrep-rules** — community rules (pinned at commit `4ccd3b9`)
35
+ 2. **GitLab SAST rules** — MIT-licensed rules from `gitlab.com/gitlab-org/security-products/sast-rules`
36
+ 3. **Codacy custom rules** — from `codacy/codacy-opengrep` wrapper repo
37
+
38
+ The bundled `src/rules.yaml` is **committed to the repository** for consistency and reproducibility.
39
+
40
+ ## Updating patterns
41
+
42
+ ```bash
43
+ # Re-fetch pattern metadata from the Codacy API
44
+ pnpm prefetch
45
+
46
+ # Commit the result
47
+ git add src/patterns.json
48
+ ```
49
+
50
+ Pattern IDs follow the format `Semgrep_python.lang.security.audit.exec-detected.exec-detected` (dot-separated rule paths).
51
+
52
+ ## Updating rules
53
+
54
+ ```bash
55
+ # Re-fetch and bundle rules from all three sources
56
+ pnpm fetch-rules
57
+
58
+ # This clones the rule repos, extracts matching rules, and writes src/rules.yaml
59
+ # Only rules whose IDs match src/patterns.json are included
60
+
61
+ # Commit the result
62
+ git add src/rules.yaml
63
+ ```
64
+
65
+ The `fetch-rules` script (`scripts/fetch-rules.mjs`):
66
+ - Clones `semgrep/semgrep-rules` at the pinned commit
67
+ - Clones GitLab SAST rules (latest)
68
+ - Clones `codacy/codacy-opengrep` for custom rules
69
+ - Extracts rules, assigns path-based IDs
70
+ - Filters to only rules matching `src/patterns.json`
71
+ - Writes concatenated YAML to `src/rules.yaml`
72
+
73
+ To update the pinned semgrep-rules commit, edit `SEMGREP_RULES_COMMIT` in `scripts/fetch-rules.mjs`.
74
+
75
+ ## Updating the Opengrep version
76
+
77
+ 1. Update `preferredVersion` in `src/adapter.ts`
78
+ 2. Run `pnpm test` to verify compatibility
79
+ 3. Consider re-running `pnpm fetch-rules` if the new version supports new rule syntax
80
+
81
+ ## Development
82
+
83
+ ```bash
84
+ pnpm build # Build with tsup
85
+ pnpm test # Run tests (requires opengrep in PATH)
86
+ pnpm fetch-rules # Re-bundle rules from upstream sources
87
+ pnpm prefetch # Re-fetch pattern metadata from Codacy API
88
+ ```
89
+
90
+ **Opengrep must be installed manually:**
91
+ ```bash
92
+ curl -fsSL https://raw.githubusercontent.com/opengrep/opengrep/main/install.sh | bash
93
+ ```
94
+
95
+ ## Notes for maintainers
96
+
97
+ - **Tool ID is `Semgrep`** for legacy compatibility with the Codacy platform. The `displayName` is set to `Opengrep` for CLI display. Never change the tool ID without coordinating with the Codacy platform team.
98
+ - **Config materialization**: When Codacy patterns are specified, the adapter loads `src/rules.yaml`, filters to enabled rules, and writes a filtered config to `.codacy/generated/opengrep-rules.yaml`.
99
+ - **check_id prefix stripping**: Opengrep prepends a path-based namespace to check_ids derived from the config file path relative to cwd. The adapter computes and strips this prefix (e.g. `codacy.generated.`) plus any `tmp.` legacy prefix.
100
+ - **Config file search**: `.semgrep.yaml`, `.opengrep.yaml`, `.semgrep.yml`, `.opengrep.yml` (in that order).
101
+ - **Opengrep errors**: Parse errors (syntax errors, partial parsing) from Opengrep's JSON `errors` array are converted to structured `AnalysisError` objects with `filePath`. Stderr (scan status table) is logged at debug level only.
102
+ - **Rule ID format**: Semgrep-rules use `{dir}.{filename}.{ruleId}` (dots), GitLab rules use `{dir}_{filename}` (underscores), Codacy custom rules keep their original IDs.
@@ -0,0 +1,5 @@
1
+ import * as _codacy_tooling from '@codacy/tooling';
2
+
3
+ declare const _default: Readonly<_codacy_tooling.ToolAdapter>;
4
+
5
+ export { _default as default };