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

Skip to content

Verify code blocks #15257

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
merged 1 commit into from
Apr 21, 2021
Merged

Verify code blocks #15257

merged 1 commit into from
Apr 21, 2021

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Apr 18, 2021

This PR is a first step to make sure we are using valid code blocks. I created a small parser that will replace the PR to the docs builder.

This CI job will look at the modified files, and give the the the code-block-checker. That project will find the code blocks and make sure they are using valid syntax. It also supports a baseline so we can write invalid syntax if we want to. (it may sometimes make the examples more readable See #15250)

The next step is to make sure one can actually run code examples. Im planning to get all examples that starts with a comment and figure out if that is a filepath to the config directory. I will then capture any symfony errors when using that config. This is super helpful when updating the PHP config to use the config builders.

EDIT: I included "the next step" in this PR. We do run all config examples.

Note that thanks to the baseline feature, will only report new errors on modified code blocks.

@Nyholm Nyholm requested a review from OskarStark as a code owner April 18, 2021 17:06
@Nyholm Nyholm changed the base branch from 5.x to 4.4 April 18, 2021 17:06
@Nyholm
Copy link
Member Author

Nyholm commented Apr 18, 2021

Note that it will not complain about the existing syntax error (missing semi colon) in the cache.rst. (It will be fixed here).

This is thanks to the baseline feature.

@Nyholm
Copy link
Member Author

Nyholm commented Apr 19, 2021

The PR is updated. The docs team has an invitation to https://github.com/symfony-docs-tools

@Nyholm
Copy link
Member Author

Nyholm commented Apr 19, 2021

Here is an example output that shows both a syntax error and where a code block for config will cause an issue on bin/console cache:warmup.

Screenshot 2021-04-19 at 14 36 54

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a super fan of automated code validations ... because sometimes in docs we might want to show some code which is technically wrong (e.g. a method outside of a class) but we do that consciously because it makes sense in that context.

But, I know we've talked about this for some time inside the Docs Team, so I think we should give this a try in practice. That's why I'm voting in favor of it. Thanks Tobias!

javiereguiluz added a commit that referenced this pull request Apr 21, 2021
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Fixed syntax errors on 4.4

I ran the [new parser](#15257) on 4.4. There are about 130 more syntax errors that I decided not to fix. Some are false positives (ie a code example where we only have a PHP array). Others show some limitations of the parser. Ie, we cannot automatically detect a code block with no language, we currently assume it is PHP but that is not always correct.

This is the last fixes I'll do for 4.4.

Commits
-------

2a9103c Fixed syntax errors on 4.4
This was referenced Apr 21, 2021
@javiereguiluz
Copy link
Member

This is now merged! Thanks.

@javiereguiluz javiereguiluz merged commit 69c6ef7 into symfony:4.4 Apr 21, 2021
@Nyholm Nyholm deleted the code-block-verify branch April 21, 2021 09:11
@Nyholm
Copy link
Member Author

Nyholm commented Apr 21, 2021

Wohoo. It's going to be exiting to see how this works.

javiereguiluz added a commit that referenced this pull request Apr 21, 2021
This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

Fixed syntax error in 5.2

Here are the syntax errors I found when running the parser (#15257) on 5.2.

Commits
-------

9d1216e Fixed syntax error in 5.2
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