Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Skip all code blocks in the ensure_attribute_between_backticks_in_content rule - #2390

Open
Amoifr wants to merge 1 commit into
OskarStark:mainfrom
Amoifr:fix-attribute-backticks-in-code-blocks
Open

Skip all code blocks in the ensure_attribute_between_backticks_in_content rule#2390
Amoifr wants to merge 1 commit into
OskarStark:mainfrom
Amoifr:fix-attribute-backticks-in-code-blocks

Conversation

@Amoifr

@Amoifr Amoifr commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

The rule only skipped php and diff code blocks, so an attribute inside any other code block was reported. symfony-docs hits it since symfony/symfony-docs#22926: the debug:messenger output in messenger.rst lists App\Message\DummyQuery (from #[AsMessage]) inside a .. code-block:: terminal, and DOCtor-RST now fails on every 8.2 pull request.

in() was called with [RstParser::CODE_BLOCK_DIFF], which restricts the match to diff blocks. Dropping the filter skips every code block, as #2170 did for use_double_backticks_for_inline_literals.

Tests

The existing diff case built its RstSample without a line number, so it checked line 0, the .. code-block:: line itself, and passed whatever the rule did. The new cases point at the attribute line: diff, terminal, yaml, text and twig, plus the debug:messenger output, and a guard showing that an attribute in the content right after a code block is still reported. Without the fix, the five non-diff cases fail. The PHP code block loop above has the same line 0 issue; I left it alone since fixing it means rewriting its samples, happy to do it here or separately.

Verification

Running the patched rule over the symfony-docs 8.2 branch, messenger.rst is no longer reported (the remaining Tui violations are fixed by symfony/symfony-docs#22983). The 2095 tests pass, PHPStan and PHP-CS-Fixer are clean, and docs/rules.md needs no change.

symfony-docs pins oskarstark/doctor-rst:1.83.0, so it will need a bump once this is released.

@OskarStark

Copy link
Copy Markdown
Owner

Not sure it's to error prone. Did you run it against all supported Symfony docs branches?

@Amoifr

Amoifr commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Good call: about 17,000 fake attributes later, you were right to be suspicious 😄

With each branch's .doctor-rst.yaml, the output on 6.4, 7.4, 8.0, 8.1 and 8.2 is identical to main, except for the messenger.rst false positive going away on 8.2.

Since the docs are clean, that alone proves little, so I also injected a bare #[ProbeN] line right after every code block (about 3,500 per branch). That found a real blind spot in DirectiveTrait::in(): it walks up to the first less indented directive, but doesn't stop at a less indented list item or definition term. So prose following a code block inside a #. item is taken as part of an earlier code block. main already has it for diff blocks only, and this PR would extend it to all of them (5 to 8 probes lost per branch).

The fix is a 3 line change: lower the reference indentation when a non-directive line with less indentation is met. With it, every probe is reported, the symfony-docs output doesn't change on any branch (8 rules use in()), and 3 new tests fail without it.

Since it touches 8 rules, I'll open an issue and a dedicated PR for in(); this one can wait for it.

@OskarStark

Copy link
Copy Markdown
Owner

So let's close here?

@Amoifr
Amoifr force-pushed the fix-attribute-backticks-in-code-blocks branch from ca05974 to 4c8c718 Compare September 12, 2026 10:32
@Amoifr

Amoifr commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging #2392!

That one fixed in(), which attached prose to an earlier code block. This PR is a different defect: the rule only skips php and diff blocks, so an attribute inside any other block is still reported. On current main, with #2392 in, symfony-docs 8.2 still fails:

::error file=messenger.rst,line=4594::Please ensure to use backticks "          App\Message\DummyQuery (from #[AsMessage])"

With this PR on top, that line is gone and nothing else in the output moves: the three errors left on 8.2 are unrelated and were already there. So closing here would leave DOCtor-RST red on every symfony-docs 8.2 pull request, since the debug:messenger output in messenger.rst is a plain terminal block.

I just pushed it rebased on main, so the CI here runs against the merged in() fix, with the 2100 tests green. Happy to close instead if you would rather exempt code blocks another way, just tell me which way you prefer.

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