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
15
15
COPY main.js /main.js
16
16
COPY --from=build /tree-sitter/node_modules /node_modules
17
17
18
- ENTRYPOINT [ "node" , "main.js" ]
18
+ ENTRYPOINT [ "node" , "/ main.js" ]
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
3
+
3
4
PROJECT_DIR=" /project"
4
5
5
6
THREAD_DIR=" /thread"
@@ -9,6 +10,8 @@ ARGS="$1"
9
10
10
11
# args[eslint_args] args [eslint_version]
11
12
13
+ set -f
14
+ # Without pathname expansion
12
15
ESLINT_ARGS=$( echo $ARGS | jq -r ' .args' )
13
16
14
17
ESLINT_VERSION=$( echo $ARGS | jq -r ' .version' )
@@ -33,3 +36,10 @@ echo "Running npx with args: $ARGS"
33
36
ESLINT_JSON=$( npx --no-install $ARGS )
34
37
35
38
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
+
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ AFFECTED_FILE_COUNT=$(echo $INPUT | jq -r 'length')
23
23
# Iterate over file paths
24
24
for index in " ${! FILE_PATHS[@]} " ; do
25
25
file_path=${FILE_PATHS[$index]}
26
+ # Strip $TEMP_DIR from the path
27
+ file_path=$( echo $file_path | sed " s/\/eslint-temp\///g" )
26
28
# Get the messages for the file path
27
29
messages=${ALL_MESSAGES[$index]}
28
30
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:
2
12
3
13
{>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 1
1
---
2
2
functions :
3
- - name : eslint
3
+ - name : run_lint
4
4
type : prompt
5
5
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.
8
8
parameters :
9
9
type : object
10
10
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 :
20
12
type : string
21
- description : The script to run in the files.
13
+ description : Supports `condensed` or `complaints`
22
14
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.
26
18
parameters :
27
19
type : object
28
20
properties :
29
- output_level :
21
+ path :
30
22
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.
32
24
container :
33
25
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.
36
28
parameters :
37
29
type : object
38
30
properties :
@@ -42,6 +34,9 @@ functions:
42
34
line :
43
35
type : number
44
36
description : The affected line to load context from
37
+ required :
38
+ - path
39
+ - line
45
40
container :
46
41
image : vonwig/tree_sitter
47
42
---
Original file line number Diff line number Diff line change 13
13
# Get eslint.json
14
14
ESLINT_JSON=$( cat $THREAD_DIR /eslint.json)
15
15
16
+ # Replace all eslint-temp with empty string
17
+ ESLINT_JSON=$( echo $ESLINT_JSON | sed ' s/\/eslint-temp\///g' )
18
+
16
19
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
17
31
18
32
echo $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.
5
14
6
15
You are able to fix the following violations:
7
16
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ IFS=$'\n' ALL_MESSAGES=($ALL_MESSAGES)
21
21
# Iterate over file paths
22
22
for index in " ${! FILE_PATHS[@]} " ; do
23
23
file_path=${FILE_PATHS[$index]}
24
+ # Strip /eslint-temp
25
+ file_path=$( echo $file_path | sed ' s/\/eslint-temp\///g' )
24
26
# Get the messages for the file path
25
27
messages=${ALL_MESSAGES[$index]}
26
28
You can’t perform that action at this time.
0 commit comments