A comprehensive guide to setting up HBStack project configuration including EditorConfig, linting, and markdown handling for code quality and consistency.
A comprehensive guide to setting up HBStack project configuration including EditorConfig, linting, and markdown handling for code quality and consistency.
This project implements a comprehensive approach to code formatting, linting, and markdown handling. Below is a detailed explanation of how these components work together to maintain code quality and consistency.
The .editorconfig file provides basic code style definitions that work across different editors and IDEs.
1[*]
2end_of_line = lf # Use Unix-style line endings
3insert_final_newline = true # Ensure files end with a newline
4charset = utf-8 # Set UTF-8 character encoding
5trim_trailing_whitespace = true # Remove trailing whitespace
6indent_style = space # Use spaces for indentation
7indent_size = 2 # Use 2 spaces per indentation level
8
9[*.{md,markdown}]
10trim_trailing_whitespace = false # Don't trim trailing whitespace in markdown
11 # (preserves intentional line breaks)
Key points about EditorConfig:
trim_trailing_whitespace = false for markdown files is crucial for preserving intended line breaks (two spaces at the end of a line)Prettier handles more sophisticated code formatting with the .prettierrc file.
1{
2 "singleQuote": true,
3 "tabWidth": 2,
4 "useTabs": false,
5 "trailingComma": "es5",
6 "printWidth": 100,
7 "endOfLine": "lf",
8 "overrides": [
9 {
10 "files": "*.md",
11 "options": {
12 "proseWrap": "preserve",
13 "printWidth": 100,
14 "parser": "markdown"
15 }
16 }
17 ]
18}
Important Prettier aspects:
parser: "markdown" in the overrides sectionproseWrap: "preserve" option is crucial for markdown to maintain line breaks and formattingprintWidth option sets the maximum line length for code formattingplugins section includes the prettier-plugin-go-template for handling Go templates in markdown filesoverrides section allows for specific configurations for different file types, in this case, markdown filesparser option specifies the parser to use for markdown files, ensuring proper formattingendOfLine option ensures consistent line endings across different operating systemstrailingComma option specifies how trailing commas are handled in objects and arraysVS Code settings help connect these tools together:
1{
2 "editor.formatOnSave": true,
3 "editor.defaultFormatter": "esbenp.prettier-vscode",
4 "[markdown]": {
5 "editor.defaultFormatter": "esbenp.prettier-vscode"
6 }
7}
1{
2 "prettier.configPath": ".prettierrc",
3 "prettier.requireConfig": true,
4 "prettier.useEditorConfig": true,
5 "prettier.documentSelectors": ["**/*.{html,hugo}"]
6}
Why separate Prettier settings in VS Code:
.vscode/prettier.json contains settings specific to the Prettier VS Code extensionWhen working with Markdown files in this project:
On Save Behavior:
Manual Formatting:
Linting vs. Formatting:
| Rule ID | Description | Auto-fixed by Prettier? |
|---|---|---|
| MD009 | Trailing spaces | Yes |
| MD031 | Blank lines around code blocks | No |
| MD026 | Trailing punctuation in headings | No |
| MD013 | Line length | Partially |
| MD033 | Inline HTML | No |
Issue: Multiple conflicting configuration files were causing VS Code file saving problems and performance issues. The workspace had redundant and conflicting settings across various configuration files that were interfering with proper file operations.
Changes Made:
Removed: .prettierrc file (conflicting configuration)
Kept: .prettierrc.json as the single source of truth
Updated .prettierrc.json:
1{
2 "singleQuote": true,
3 "tabWidth": 2,
4 "useTabs": false,
5 "trailingComma": "es5",
6 "printWidth": 100,
7 "endOfLine": "lf",
8 "overrides": [
9 {
10 "files": "*.md",
11 "options": {
12 "proseWrap": "preserve",
13 "printWidth": 100,
14 "parser": "markdown"
15 }
16 }
17 ]
18}
Reason: Removed problematic plugins (prettier-plugin-go-template and prettier-plugin-md-nocjsp) that were causing formatting conflicts and VS Code performance issues.
Updated .vscode/settings.json:
1{
2 "editor.formatOnSave": true,
3 "editor.defaultFormatter": "esbenp.prettier-vscode",
4 "editor.codeActionsOnSave": {
5 "source.fixAll": "explicit"
6 },
7 "[markdown]": {
8 "editor.defaultFormatter": "esbenp.prettier-vscode",
9 "editor.wordWrap": "on"
10 },
11 "[yaml]": {
12 "editor.defaultFormatter": "esbenp.prettier-vscode"
13 },
14 "[json]": {
15 "editor.defaultFormatter": "esbenp.prettier-vscode"
16 }
17}
Reason: Simplified and unified formatter settings, removed redundant configurations that were causing conflicts.
Updated hugo-with-docker.code-workspace:
Reason: Eliminated conflicts between workspace-level and folder-level settings that were causing inconsistent behavior.
Removed Dependencies:
prettier-plugin-go-template: Was causing formatting conflictsprettier-plugin-md-nocjsp: Was interfering with markdown processingAdded Debug Scripts:
1{
2 "scripts": {
3 "debug": "hugo server --debug --verbose --logLevel debug",
4 "debug:build": "hugo --debug --verbose --logLevel debug --minify",
5 "diagnose": "echo '=== Hugo Diagnostics ===' && hugo version && hugo env && hugo config",
6 "troubleshoot": "npm run diagnose && npm run check:modules && npm run check:build",
7 "check:links": "hugo server --navigateToChanged=false --disableFastRender --logLevel info 2>&1 | grep -i 'error\\|warn' || echo 'No link errors found'",
8 "check:config": "hugo config --logLevel info",
9 "check:modules": "hugo mod verify && hugo mod graph",
10 "check:build": "hugo --dry-run --logLevel info",
11 "health": "hugo version && hugo mod verify && hugo config | head -20"
12 }
13}
Reason: Added comprehensive debugging and troubleshooting capabilities to help diagnose project issues quickly.
Problems Resolved:
Benefits:
Migration Notes: