Skip to content

[6.0] Auto-Capitalize first word #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

emilyychenn
Copy link
Contributor

  • Explanation: When writing a doc comment, it feels intuitive to not capitalise the first word of its description because of the nature of the doc comment.

    • For example: adding a new parameter would be written as: /// - Parameter testParam: this parameter is just a test parameter to show what this looks like in lowercase.
    • In this example, the sentence in doc comments is natural to write with a lowercase starting word, because the first word (Parameter) is already capitalized.
    • This PR auto-capitalizes the first word of a new section or aside.
    • Note that this auto-capitalization only occurs if the first word is all lowercase and contains only characters A-Z, or if the first word contains CharacterSet punctuation characters (e.g. a period, comma, hyphen, semi-colon, colon).
  • Scope: Developer experience — auto-capitalizes the first word.

  • Issue: rdar://122167705

  • Risk: Low, only risk is that developers don't like this change and would prefer taking control of their own capitalization.

  • Testing:

    • Added unit tests to check behaviour of the auto-capitalization for a variety of different strings and a variety of languages and characters, spaces.
    • Added end-to-end integration tests to check behaviour of the auto-capitalization for a variety of different content types (e.g. parameter sections, asides, returns sections etc).
    • Also tested manually with a small test project and catalog by building a docc executable using this branch, then building the documentation within Xcode and checking that the capitalization is applied correctly when applicable and is not applied when it's not relevant.
  • Reviewers: @patshaughnessy @daniel-grumberg @d-ronnqvist

emilyychenn and others added 2 commits April 16, 2024 14:13
rdar://122167705

When writing a doc comment, it feels intuitive to not capitalise the first word of its description because of the nature of the doc comment.

For example: adding a new parameter would be written as:
`/// - Parameter testParam: this parameter is just a test parameter to show what this looks like in lowercase.`
In this example, the sentence in doc comments is natural to write with a lowercase starting word, because the first word (Parameter) is already capitalized. 

This PR auto-capitalizes the first word of a new section or aside. Note that this auto-capitalization only occurs if the first word is all lowercase and contains only characters A-Z, or if the first word contains CharacterSet punctuation characters (e.g. a period, comma, hyphen, semi-colon, colon). This capitalization is also locale specific.

---------

Co-authored-by: Pat Shaughnessy <[email protected]>
rdar://122167705

* Changed withFirstWordCapitalized from a computed property to a function.

* Remove unused protocol and extension, and extracted repeated capitalization logic into [RenderBlockContent] and [RenderInlineContent] extensions.

* Rename function from capitalizeFirstWord() to capitalizingFirstWord() since this is a non-mutating function.
@emilyychenn
Copy link
Contributor Author

@swift-ci please test

@emilyychenn emilyychenn requested a review from franklinsch April 16, 2024 13:35
@emilyychenn
Copy link
Contributor Author

@swift-ci please test

@emilyychenn emilyychenn merged commit 4cdcc7d into swiftlang:release/6.0 Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants