Add code formatter capabilities #848
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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