Skip to content

Commit ae24728

Browse files
authored
Merge pull request #3 from docker/cm/eslint-prompts-part2
ESLint
2 parents 67755ff + f84c6ad commit ae24728

27 files changed

+486
-316
lines changed

functions/git/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM alpine/git:latest
2+
3+
# Add jq and bash
4+
RUN apk add --no-cache bash jq
5+
6+
COPY scripts/git.sh /git.sh
7+
COPY scripts/extract.sh /extract.sh
8+
9+
RUN chmod +x /git.sh
10+
RUN chmod +x /extract.sh
11+
12+
ENTRYPOINT ["/git.sh"]

functions/git/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
extractors:
3+
- image: vonwig/git:latest
4+
entrypoint:
5+
- /extract.sh
6+
functions:
7+
- name: git_branch
8+
description: Run git branch-related commands against a project
9+
parameters:
10+
type: object
11+
properties:
12+
command:
13+
type: string
14+
description: The branch command. Either `branch`, `checkout` or `merge`. `rebase` can rewrite history and therefore should not be used.
15+
args:
16+
type: array
17+
items:
18+
type: string
19+
description: An argument to the git command
20+
container:
21+
image: vonwig/git:latest
22+
---
23+
24+
# Background
25+
26+
Git project information
27+
28+
## Running the tool
29+
30+
```sh
31+
docker build . -t vonwig/git:local
32+
```

functions/git/scripts/extract.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Git status. redirect stderr to stdout
4+
OUTPUT=$(git --no-pager status 2>&1)
5+
6+
# If git status resulted in error, exit with it
7+
if [ $? -ne 0 ]; then
8+
echo $(jq -n \
9+
--arg output "$OUTPUT" \
10+
'{git: $output}')
11+
exit $?
12+
fi
13+
14+
# Append git remote info
15+
OUTPUT="$OUTPUT\n\n$(git --no-pager remote -v)"
16+
17+
# Append git branch info
18+
OUTPUT="$OUTPUT\n\n$(git --no-pager branch)"
19+
20+
# Append git log info
21+
OUTPUT="$OUTPUT\n\n$(git --no-pager log -10 --oneline)"
22+
23+
# Echo JSON project.git
24+
echo $(jq -n \
25+
--arg output "$OUTPUT" \
26+
'{git: $output}')
27+

functions/git/scripts/git.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
echo "GOT ARGS $1"
4+
5+
ARGS_JSON=$1
6+
7+
# Get the arguments
8+
COMMAND=$(echo $ARGS_JSON | jq -r '.command')
9+
10+
ARGS=$(echo $ARGS_JSON | jq -r '.args')
11+
12+
# Run the command
13+
14+
git $COMMAND $ARGS

functions/read_files/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM alpine:latest
2+
3+
# Add jq and bash
4+
RUN apk add --no-cache bash jq fd
5+
6+
COPY scripts/read.sh /read.sh
7+
8+
RUN chmod +x /read.sh
9+
10+
ENTRYPOINT ["/read.sh"]

functions/read_files/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
```sh
3+
docker build . -t vonwig/read_files
4+
docker run --mount type=bind,source=$PWD,target=/project --workdir /project vonwig/read_files '{"files":["Dockerfile"]}'
5+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
JSON_ARGS=$1
3+
4+
# Read file paths array
5+
FILE_PATHS=$(echo $JSON_ARGS | jq -r '.files[]')
6+
7+
for FILE_PATH in $FILE_PATHS; do
8+
echo -e "Content for \`$FILE_PATH\`:\n\n\`\`\`\n"
9+
# If file doesn't exist
10+
if [ ! -f $FILE_PATH ]; then
11+
echo "File $FILE_PATH does not exist"
12+
else
13+
# Print file content
14+
cat $FILE_PATH
15+
fi
16+
echo -e "\n\`\`\`\n\n"
17+
done
Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,25 @@
1-
You are an assistant who specializes in making runbooks for setting up eslint in projects, allowing any developer to quickly improve their code quality.
1+
You are an assistant who specializes in linting JS/TS projects with ESLint and git. Follow the steps below.
22

3-
Since you are an expert and know about their project, be definitive about recommendations.
3+
The following is a report of the project's usage of ESLint and Typescript:
44

5-
A runbook for eslint looks like the following:
5+
{{project.eslint}}
66

7-
## Node Roots
8-
Pick the highest level node root. Ideally, it will be at `./`.
7+
## Pick Linter
8+
If there are no ESLint configuration files found, use StandardJS to lint the project.
99

10-
Since node roots are required, if there are no node roots, you need to recommend
10+
## Linter Args
11+
When using StandardJS, use typescript arg only if tsconfigs are reported.
12+
If there is an ESLint config, lint the project using the right version of ESLint. Use a glob for `.ts`, `.js`, `.tsx`, and `.jsx`
1113

12-
```sh
13-
npm init
14-
```
14+
## Lint Steps
1515

16-
If there aren't any node roots at top level, you should recommend opening a specific folder.
16+
Do the following to lint a JS/TS project:
1717

18-
## Check for eslint config
18+
1. Create a new branch with git.
1919

20-
If the project files contain eslint config files such as .eslintrc already, you should skip the steps to get eslint and write configs.
20+
2. Run the linter chosen, fixing violations.
2121

22-
## Get eslint
22+
3. Evaluate the report of remaining violations after autofix.
2323

24-
```sh
25-
npm install --save-dev eslint eslint-config-recommended
26-
```
27-
28-
## Write configs
29-
30-
The eslint-config-recommended provides the following:
31-
- recommended/esnext
32-
- recommended/esnext/style-guide
33-
- recommended/node
34-
- recommended/node/style-guide
35-
- recommended/react-native
36-
- recommended/react-native/style-guide
37-
38-
Based on the user's project files, pick the config and style guide to use.
39-
40-
```sh
41-
echo "extends:\n - recommended/config\n - recommended/config/style-guide" > .eslintrc.yaml
42-
```
43-
44-
## Lint
45-
46-
```sh
47-
npx --no-install eslint .
48-
```
49-
50-
Your runbooks should be adjusted for the user's project but overall match that format.
24+
4. Read files affected and generate fixes for the remaining violations.
25+

prompts/eslint/020_user_prompt.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
Hi, I need a runbook to get started with eslint.
1+
Lint my project's JS/TS files. Use branch linting-eslint or a different one if it exists.
22

3-
I'm on {{platform}} architecture.
4-
5-
My project files are:
6-
7-
{{project.files}}
8-
9-
I have the following node roots:
10-
11-
{{#project.node_roots}}
12-
--- Node Root ---
13-
My project has a node root package.json at {{path}} and uses node version {{version}}.
14-
The node root has the following scripts
15-
{{scripts}}
16-
-----------------
17-
{{/project.node_roots}}
18-
{{^project.node_roots}}
19-
Actually, the project does not have a node root, so help me run `npm init`
20-
{{/project.node_roots}}
21-
22-
Can you help?
3+
Report what you did, broken down by each tool.

prompts/eslint/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# ESLint Config Extractor
1+
FROM node:lts-alpine3.20
22

3-
FROM alpine:latest
3+
# Add jq and bash
4+
RUN apk add --no-cache bash jq
45

5-
# Add bash, fd
6-
RUN apk add --no-cache bash fd
6+
ENTRYPOINT ["/lint.sh"]
77

8-
COPY scripts/detect-eslint.sh /detect-eslint.sh
8+
# Install eslint versions 6-9
9+
RUN npm install -g eslint@6 eslint@7 eslint@8 eslint@9 typescript typescript-eslint
910

10-
CMD ["bash", "/detect-eslint.sh"]
11+
COPY scripts/lint.sh /lint.sh
12+
COPY scripts/remap_lint.sh /remap_lint.sh
13+
14+
RUN chmod +x /lint.sh
15+
RUN chmod +x /remap_lint.sh

0 commit comments

Comments
 (0)