Skip to content

Commit 78f3ef1

Browse files
committed
add patterns editing
1 parent d41ed3d commit 78f3ef1

File tree

13 files changed

+2039
-0
lines changed

13 files changed

+2039
-0
lines changed

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,86 @@ With `--issue <id>`: shows full detail for that issue (code context + pattern do
251251

252252
With `--diff`: shows the annotated git diff — only blocks containing covered/uncovered lines or new issues, with 3 lines of context around each. Coverage is shown with ✓ (green, covered) and ✘ (red, uncovered) symbols; issues are annotated inline with severity, category, and message.
253253

254+
#### `tools <provider> <organization> <repository>`
255+
256+
List all analysis tools configured for a repository with their status.
257+
258+
```bash
259+
codacy tools gh my-org my-repo
260+
codacy tools gh my-org my-repo --output json
261+
```
262+
263+
Displays tools grouped into **Enabled** and **Disabled** sections. For each tool:
264+
- **Config File**`Applied` (config file detected and in use), `Available` (detected but not used), or `Not Available`
265+
- **Via Standard** — name of any Coding Standard that enabled the tool
266+
- **Notes**`Client-side tool` for tools that run locally
267+
268+
#### `tool <provider> <organization> <repository> <toolName>`
269+
270+
Enable, disable, or configure an analysis tool for a repository.
271+
272+
```bash
273+
codacy tool gh my-org my-repo eslint --enable
274+
codacy tool gh my-org my-repo eslint --disable
275+
codacy tool gh my-org my-repo eslint --configuration-file true
276+
codacy tool gh my-org my-repo eslint --enable --configuration-file true
277+
```
278+
279+
| Argument | Description |
280+
|---|---|
281+
| `toolName` | Tool name (use hyphens for spaces, e.g. `eslint-(deprecated)`) |
282+
283+
| Option | Description |
284+
|---|---|
285+
| `-e, --enable` | Enable the tool |
286+
| `-d, --disable` | Disable the tool |
287+
| `-c, --configuration-file <true/false>` | Set whether the tool uses a configuration file |
288+
289+
Tool names are matched by best-fit: `eslint` matches "ESLint" but not "ESLint9" or "ESLint (deprecated)"; `eslint-(deprecated)` matches "ESLint (deprecated)".
290+
291+
#### `patterns <provider> <organization> <repository> <toolName>`
292+
293+
List all patterns for an analysis tool in a repository with their status and configuration.
294+
295+
```bash
296+
codacy patterns gh my-org my-repo eslint
297+
codacy patterns gh my-org my-repo eslint --enabled --categories Security
298+
codacy patterns gh my-org my-repo eslint --severities Critical,High --search "sql injection"
299+
codacy patterns gh my-org my-repo eslint --output json
300+
```
301+
302+
| Option | Description |
303+
|---|---|
304+
| `-l, --languages <languages>` | Comma-separated list of languages |
305+
| `-C, --categories <categories>` | Comma-separated list of categories |
306+
| `-s, --severities <severities>` | Comma-separated severity levels: `Critical`, `High`, `Medium`, `Minor` |
307+
| `-t, --tags <tags>` | Comma-separated list of tags |
308+
| `-q, --search <search>` | Search term to filter patterns |
309+
| `-e, --enabled` | Show only enabled patterns |
310+
| `-D, --disabled` | Show only disabled patterns |
311+
| `-r, --recommended` | Show only recommended patterns |
312+
313+
Displays patterns as cards sorted by severity (Critical first), then recommended first, then alphabetically. Each card shows severity, category, description, rationale, solution, and active parameter values.
314+
315+
#### `pattern <provider> <organization> <repository> <toolName> <patternId>`
316+
317+
Enable, disable, or set parameters for a specific analysis pattern.
318+
319+
```bash
320+
codacy pattern gh my-org my-repo eslint no-unused-vars --enable
321+
codacy pattern gh my-org my-repo eslint no-unused-vars --disable
322+
codacy pattern gh my-org my-repo eslint max-len --parameter max=120
323+
codacy pattern gh my-org my-repo eslint max-len --enable --parameter max=120 --parameter tabWidth=2
324+
```
325+
326+
| Option | Description |
327+
|---|---|
328+
| `-e, --enable` | Enable the pattern |
329+
| `-d, --disable` | Disable the pattern |
330+
| `-p, --parameter <name=value>` | Set a parameter value (`name=value` format, repeatable) |
331+
332+
When only `--parameter` is used (without `--enable` or `--disable`), the current enabled state of the pattern is preserved automatically.
333+
254334
## Development
255335

256336
```bash

SPECS/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ _No pending tasks._
2020
| `issue` | `iss` | ✅ Done | [issue.md](commands/issue.md) |
2121
| `findings` | `fins` | ✅ Done | [findings.md](commands/findings.md) |
2222
| `finding` | `fin` | ✅ Done (CVE enrichment included) | [finding.md](commands/finding.md) |
23+
| `tools` | `tls` | ✅ Done | [tools-and-patterns.md](commands/tools-and-patterns.md) |
24+
| `tool` | `tl` | ✅ Done | [tools-and-patterns.md](commands/tools-and-patterns.md) |
25+
| `patterns` | `pats` | ✅ Done | [tools-and-patterns.md](commands/tools-and-patterns.md) |
26+
| `pattern` | `pat` | ✅ Done | [tools-and-patterns.md](commands/tools-and-patterns.md) |
2327

2428
## Other Specs
2529

@@ -50,3 +54,4 @@ _No pending tasks._
5054
| 2026-02-24 | SPECS folder created — TODO.md split into `SPECS/README.md` + per-command specs + setup/deployment |
5155
| 2026-02-25 | `pull-request --diff` option + Diff Coverage Summary section (6 new tests, 108 total) |
5256
| 2026-02-25 | `repository` actions: `--add`, `--remove`, `--follow`, `--unfollow` (4 new tests, 112 total) |
57+
| 2026-02-25 | `tools`, `tool`, `patterns`, `pattern` commands + tests (35 new tests, 147 total); `findToolByName` helper added to `utils/formatting.ts` |
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# `tools` Command Spec
2+
3+
## Purpose
4+
List all tools available for a repository and their status (enabled/disabled, using configuration file or not)
5+
6+
7+
## Usage
8+
```
9+
codacy tools <provider> <organization> <repository>
10+
codacy tools gh my-org my-repo --output json
11+
```
12+
13+
## API Endpoints
14+
- [`listRepositoryTools`](https://api.codacy.com/api/api-docs#listrepositorytools)
15+
16+
## Considerations
17+
- Tools can be enabled by users for that specific repository, or by an applied Coding Standard.
18+
- Tools may support local configuration files; if so, they would indicate if a configuration file was detected and if it is being used.
19+
20+
21+
## Output
22+
23+
List first all enabled tools for the repository (under a title "✅ Enabled tools"), then all disabled tools for the repository (under a title "❌ Disabled tools").
24+
25+
For each tool, show the following information:
26+
- Tool name
27+
- If enabled in a Coding Standard, show the Coding Standard name
28+
- Tool configuration file status (Available, Not Available, Applied)
29+
- Notes
30+
- if the tool is client-side, show 'Client-side tool'
31+
32+
# `tool` Command Spec
33+
## Purpose
34+
Enable or disable a specific tool for a repository.
35+
36+
## Usage
37+
```
38+
codacy tool <provider> <organization> <repository> <tool name> --enable
39+
codacy tool <provider> <organization> <repository> <tool name> --disable
40+
codacy tool <provider> <organization> <repository> <tool name> --configuration-file true
41+
```
42+
43+
### Options
44+
- `--enable, -e`
45+
- `--disable, -d`
46+
- `--configuration-file, -cf <true/false>`
47+
48+
### Output
49+
If successful, return a success message with the action taken ("Tool X enabled", "Tool X uses now a configuration file", etc). Otherwise, return an error message with the error details provided by the API.
50+
51+
52+
## API Endpoints
53+
- [`configureTool`](https://api.codacy.com/api/api-docs#configuretool)
54+
55+
## Considerations
56+
The API expects a tool UUID, not the tool name, so we need to fetch the tool UUID first. We can do this by calling the [`listRepositoryTools`](https://api.codacy.com/api/api-docs#listrepositorytools) API endpoint. We should match the tool name by "best match" using the `name` field.
57+
58+
e.g.
59+
- for `trivy`, we'll match the tool called "Trivy"
60+
- for `eslint`, we'll match the tool called "ESLint", but not the tool called "ESLint (deprecated)" nor the tool called "ESLint9"
61+
- for `jackson`, we'll match the tool called "Jackson Linter"
62+
- to match a tool with spaces in the name, the user needs to replace the spaces with a hyphen `-`; e.g. `eslint-(deprecated)` should match the tool called "ESLint (deprecated)"
63+
64+
65+
66+
# `patterns` Command Spec
67+
68+
## Purpose
69+
List all tool patterns for a repository and their status (enabled/disabled, parameters)
70+
71+
## Options
72+
- `--languages <languages>`
73+
- `--categories <categories>`
74+
- `--severities <severities>`
75+
- `--tags <tags>`
76+
- `--search <search>`
77+
- `--enabled`
78+
- `--disabled`
79+
- `--recommended`
80+
81+
## Usage
82+
```
83+
codacy patterns <provider> <organization> <repository> <tool name>
84+
codacy patterns gh my-org my-repo eslint
85+
codacy patterns gh my-org my-repo eslint ---categories security,errorprone --severities critical,high --search "sql injection" --disabled --recommended
86+
```
87+
88+
## API Endpoints
89+
- [`listRepositoryTools`](https://api.codacy.com/api/api-docs#listrepositorytools)
90+
- [`listRepositoryToolPatterns`](https://api.codacy.com/api/api-docs#listrepositorytoolpatterns)
91+
92+
## Considerations
93+
Have the same considerations described in the `tool` command spec about matching the tool name.
94+
95+
96+
## Output
97+
Instead of a table, show a card-style format for each pattern.
98+
```
99+
────────────────────────────────────────
100+
{✅/❌} {Title in white if enabled, gray if disabled} ({id in dark gray}) | {Recommended? in purple}
101+
{Severity colored} | {Category} {SubCategory?} | {Languages} | {Tags}
102+
{Description}
103+
104+
Why? {Rationale}
105+
How to fix? {Solution}
106+
107+
<IF THERE ARE PARAMETERS SET AND PATTERN IS ENABLED>
108+
Parameters:
109+
- {Parameter name} = {Parameter value}
110+
...
111+
</IF THERE ARE PARAMETERS SET AND PATTERN IS ENABLED>
112+
────────────────────────────────────────
113+
```
114+
115+
- "Why?" and "How to fix?" should be in white; their content should be in dim gray
116+
- Sort the results by severity (Critical > High > Medium > Minor), then by recommended (true > false), then by title alphabetically
117+
- As with other commands, if the results return more than 100 items, show a pagination warning and suggest filters to use.
118+
119+
120+
#`pattern` Command Spec
121+
## Purpose
122+
Enable or disable a specific pattern for a repository, and set its parameters if available.
123+
124+
## Usage
125+
```
126+
codacy pattern <provider> <organization> <repository> <tool name> <pattern id> --enable
127+
codacy pattern <provider> <organization> <repository> <tool name> <pattern id> --disable
128+
codacy pattern <provider> <organization> <repository> <tool name> <pattern id> --parameter <parameter name> <parameter value>
129+
```
130+
131+
### Options
132+
- `--enable, -e`
133+
- `--disable, -d`
134+
- `--parameter, -p <parameter name> <parameter value>`
135+
136+
## API Endpoints
137+
- [`configureTool`](https://api.codacy.com/api/api-docs#configuretool)
138+
139+
## Considerations
140+
Have the same considerations described in the `tool` command spec about matching the tool name.

0 commit comments

Comments
 (0)