Skip to content
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

Generators: don't print documentation title if there are no docs #755

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 7, 2024

Description

Previously, in case an XML documentation file contained no usable documentation, the Generators would still print the title for the sniff documentation, even though there was no documentation to print.

It is my opinion, that in such a case, the title should also not be printed.

Some screenshots of situations which will no longer occur once this PR is merged:

HTML

7-useless-doc-html

Markdown

7-useless-doc-markdown

Commits

Generators/Text: don't print title if there is no content

This refactors the class to retrieve the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:

  • printTitle() in favour of getFormattedTitle()
  • printTextBlock() in favour of getFormattedTextBlock()
  • printCodeComparisonBlock() in favour of getFormattedCodeComparisonBlock()

Generators/Markdown: don't print title if there is no content

This refactors the class to retrieve the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:

  • printHeader() in favour of getFormattedHeader()
  • printFooter() in favour of getFormattedFooter()
  • printTextBlock() in favour of getFormattedTextBlock()
  • printCodeComparisonBlock() in favour of getFormattedCodeComparisonBlock()

Generators/HTML: don't print title if there is no content

This refactors the class to retrieve the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:

  • printHeader() in favour of getFormattedHeader()
  • printToc() in favour of getFormattedToc()
  • printFooter() in favour of getFormattedFooter()
  • printTextBlock() in favour of getFormattedTextBlock()
  • printCodeComparisonBlock() in favour of getFormattedCodeComparisonBlock()

Suggested changelog entry

Changed

  • Documentation files which don't contain any actual documentation will now be silently ignored.

Deprecated

The following methods have been deprecated and will be removed in PHP_CodeSniffer 4.0:

  • PHP_CodeSniffer\Generators\Text\printTitle() in favour of PHP_CodeSniffer\Generators\Text\getFormattedTitle()
  • PHP_CodeSniffer\Generators\Text\printTextBlock() in favour of PHP_CodeSniffer\Generators\Text\getFormattedTextBlock()
  • PHP_CodeSniffer\Generators\Text\printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\Text\getFormattedCodeComparisonBlock()
  • PHP_CodeSniffer\Generators\Markdown\printHeader() in favour of PHP_CodeSniffer\Generators\Markdown\getFormattedHeader()
  • PHP_CodeSniffer\Generators\Markdown\printFooter() in favour of PHP_CodeSniffer\Generators\Markdown\getFormattedFooter()
  • PHP_CodeSniffer\Generators\Markdown\printTextBlock() in favour of PHP_CodeSniffer\Generators\Markdown\getFormattedTextBlock()
  • PHP_CodeSniffer\Generators\Markdown\printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\Markdown\getFormattedCodeComparisonBlock()
  • PHP_CodeSniffer\Generators\HTML\printHeader() in favour of PHP_CodeSniffer\Generators\HTML\getFormattedHeader()
  • PHP_CodeSniffer\Generators\HTML\printToc() in favour of PHP_CodeSniffer\Generators\HTML\getFormattedToc()
  • PHP_CodeSniffer\Generators\HTML\printFooter() in favour of PHP_CodeSniffer\Generators\HTML\getFormattedFooter()
  • PHP_CodeSniffer\Generators\HTML\printTextBlock() in favour of PHP_CodeSniffer\Generators\HTML\getFormattedTextBlock()
  • PHP_CodeSniffer\Generators\HTML\printCodeComparisonBlock() in favour of PHP_CodeSniffer\Generators\HTML\getFormattedCodeComparisonBlock()

Related issues/external references

This PR is part of a series of PRs which will add a complete set of tests (and improvements) for the Generator feature.

Also see: #671 and #716.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

jrfnl added 3 commits January 23, 2025 19:13
This refactors the class to _retrieve_ the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:
* `printTitle()` in favour of `getFormattedTitle()`
* `printTextBlock()` in favour of `getFormattedTextBlock()`
* `printCodeComparisonBlock()` in favour of `getFormattedCodeComparisonBlock()`
This refactors the class to _retrieve_ the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:
* `printHeader()` in favour of `getFormattedHeader()`
* `printFooter()` in favour of `getFormattedFooter()`
* `printTextBlock()` in favour of `getFormattedTextBlock()`
* `printCodeComparisonBlock()` in favour of `getFormattedCodeComparisonBlock()`
This refactors the class to _retrieve_ the intended output, instead of echo-ing it out directly and validates whether it makes sense to print anything at all about a sniff before sending the output to screen.

It deprecates the following methods, which will be removed in PHPCS 4.0:
* `printHeader()` in favour of `getFormattedHeader()`
* `printToc()` in favour of `getFormattedToc()`
* `printFooter()` in favour of `getFormattedFooter()`
* `printTextBlock()` in favour of `getFormattedTextBlock()`
* `printCodeComparisonBlock()` in favour of `getFormattedCodeComparisonBlock()`
@jrfnl
Copy link
Member Author

jrfnl commented Jan 23, 2025

Rebased without changes to get a passing build. Merging once the build has finished.

@jrfnl jrfnl force-pushed the feature/generators-dont-print-title-if-no-docs branch from 0f978c7 to cc82dcd Compare January 23, 2025 18:14
@jrfnl jrfnl merged commit 296db10 into master Jan 23, 2025
65 checks passed
@jrfnl jrfnl deleted the feature/generators-dont-print-title-if-no-docs branch January 23, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants