File tree Expand file tree Collapse file tree 9 files changed +69
-31
lines changed
Expand file tree Collapse file tree 9 files changed +69
-31
lines changed Original file line number Diff line number Diff line change @@ -15,4 +15,4 @@ FROM node:alpine3.20
1515COPY main.js /main.js
1616COPY --from=build /tree-sitter/node_modules /node_modules
1717
18- ENTRYPOINT [ "node" , "main.js" ]
18+ ENTRYPOINT [ "node" , "/ main.js" ]
Original file line number Diff line number Diff line change 11#! /bin/bash
22
3+
34PROJECT_DIR=" /project"
45
56THREAD_DIR=" /thread"
@@ -9,6 +10,8 @@ ARGS="$1"
910
1011# args[eslint_args] args [eslint_version]
1112
13+ set -f
14+ # Without pathname expansion
1215ESLINT_ARGS=$( echo $ARGS | jq -r ' .args' )
1316
1417ESLINT_VERSION=$( echo $ARGS | jq -r ' .version' )
@@ -33,3 +36,10 @@ echo "Running npx with args: $ARGS"
3336ESLINT_JSON=$( npx --no-install $ARGS )
3437
3538echo $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+
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ AFFECTED_FILE_COUNT=$(echo $INPUT | jq -r 'length')
2323# Iterate over file paths
2424for 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
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 11---
22functions :
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---
Original file line number Diff line number Diff line change 1313# Get eslint.json
1414ESLINT_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+
1619OUTPUT_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
1832echo $ESLINT_JSON | /remap_lint.sh " $OUTPUT_LEVEL "
Original file line number Diff line number Diff line change 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
615You are able to fix the following violations:
716
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ IFS=$'\n' ALL_MESSAGES=($ALL_MESSAGES)
2121# Iterate over file paths
2222for 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
You can’t perform that action at this time.
0 commit comments