Skip to content

Commit 5b75fe6

Browse files
author
Colin McNeil
committed
Scripts
1 parent 664eec4 commit 5b75fe6

File tree

9 files changed

+195
-9
lines changed

9 files changed

+195
-9
lines changed

prompts/eslint/scripts/lint-standardjs.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
PROJECT_DIR="/project"
44

5+
THREAD_DIR="/thread"
6+
57
# First arg
68
ARGS="$1"
79

@@ -25,13 +27,15 @@ fi
2527

2628
# If typescript is false, run standard
2729
if [ $TYPESCRIPT == 'false' ]; then
28-
$LINT_ARGS="$FILES"
30+
LINT_ARGS="$FILES"
2931
# If FIX
3032
if [ $FIX == "true" ]; then
3133
LINT_ARGS="--fix $FILES"
3234
fi
3335
# Pass files array as args to standard
34-
echo standard 2>/dev/null | standard-json | /remap_lint.sh "$OUTPUT_LEVEL"
36+
STANDARD_JSON=$(standard 2>/dev/null | standard-json)
37+
echo $STANDARD_JSON | /remap_lint.sh "$OUTPUT_LEVEL"
38+
echo $STANDARD_JSON > $THREAD_DIR/eslint.json
3539
exit $?
3640
fi
3741

@@ -66,7 +70,9 @@ for TS_ROOT in $TS_ROOTS; do
6670
else
6771
LINT_ARGS="$TS_FILES_IN_ROOT"
6872
fi
69-
TS_OUTPUT+=$(ts-standard 2>/dev/null | standard-json | /remap_lint.sh "$OUTPUT_LEVEL")
73+
TS_JSON=$(ts-standard 2>/dev/null | standard-json)
74+
echo $TS_JSON >> $THREAD_DIR/eslint.json
75+
TS_OUTPUT+=$($TS_JSON | /remap_lint.sh "$OUTPUT_LEVEL")
7076
# If ts-standard failed and EXIT_CODE is 0, set EXIT_CODE
7177
if [ $? -ne 0 ] && [ $EXIT_CODE -eq 0 ]; then
7278
EXIT_CODE=$?

prompts/eslint/scripts/lint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
PROJECT_DIR="/project"
44

5+
THREAD_DIR="/thread"
6+
57
# First arg
68
ARGS="$1"
79

@@ -30,4 +32,4 @@ echo "Running npx with args: $ARGS"
3032

3133
ESLINT_JSON=$(npx --no-install $ARGS )
3234

33-
echo $ESLINT_JSON | /remap_lint.sh "$OUTPUT_LEVEL"
35+
echo $ESLINT_JSON | /remap_lint.sh "$OUTPUT_LEVEL"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
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.
2+
3+
{>fixing}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1. Run ESLint summary in the project
1+
1. Run ESLint in the project
22
2. Evaluate total violations.
3-
<10 violations: Re-run eslint with complaints output.
4-
10+ violations: Re-run eslint with condensed output.
3+
<10 violations: Parse eslint with complaints output.
4+
10+ violations: Parse eslint with condensed output.
55
3. Fix the violations.

prompts/eslint_fix/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM alpine:3.20
2+
3+
RUN apk add --no-cache jq bash
4+
5+
COPY entrypoint.sh /entrypoint.sh
6+
7+
# Depends on eslint prompt sibling directory
8+
COPY scripts/remap_lint.sh /remap_lint.sh
9+
10+
RUN chmod +x /entrypoint.sh
11+
RUN chmod +x /remap_lint.sh
12+
13+
ENTRYPOINT ["/entrypoint.sh"]

prompts/eslint_fix/README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,33 @@ functions:
3131
description: "`condensed` or `complaints`"
3232
container:
3333
image: vonwig/read_eslint
34-
---
34+
- name: tree_sitter
35+
description: Gets the surrounding code block for a given line in a file
36+
parameters:
37+
type: object
38+
properties:
39+
path:
40+
type: string
41+
description: The filepath of the affected code
42+
line:
43+
type: number
44+
description: The affected line to load context from
45+
container:
46+
image: vonwig/tree_sitter
47+
---
48+
49+
```sh
50+
docker run --rm \
51+
-it \
52+
-v /var/run/docker.sock:/var/run/docker.sock \
53+
--mount type=bind,source=$PROMPTS_DIR,target=/app/eslint_fix \
54+
--workdir /app \
55+
--mount type=volume,source=docker-prompts,target=/prompts \
56+
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
57+
vonwig/prompts:latest \
58+
run \
59+
$PWD \
60+
$USER \
61+
"$(uname -o)" \
62+
eslint_fix
63+
```

prompts/eslint_fix/entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
ARGS_JSON=$1
4+
5+
THREAD_DIR="/thread"
6+
7+
# Check for eslint.json
8+
if [ ! -f $THREAD_DIR/eslint.json ]; then
9+
echo "No eslint.json found. Exiting."
10+
exit 0
11+
fi
12+
13+
# Get eslint.json
14+
ESLINT_JSON=$(cat $THREAD_DIR/eslint.json)
15+
16+
OUTPUT_LEVEL=$(echo $ARGS_JSON | jq -r '.outputLevel')
17+
18+
echo $ESLINT_JSON | /remap_lint.sh "$OUTPUT_LEVEL"

prompts/eslint_fix/fixing.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
5+
6+
You are able to fix the following violations:
7+
8+
constructor-super:
9+
no-compare-neg-0:
10+
no-const-assign
11+
no-control-regex
12+
no-debugger
13+
no-empty-character-classes
14+
no-empty-pattern
15+
no-new-native-constructors
16+
no-obj-calls
17+
no-self-assign
18+
getter-return
19+
no-async-promise-executer
20+
no-class-assign
21+
no-constant-binary-expression
22+
no-dupe-args
23+
no-dupe-else-if
24+
no-dupe-keys
25+
no-duplicate-case
26+
no-ex-assign
27+
no-func-assign
28+
no-import-assign
29+
no-irregular-whitespace
30+
no-loss-of-precision
31+
no-misleading-character-class
32+
no-this-before-super
33+
no-undef
34+
no-unexpected-multiline
35+
no-unreachable
36+
no-unsafe-finally
37+
no-unsafe-negation
38+
no-unused-private-class-members
39+
no-unused-vars
40+
no-useless-backreference
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Get piped stdin as input
4+
INPUT=$(cat)
5+
6+
OUTPUT="{}"
7+
8+
OUTPUT_MODE=$1 # summary, complaints, condensed, json
9+
10+
# If not set
11+
if [ -z "$OUTPUT_MODE" ]; then
12+
OUTPUT_MODE="summary"
13+
fi
14+
15+
FILE_PATHS=$(echo $INPUT | jq -r '.[].filePath')
16+
ALL_MESSAGES=$(echo $INPUT | jq -r -c '.[].messages')
17+
18+
# convert to array
19+
IFS=$'\n' FILE_PATHS=($FILE_PATHS)
20+
IFS=$'\n' ALL_MESSAGES=($ALL_MESSAGES)
21+
# Iterate over file paths
22+
for index in "${!FILE_PATHS[@]}"; do
23+
file_path=${FILE_PATHS[$index]}
24+
# Get the messages for the file path
25+
messages=${ALL_MESSAGES[$index]}
26+
27+
if [ $OUTPUT_MODE == "complaints" ]; then
28+
29+
# Complaint: {filePath: "path", "start": [line, column], "end": [line, column], "message": "message", "severity": "severity", "ruleId": "ruleId"}
30+
messages=$(echo $messages | jq -r -c '.[]' | tr '\n' ' ')
31+
IFS=$'\n' messages=($messages)
32+
for message in "${messages[@]}"; do
33+
# If endLine is null, set it to line
34+
message_parsed=$(echo $message | jq -r -c 'if .endLine == null then .endLine = .line end')
35+
# If endColumn is null, set it to convert column to number and add 1
36+
message_parsed=$(echo $message_parsed | jq -r -c 'if .endColumn == null then .endColumn = (.column | tonumber + 1) end')
37+
# If severity is null, set it to "error"
38+
message_parsed=$(echo $message_parsed | jq -r -c 'if .severity == null then .severity = "error" end')
39+
COMPLAINT=$(echo $message_parsed | jq -r -c --arg file_path $file_path '{filePath: $file_path, start: [.line, .column], end: [.endLine, .endColumn], message: .message, severity: .severity, ruleId: .ruleId}')
40+
echo $COMPLAINT
41+
done
42+
elif [ $OUTPUT_MODE == "condensed" ]; then
43+
# Remove duplicates
44+
messages=$(echo $messages | jq -r -c 'unique_by(.ruleId)')
45+
messages=$(echo $messages | jq -r -c '.[]')
46+
IFS=$'\n' messages=($messages)
47+
# Iterate over messages
48+
for message in "${messages[@]}"; do
49+
# Get the message id
50+
ID=$(echo $message | jq -r '.ruleId')
51+
52+
# If the OUTPUT[id] is null, set it to empty array
53+
if [[ $(echo $VIOLATIONS_BY_ID | jq -r "has(\"$ID\")") == 'false' ]]; then
54+
OUTPUT=$(echo $OUTPUT | jq --arg id "$ID" '.[$id] = []')
55+
fi
56+
# Add the fileid to the violations object key
57+
OUTPUT=$(echo $OUTPUT | jq --arg id "$ID" --arg file_path "$file_path" '.[$id] += [$file_path]')
58+
done
59+
elif [ $OUTPUT_MODE == "json" ]; then
60+
OUTPUT=$(echo $INPUT)
61+
else
62+
# Summary
63+
AFFECTED_FILE_COUNT=$(echo $INPUT | jq -r 'length')
64+
TOTAL_VIOLATION_COUNT=$(echo $INPUT | jq -r '.[].messages | length' | jq -s add)
65+
66+
if [[ $TOTAL_VIOLATION_COUNT -gt 0 ]]; then
67+
OUTPUT="Found $TOTAL_VIOLATION_COUNT violations in $AFFECTED_FILE_COUNT files."
68+
else
69+
OUTPUT="No violations found."
70+
fi
71+
fi
72+
done
73+
74+
echo $OUTPUT
75+
76+
exit 0

0 commit comments

Comments
 (0)