Add code formatter capabilities#848
Add code formatter capabilities#848jorgemoralespou wants to merge 2 commits intoeducates:developfrom
Conversation
|
Not sure I like this. Personally I rely on specific VS Code settings to ensure code is automatically formatted on save in consistent style using VS Code native support, or well known language specific formatters (eg., black for Python). I expect that this prettier tool is going to fight with my editor settings meaning anything committed and pushed will fail validation checks. Can we instead first look at just having VS Code settings for the project which we all use? |
|
I was working on the code-formatting with Claude, and he told me to better use Ruff than Black, etc... which you commented on. I just wanted to raise your attention here to it. Since the .vscode folder is in .gitignore, we can not enforce vscode settings for users. My And my Maybe, we should enable having these files in the repository. |
Code Formatting Guide
This project uses Prettier and EditorConfig to maintain consistent code formatting across all contributors and prevent unwanted reformatting.
Why Formatting Matters
Without a standardized formatter:
Configuration Files
.prettierrc.jsonDefines the formatting rules for Prettier. The current configuration matches the existing codebase style:
.editorconfigProvides editor-agnostic formatting settings that work across different IDEs and editors.
.prettierignoreSpecifies files and directories that should not be formatted by Prettier (e.g.,
node_modules, build outputs, Go files, Python files).Setup
Install Dependencies
This installs Prettier as a dev dependency.
Editor Configuration
VS Code
The project includes
.vscode/settings.jsonwhich configures VS Code to:If you're using VS Code, these settings will be automatically applied.
Other Editors
Usage
Format All Files
This formats all TypeScript, JavaScript, JSON, and Markdown files in the project.
Check Formatting (without modifying files)
This is useful for CI/CD to verify that files are properly formatted.
Format Specific Directories
Pre-commit Hooks (Optional)
To automatically format files before committing, you can set up a pre-commit hook:
Alternatively, you can use Git hooks directly:
CI/CD Integration
The project includes a GitHub Actions workflow (
.github/workflows/check-code-formatting.yml) that:Troubleshooting
My editor is reformatting code differently
.prettierrc.jsonfileprettier.requireConfigis set totruein your editor settingsFormatting conflicts in PRs
If you see formatting-only changes in a PR:
npm run formatbefore submittinggit checkout <branch> && npm run format && git commit -am "Format code"Prettier is formatting files I don't want formatted
Add the file patterns to
.prettierignore. Common exclusions:Current Formatting Style
Based on the existing codebase, the project uses:
These settings are defined in
.prettierrc.jsonand should not be changed without team consensus.Things to be done
Current formatting style would reformat documentation (in markdown) as well as typescript and json files as the rules are not 100% compatible. Let's discuss which formatting style we want to enforce, and update the rules accordingly, and then reformat the code with the plugin, all at once, before merging this PR. We would need to rebase on develop before to accommodate all the changes that happen between now and then.
@GrahamDumpleton