Skip to content

Commit 230effc

Browse files
authored
lint: use typos as precommit's hook (SWE-agent#259)
* lint: use typos as precommit hook * fixing typos
1 parent 6e51414 commit 230effc

File tree

11 files changed

+38
-21
lines changed

11 files changed

+38
-21
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ repos:
1313
- id: detect-private-key
1414
- id: check-ast
1515

16+
- repo: https://github.com/crate-ci/typos
17+
rev: v1.20.7
18+
hooks:
19+
- id: typos
20+
files: \.(py|md|rst|yaml|toml)
21+
# empty to do not write fixes
22+
args: []
23+
exclude: pyproject.toml
24+
1625
- repo: https://github.com/astral-sh/ruff-pre-commit
1726
rev: v0.4.3
1827
hooks:

config/commands/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Every command subscribes to the following skeleton code.
2323
* If there are no arguments, omit the `arguments` section.
2424
* The implementation for your command is unconstrained. There are no limitations on the form of the underlying command code.
2525
* The minimal documentation requirements are `signature` and `docstring`.
26-
* If you'd like multiple commands to make modifications to a similar body of functions, we recommend using global varibles.
26+
* If you'd like multiple commands to make modifications to a similar body of functions, we recommend using global variables.
2727
* For instance, in `config/commands/default.sh`, you'll see we define the `CURRENT_LINE` variable for the file viewer. This variable is modified across multiple commands, including `open`, `goto`, `scroll_up`, `scroll_down`, and `edit`.
2828
* You can also leverage third party libraries (check out how we do linting enabled `edit` in `config/commands/edit_linting.sh`).
2929
* To show effects of the command, print to standard output (i.e. `echo`). SWE-agent is implemented such that it does not look for a return value from these commands.

inspector/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def load_content(file_name, gold_patches, test_patches):
139139
with open(scorecards_file) as infile:
140140
scorecards = json.load(infile)
141141

142-
content = append_exit(content) # accomodate new and old format
142+
content = append_exit(content) # accommodate new and old format
143143
content = append_patch(Path(file_name).stem, content, gold_patches, "Gold")
144144
content = append_patch(Path(file_name).stem, content, test_patches, "Test")
145145
content = append_results(

make_demos/convert_traj_to_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def convert_traj_to_action_demo(traj_path: str, output_file: str = None, include
5858
traj = json.load(open(traj_path))
5959
history = traj["history"]
6060
action_traj = list()
61-
admissable_roles = {"assistant", "user"} if include_user else {"assistant"}
61+
admissible_roles = {"assistant", "user"} if include_user else {"assistant"}
6262
for step in history:
63-
if step['role'] in admissable_roles and step.get('agent', 'primary') == 'primary':
63+
if step['role'] in admissible_roles and step.get('agent', 'primary') == 'primary':
6464
action_traj.append({k: v for k, v in step.items() if k in {'content', 'role'}})
6565
save_demo(action_traj, output_file, traj_path)
6666
print(f"Saved demo to {output_file}")

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ skip-magic-trailing-comma = false
127127

128128
# Like Black, automatically detect the appropriate line ending.
129129
line-ending = "auto"
130+
131+
[tool.typos.default.extend-identifiers]
132+
# *sigh* this just isn't worth the cost of fixing
133+
ACI = "ACI"
134+
135+
[tool.typos.default.extend-words]
136+
# Don't correct the surname "Teh"
137+
aci = "aci"

sweagent/environment/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,12 @@ def get_container(ctr_name: str, image_name: str, persistent: bool = False) -> T
353353
try:
354354
client = docker.from_env()
355355
except docker.errors.DockerException as e:
356-
docker_not_runnnig = any((
356+
docker_not_running = any((
357357
"connection aborted" in str(e).lower(),
358358
"connection refused" in str(e).lower(),
359359
"error while fetching server api version" in str(e).lower(),
360360
))
361-
if docker_not_runnnig:
361+
if docker_not_running:
362362
msg = (
363363
"Probably the Docker daemon is not running. Please start the Docker daemon and try again. "
364364
"You might need to allow the use of the docker socket "

tests/test_data/trajectories/gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ agent:
234234
"File updated. Please review the changes and make sure they are correct (correct
235235
indentation, no duplicate lines, etc). Edit the file again if necessary." else echo
236236
"Your proposed edit has introduced new syntax error(s). Please understand
237-
the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string
237+
the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string
238238
"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #
239239
Update values export CURRENT_LINE=$(( (line_count / 2) + start_line
240240
)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show
@@ -406,7 +406,7 @@ agent:
406406
\ environment, and run it to make sure you can reproduce the bug.\n Then start\
407407
\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\
408408
\ reproduction script to make sure that the bug has indeed been fixed.\n \n\
409-
\ If the bug reproduction script does not print anything when it succesfully\
409+
\ If the bug reproduction script does not print anything when it successfully\
410410
\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\
411411
) command at the end of the file,\n so that you can be sure that the script\
412412
\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\

tests/test_data/trajectories/gpt4__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1/args.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ agent:
235235
"File updated. Please review the changes and make sure they are correct (correct
236236
indentation, no duplicate lines, etc). Edit the file again if necessary." else echo
237237
"Your proposed edit has introduced new syntax error(s). Please understand
238-
the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string
238+
the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string
239239
"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #
240240
Update values export CURRENT_LINE=$(( (line_count / 2) + start_line
241241
)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show
@@ -407,7 +407,7 @@ agent:
407407
\ environment, and run it to make sure you can reproduce the bug.\n Then start\
408408
\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\
409409
\ reproduction script to make sure that the bug has indeed been fixed.\n \n\
410-
\ If the bug reproduction script does not print anything when it succesfully\
410+
\ If the bug reproduction script does not print anything when it successfully\
411411
\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\
412412
) command at the end of the file,\n so that you can be sure that the script\
413413
\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\

tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ agent:
235235
"File updated. Please review the changes and make sure they are correct (correct
236236
indentation, no duplicate lines, etc). Edit the file again if necessary." else echo
237237
"Your proposed edit has introduced new syntax error(s). Please understand
238-
the fixes and retry your edit commmand." echo "" echo "ERRORS:" _split_string
238+
the fixes and retry your edit command." echo "" echo "ERRORS:" _split_string
239239
"$lint_output" echo "" # Save original values original_current_line=$CURRENT_LINE original_window=$WINDOW #
240240
Update values export CURRENT_LINE=$(( (line_count / 2) + start_line
241241
)) # Set to "center" of edit export WINDOW=$((line_count + 10)) # Show
@@ -407,7 +407,7 @@ agent:
407407
\ environment, and run it to make sure you can reproduce the bug.\n Then start\
408408
\ trying to fix it.\n When you think you've fixed the bug, re-run the bug\
409409
\ reproduction script to make sure that the bug has indeed been fixed.\n \n\
410-
\ If the bug reproduction script does not print anything when it succesfully\
410+
\ If the bug reproduction script does not print anything when it successfully\
411411
\ runs, we recommend adding a print(\"Script completed successfully, no errors.\"\
412412
) command at the end of the file,\n so that you can be sure that the script\
413413
\ indeed ran fine all the way through. \n\n2. If you run a command and it doesn't\

tests/test_models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
@pytest.fixture
77
def openai_mock_client():
88
model = Mock()
9-
reponse = Mock()
9+
response = Mock()
1010
choice = Mock()
1111
choice.message.content = "test"
12-
reponse.choices = [choice]
13-
reponse.usage.prompt_tokens = 10
14-
reponse.usage.completion_tokens = 10
15-
model.chat.completions.create = MagicMock(return_value=reponse)
12+
response.choices = [choice]
13+
response.usage.prompt_tokens = 10
14+
response.usage.completion_tokens = 10
15+
model.chat.completions.create = MagicMock(return_value=response)
1616

1717
return model
1818

tests/test_replay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def test_model_replay_local_repo(swe_agent_test_repo_clone, swe_agent_test_repo_
102102
"--raise_exceptions",
103103
]
104104
print(run_cmd)
105-
args, remaing_args = get_args(run_cmd)
106-
main(**vars(args), forward_args=remaing_args)
105+
args, remaining_args = get_args(run_cmd)
106+
main(**vars(args), forward_args=remaining_args)
107107
solution = (swe_agent_test_repo_traj.parent / "solution_missing_colon.py").read_text().strip()
108108
solution_retrieved = (local_repo_path / "tests" / "missing_colon.py").read_text().strip()
109109
assert solution == solution_retrieved
@@ -127,6 +127,6 @@ def test_exception_replay_local_dirty(swe_agent_test_repo_clone, swe_agent_test_
127127
"--apply_patch",
128128
"--raise_exceptions",
129129
]
130-
args, remaing_args = get_args(run_cmd)
130+
args, remaining_args = get_args(run_cmd)
131131
with pytest.raises(ValueError, match=".*dirty.*"):
132-
main(**vars(args), forward_args=remaing_args)
132+
main(**vars(args), forward_args=remaining_args)

0 commit comments

Comments
 (0)