Skip to content

Commit da166ea

Browse files
committed
feat: add forge fmt editor-agnostic rules
1 parent 712c073 commit da166ea

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.sol]
10+
indent_style = space
11+
indent_size = 4
12+
max_line_length = 120
13+
# Forge formatter typically puts opening braces on the same line:
14+
curly_bracket_next_line = false
15+
# Space after control statements like if, for, while:
16+
spaces_around_operators = true
17+
spaces_around_brackets = false
18+
indent_brace_style = K&R

.githooks/pre-commit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# Format all staged Solidity files using forge fmt
4+
staged_sol_files=$(git diff --cached --name-only --diff-filter=ACMR | grep "\.sol$" || true)
5+
6+
if [ -n "$staged_sol_files" ]; then
7+
echo "Formatting Solidity files with forge fmt..."
8+
# Format all staged Solidity files
9+
forge fmt $staged_sol_files
10+
11+
# Add the formatted files back to the staging area
12+
git add $staged_sol_files
13+
fi
14+
15+
exit 0

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"makefile.configureOnOpen": false,
3+
"editor.formatOnSave": true,
4+
"[solidity]": {
5+
"editor.formatOnSave": true
6+
},
7+
"solidity.formatter": "forge"
8+
}

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,48 @@ LiteVault Owner can change the Authorizer contract, which will enable a grace wi
1717

1818
Authorizer contract that authorize withdrawal regardless of token and amount, but only outside of the time range specified on deployment.
1919

20+
## Development Setup
21+
22+
### Code Formatting
23+
24+
This project uses `forge fmt` for consistent Solidity code formatting. We follow an editor-agnostic approach with additional convenience settings for VS Code users.
25+
26+
#### Editor-Agnostic Formatting
27+
28+
1. **Git Hooks**: The project includes pre-commit hooks that automatically format Solidity files using `forge fmt` before each commit.
29+
30+
To set up the pre-commit hook:
31+
32+
```bash
33+
# Configure git to use the hooks in the .githooks directory
34+
git config core.hooksPath .githooks
35+
```
36+
37+
2. **EditorConfig**: The project includes an `.editorconfig` file with basic formatting rules that many editors support.
38+
39+
To use these settings:
40+
41+
- Install an EditorConfig plugin for your editor if it doesn't have built-in support
42+
- The plugin will automatically apply basic formatting rules (indentation, line endings, etc.)
43+
44+
More information about EditorConfig can be found at [https://editorconfig.org/](https://editorconfig.org/)
45+
46+
#### VS Code-Specific Settings
47+
48+
For VS Code users, additional settings are provided in `.vscode/settings.json` that:
49+
50+
- Configure VS Code to use `forge fmt` automatically when saving Solidity files
51+
- Ensure consistent formatting directly in the editor
52+
53+
These settings are optional and only apply to VS Code users. Other editors may need their own configuration to exactly match `forge fmt` behavior.
54+
55+
#### Recommended Workflow
56+
57+
The recommended workflow for all developers, regardless of editor:
58+
59+
1. Use the pre-commit hooks to ensure consistent formatting in the repository
60+
2. If needed, run `forge fmt` manually before committing to see changes
61+
2062
## Deployment and interaction
2163

2264
This repository uses Foundry toolchain for development, testing and deployment.

0 commit comments

Comments
 (0)