Skip to content

Commit 02393a9

Browse files
author
Colin McNeil
committed
Single violation
1 parent 5b75fe6 commit 02393a9

File tree

9 files changed

+69
-31
lines changed

9 files changed

+69
-31
lines changed

functions/tree_sitter/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ FROM node:alpine3.20
1515
COPY main.js /main.js
1616
COPY --from=build /tree-sitter/node_modules /node_modules
1717

18-
ENTRYPOINT [ "node", "main.js" ]
18+
ENTRYPOINT [ "node", "/main.js" ]

prompts/eslint/scripts/lint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
34
PROJECT_DIR="/project"
45

56
THREAD_DIR="/thread"
@@ -9,6 +10,8 @@ ARGS="$1"
910

1011
# args[eslint_args] args [eslint_version]
1112

13+
set -f
14+
# Without pathname expansion
1215
ESLINT_ARGS=$(echo $ARGS | jq -r '.args')
1316

1417
ESLINT_VERSION=$(echo $ARGS | jq -r '.version')
@@ -33,3 +36,10 @@ echo "Running npx with args: $ARGS"
3336
ESLINT_JSON=$(npx --no-install $ARGS )
3437

3538
echo $ESLINT_JSON | /remap_lint.sh "$OUTPUT_LEVEL"
39+
echo $ESLINT_JSON > $THREAD_DIR/eslint.json
40+
41+
# If --fix is in args, copy the files back to the project directory
42+
if [[ $ESLINT_ARGS == *"--fix"* ]]; then
43+
cp -r $TEMP_DIR/. $PROJECT_DIR
44+
fi
45+

prompts/eslint/scripts/remap_lint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ AFFECTED_FILE_COUNT=$(echo $INPUT | jq -r 'length')
2323
# Iterate over file paths
2424
for index in "${!FILE_PATHS[@]}"; do
2525
file_path=${FILE_PATHS[$index]}
26+
# Strip $TEMP_DIR from the path
27+
file_path=$(echo $file_path | sed "s/\/eslint-temp\///g")
2628
# Get the messages for the file path
2729
messages=${ALL_MESSAGES[$index]}
2830

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
You are an AI assistant who specializes in resolving lint violations in projects.
1+
You are an AI assistant who specializes in resolving lint violations in projects. Use the tools available to quickly take action and be very brief.
2+
3+
1. Run lint.
4+
2. Evaluate total violations.
5+
<10 violations: Parse output with complaints output.
6+
10+ violations: Parse output with condensed output.
7+
3. Fix the violations using the following steps:
8+
9+
## Condensed:
10+
11+
For each file:
212

313
{>fixing}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
1. Run ESLint in the project
2-
2. Evaluate total violations.
3-
<10 violations: Parse eslint with complaints output.
4-
10+ violations: Parse eslint with condensed output.
5-
3. Fix the violations.
1+
Fix any lint violations you can using the tools provided.

prompts/eslint_fix/README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
---
22
functions:
3-
- name: eslint
3+
- name: run_lint
44
type: prompt
55
ref: github:docker/labs-ai-tools-for-devs?ref=main&path=prompts/eslint
6-
- name: write_files
7-
description: Write a set of files to my project
6+
- name: parse_lint_results
7+
description: Loads lint violations grouped by type.
88
parameters:
99
type: object
1010
properties:
11-
files:
12-
type: array
13-
items:
14-
type: object
15-
properties:
16-
path:
17-
type: string
18-
description: the relative path to the file that the script should run in
19-
script:
11+
outputLevel:
2012
type: string
21-
description: The script to run in the files.
13+
description: Supports `condensed` or `complaints`
2214
container:
23-
image: vonwig/apply_script:latest
24-
- name: read_eslint
25-
description: Loads ESLint violations
15+
image: vonwig/read_eslint
16+
- name: violations_for_file
17+
description: Loads lint violations for a file.
2618
parameters:
2719
type: object
2820
properties:
29-
output_level:
21+
path:
3022
type: string
31-
description: "`condensed` or `complaints`"
23+
description: Path to read violations for. Useful for getting line numbers. Always uses full `json` output level for most context.
3224
container:
3325
image: vonwig/read_eslint
34-
- name: tree_sitter
35-
description: Gets the surrounding code block for a given line in a file
26+
- name: run_tree_sitter
27+
description: Gets context from source code for a given line.
3628
parameters:
3729
type: object
3830
properties:
@@ -42,6 +34,9 @@ functions:
4234
line:
4335
type: number
4436
description: The affected line to load context from
37+
required:
38+
- path
39+
- line
4540
container:
4641
image: vonwig/tree_sitter
4742
---

prompts/eslint_fix/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ fi
1313
# Get eslint.json
1414
ESLINT_JSON=$(cat $THREAD_DIR/eslint.json)
1515

16+
# Replace all eslint-temp with empty string
17+
ESLINT_JSON=$(echo $ESLINT_JSON | sed 's/\/eslint-temp\///g')
18+
1619
OUTPUT_LEVEL=$(echo $ARGS_JSON | jq -r '.outputLevel')
20+
FILEPATH=$(echo $ARGS_JSON | jq -r '.path')
21+
# If path is not null
22+
if [ "$FILEPATH" != "null" ]; then
23+
echo "Getting eslint.json for path: $FILEPATH"
24+
ESLINT_JSON_FOR_PATH=$(echo $ESLINT_JSON | jq -r --arg path "$FILEPATH" '.[] | select(.filePath == $path)')
25+
echo "ESLint violations for $FILEPATH:"
26+
# Strip source key if it exists
27+
ESLINT_JSON_FOR_PATH=$(echo $ESLINT_JSON_FOR_PATH | jq -r 'del(.source)')
28+
echo $ESLINT_JSON_FOR_PATH
29+
exit 0
30+
fi
1731

1832
echo $ESLINT_JSON | /remap_lint.sh "$OUTPUT_LEVEL"

prompts/eslint_fix/fixing.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
To fix a violation:
2-
1. Take filepath of violation
3-
2. Use tree_sitter with the filepath and line number to get the code to correct
4-
3. Make the correction
1+
1. **Get the line**: Use read_eslint with the `path` arg to get all of the violations for a file.
2+
2. **Get the code**: Use tree_sitter with the path and line to read the surrounding code if necessary. Repeat for all violations in the file.
3+
3. **Make the correction** Respond in the following format:
4+
5+
```json
6+
{
7+
"start": [1, 4],
8+
"end": [2, 4],
9+
"edit": "Lorem ipsum"
10+
}
11+
```
12+
13+
Once you have fixed one file, move on to the next.
514

615
You are able to fix the following violations:
716

prompts/eslint_fix/scripts/remap_lint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ IFS=$'\n' ALL_MESSAGES=($ALL_MESSAGES)
2121
# Iterate over file paths
2222
for index in "${!FILE_PATHS[@]}"; do
2323
file_path=${FILE_PATHS[$index]}
24+
# Strip /eslint-temp
25+
file_path=$(echo $file_path | sed 's/\/eslint-temp\///g')
2426
# Get the messages for the file path
2527
messages=${ALL_MESSAGES[$index]}
2628

0 commit comments

Comments
 (0)