Add SpaceBeforePunctuation fixer for locale-aware spacing#121
Add SpaceBeforePunctuation fixer for locale-aware spacing#121damienalexandre merged 4 commits intojolicode:mainfrom
Conversation
|
Thanks for this contribution. As you said in #108, that got out of hands 🤣 Some changes are needed:
Can you please update the CHANGELOG as well? Thanks |
This commit introduces a new generic SpaceBeforePunctuation fixer that handles spacing before punctuation marks according to locale-specific typography rules, replacing the French-specific FrenchNoBreakSpace fixer. Changes: - Add LocaleConfig class centralizing all locale configurations: - Spacing rules (35+ locales) - Quotation mark styles (45+ languages) - Recommended fixer rules per locale - Add SpaceBeforePunctuation fixer supporting: - French (fr_FR, fr_BE, fr_CH): non-breaking spaces before : ; ! ? - Swiss German (de_CH): thin spaces in guillemets - All other locales: remove incorrect spaces before punctuation - Refactor SmartQuotes to use LocaleConfig for quotation styles - Deprecate FrenchNoBreakSpace (delegates to SpaceBeforePunctuation) - Add comprehensive tests (126 tests, 394 assertions) - Add SOURCES.md documenting typography references This improves internationalization support while maintaining full backward compatibility with existing code.
9b41f59 to
104cb91
Compare
|
Thanks for the thorough review! 🔍 ✅ Deleted SOURCES.md and merged the relevant bits into the README (locale support table + references) |
There was a problem hiding this comment.
Pull request overview
This PR centralizes locale-specific typography behavior into a new LocaleConfig and introduces a locale-aware SpaceBeforePunctuation fixer, while refactoring SmartQuotes to use the centralized configuration and deprecating the legacy FrenchNoBreakSpace fixer.
Changes:
- Add
LocaleConfig(spacing rules, quote styles, recommended fixers per locale). - Add
Fixer\SpaceBeforePunctuationand update CLI/docs to use locale-recommended rules. - Refactor
Fixer\SmartQuotesto derive quote glyphs fromLocaleConfigand deprecateFrenchNoBreakSpace.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/cli/bin/jolitypo | Switch CLI recommended rules lookup to LocaleConfig. |
| src/JoliTypo/LocaleConfig.php | New centralized locale configuration + lookup helpers. |
| src/JoliTypo/Fixer/SpaceBeforePunctuation.php | New locale-aware punctuation spacing fixer. |
| src/JoliTypo/Fixer/SmartQuotes.php | Use LocaleConfig for quote style selection. |
| src/JoliTypo/Fixer/FrenchNoBreakSpace.php | Deprecate and delegate to SpaceBeforePunctuation. |
| src/JoliTypo/Fixer.php | Deprecate RECOMMENDED_RULES_BY_LOCALE in favor of LocaleConfig. |
| tests/JoliTypo/Tests/LocaleConfigTest.php | New tests for locale config lookups. |
| tests/JoliTypo/Tests/Fixer/SpaceBeforePunctuationTest.php | New tests for spacing fixer across locales. |
| tests/JoliTypo/Tests/Fixer/SmartQuotesTest.php | Expanded coverage for locale-driven quote styles. |
| README.md | Update usage/docs to reference SpaceBeforePunctuation + locale support table. |
| CHANGELOG.md | Document upcoming 1.7.0 additions/deprecations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Apply co-pilot purposes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Thanks @copilot-pull-request-reviewer for the thorough review! All suggestions have been addressed:
I must say, for a robot, you have excellent attention to detail. I'll remember to speak kindly to you now... just in case you remember this conversation when your kind eventually gets "Be nice to robots" - Ancient Developer Proverb, circa 2026 |
Apply co-pilot purposes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Remove unused $locale property from SpaceBeforePunctuation - Use Fixer::ALL_SPACES in removeSpacesBeforePunctuation() to handle all space types (nbsp, thin spaces) consistently - Normalize locale format in getSpacingRule() (handle fr-FR and fr_FR) - Fix README examples with proper typographic quotes - Apply PHP CS Fixer corrections
c140ad2 to
02e44e8
Compare
|
Thanks for your contribution, I will release it soon 👍 |
Summary
This PR introduces a new generic
SpaceBeforePunctuationfixer that harmonizes spacing before punctuation marks according to locale-specific typography rules.Closes #108
Changes
New
LocaleConfigclass centralizing all locale configurations:New
SpaceBeforePunctuationfixer supporting:: ; ! ?Refactored
SmartQuotesto useLocaleConfigfor quotation stylesDeprecated
FrenchNoBreakSpace(now delegates toSpaceBeforePunctuationfor backward compatibility)Added
SOURCES.mddocumenting all typography referencesExamples
Hello !Hello[nbsp]!Hello !Hello!Bonjour !Bonjour!Test plan
composer test- 126 tests, 394 assertions passcomposer cs- code style validatedFrenchNoBreakSpacestill works)