add support for checking examples in rst documentations #1

Merged
merged 1 commit into from May 29, 2016

Conversation

Projects
None yet
2 participants
@agallou
Contributor

agallou commented May 25, 2016

tested on atoum/atoum-documentation#209
Rusty allowed us to find some errors. Thanks.

+ {
+ $parser = new Parser();
+
+ $parser->getEnvironment()->setErrorManager(new class() extends ErrorManager {

This comment has been minimized.

@K-Phoen

K-Phoen May 26, 2016

Owner

Why do we need to do that? Is it going to silence parse errors in the document?

@K-Phoen

K-Phoen May 26, 2016

Owner

Why do we need to do that? Is it going to silence parse errors in the document?

This comment has been minimized.

@agallou

agallou May 26, 2016

Contributor

Because some directives are not supported by the parser (we only need the code example directives). And when it appends an ugly echo is made : https://github.com/Gregwar/RST/blob/master/ErrorManager.php#L19. This anonymous class prevents that.

@agallou

agallou May 26, 2016

Contributor

Because some directives are not supported by the parser (we only need the code example directives). And when it appends an ugly echo is made : https://github.com/Gregwar/RST/blob/master/ErrorManager.php#L19. This anonymous class prevents that.

+ $fileContent = file_get_contents($file->getRealPath());
+
+ /** @var \Gregwar\RST\HTML\Document $document */
+ $document = @$parser->parse($fileContent);

This comment has been minimized.

@K-Phoen

K-Phoen May 26, 2016

Owner

Same here, why do we need the @ operator?

@K-Phoen

K-Phoen May 26, 2016

Owner

Same here, why do we need the @ operator?

This comment has been minimized.

@agallou

agallou May 26, 2016

Contributor

When reading the rst file, the parser tries to read the include statements and then reading those files without testing if the file exists. So without this, and defining a current directory to the parser. A lot of warnings could occur and they will be useless because rusty will already find all the files in the folder.

@agallou

agallou May 26, 2016

Contributor

When reading the rst file, the parser tries to read the include statements and then reading those files without testing if the file exists. So without this, and defining a current directory to the parser. A lot of warnings could occur and they will be useless because rusty will already find all the files in the folder.

+ });
+
+ foreach ($nodes as $node) {
+ if ($node->getLanguage() != 'php') {

This comment has been minimized.

@K-Phoen

K-Phoen May 26, 2016

Owner

Would it make sense to do this check when we are retrieving the CodeNode objects?

@K-Phoen

K-Phoen May 26, 2016

Owner

Would it make sense to do this check when we are retrieving the CodeNode objects?

This comment has been minimized.

@agallou

agallou May 26, 2016

Contributor

yes, because codeNodes could be ruby, bash, shell or other languages. This test ensures that we will only get php examples.

Example :

.. code-block:: php
@agallou

agallou May 26, 2016

Contributor

yes, because codeNodes could be ruby, bash, shell or other languages. This test ensures that we will only get php examples.

Example :

.. code-block:: php
@K-Phoen

This comment has been minimized.

Show comment
Hide comment
@K-Phoen

K-Phoen May 26, 2016

Owner

Awesome, thanks for this PR! 👍

Owner

K-Phoen commented May 26, 2016

Awesome, thanks for this PR! 👍

@K-Phoen K-Phoen merged commit d466089 into K-Phoen:master May 29, 2016

2 checks passed

Scrutinizer 6 updated code elements
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@K-Phoen

This comment has been minimized.

Show comment
Hide comment
@K-Phoen

K-Phoen May 29, 2016

Owner

Merged, thanks :)

Owner

K-Phoen commented May 29, 2016

Merged, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment