Prompt
How do I catch broken spacing changes automatically?
Latest observation
A good way to catch “broken spacing” automatically is to combine formatting, linting, and visual regression so you detect both code-style spacing issues and layout spacing regressions.
1) Enforce formatting in CI
Use a formatter so trivial whitespace changes are standardized automatically.
- Prettier for JS/TS/CSS/JSON/Markdown
- Black for Python
- gofmt for Go
- rustfmt for Rust
Then add a CI check that fails if files aren’t formatted.
Example:
prettier --check .
2) Add lint rules for spacing
Linters can catch suspicious spacing patterns in code.
Examples:
eslintrules like:no-multi-spaceskey-spacingspace-before-function-parenobject-curly-spacing
stylelintfor CSS spacing issuesflake8/rufffor Python style issues
This catches things like inconsistent indentation, extra spaces, or malformed formatting.
3) Use visual regression testing for UI spacing
If you mean layout spacing in a UI, code formatting won’t catch that. Use screenshot tests:
- Storybook + Chromatic
- Playwright screenshot tests
- Percy
- Loki
- Cypress visual testing
These compare screenshots before/after and flag changes in margins, padding, alignment, line-height, etc.
4) Add DOM/layout assertions in tests
For critical components, write tests that assert spacing-related styles or geometry.
Examples:
- check computed styles:
marginpaddinggapline-height
- check element positions/sizes with Playwright/Cypress:
- bounding boxes
- relative distances between elements
5) Prevent accidental whitespace-only diffs
If you want to catch unintended whitespace changes in code reviews:
- enable “ignore whitespace” in review tools when appropriate
- but also have a bot or CI job that flags whitespace-only edits if they’re not expected
- use Git hooks:
pre-commithuskylint-staged
Recommended setup
For most teams:
- Formatter in pre-commit + CI
- Linter for spacing rules
- Visual regression tests for UI spacing
- Screenshot-based checks on key pages/components
If you tell me your stack (for example, React, Python, CSS, Android, etc.), I can suggest the best exact tools and setup.