Esempio n. 1
0
    public function getExamples()
    {
        $message = 'The short syntax for PHP code (::) should be used here';
        return [[Text::fromString(<<<RST
A line ending with a nice colon:

.. code-block:: php

    echo 'You failed!';
RST
), [$this->getViolationProphet($message, 3)]], [Text::fromString(<<<RST
A line ending without a colon.

.. code-block:: php

    echo 'Correct!';

And one with::

.. code-block:: php

    echo 'You failed!';

And another good usage::

    echo 'Yes, you passed!';

At last:

.. code-block:: ruby

    puts 'You\\'re a good documentor!';
RST
), [$this->getViolationProphet($message, 3)], 'When ending with a colon, the shorthand should be used for PHP code blocks']];
    }
Esempio n. 2
0
 public function testCustomSearchStrategy()
 {
     $editor = $this->container->get('redaktilo.editor');
     $text = Text::fromString('');
     // Should not throw \Gnugat\Redaktilo\Search\PatternNotSupportedException
     $editor->hasBelow($text, false);
 }
Esempio n. 3
0
    public function getExamples()
    {
        $message = 'The first person ("I", "we", "let\'s") should always be avoided';
        return [[Text::fromString('I wrote this line!'), [$this->getViolationProphet($message, 1)], 'The usage of I is not allowed'], [Text::fromString(<<<RST
Let's make things worse...
and let's not improve it on this line.
RST
), [$this->getViolationProphet($message, 1), $this->getViolationProphet($message, 2)], 'The usage of let\'s is not allowed'], [Text::fromString('We are writing this line together...'), [$this->getViolationProphet($message, 1)], 'The usage of we is not allowed']];
    }
Esempio n. 4
0
    public function getExamples()
    {
        $message = 'All words, except from closed-class words, have to be capitalized: "%s"';
        return [[Text::fromString(<<<RST
A wrong capitalized title of A section
==========================
RST
), [$this->getViolationProphet(sprintf($message, 'A Wrong Capitalized Title of a Section'), 1)], 'All words should be capitalized, except from closed-class ones.']];
    }
 /** {@inheritDoc} */
 public function execute(array $input)
 {
     $text = $this->textSanitizer->sanitize($input);
     $pattern = $input['pattern'];
     $replacement = $input['replacement'];
     $content = $this->contentFactory->make($text);
     $replacedContent = preg_replace($pattern, $replacement, $content);
     $replacedText = Text::fromString($replacedContent);
     $text->setLines($replacedText->getLines());
 }
Esempio n. 6
0
    public function getExamples()
    {
        $message = 'The underline of a title should have exact the same length as the text of the title';
        return [[Text::fromString(<<<RST
A title
====
RST
), [$this->getViolationProphet($message, 2)], 'Underlines that are too short are invalid'], [Text::fromString(<<<RST
A title
===========
RST
), [$this->getViolationProphet($message, 2)], 'Underlines that are too long are invalid']];
    }
Esempio n. 7
0
    public function getExamples()
    {
        $message = 'There should be a space between "%s" and "%s".';
        return [[Text::fromString(<<<RST
:ref:`a label<the_reference>`
:ref:`other label <correct_reference>`
RST
), [$this->getViolationProphet(sprintf($message, 'a label', '<the_reference>'), 1)], 'Ref roles must have a space between label and reference'], [Text::fromString(<<<RST
:doc:`a label<the_reference>`
:doc:`other label <correct_reference>`
RST
), [$this->getViolationProphet(sprintf($message, 'a label', '<the_reference>'), 1)], 'Doc roles must have a space between label and reference']];
    }
Esempio n. 8
0
    public function getExamples()
    {
        $message = 'There should be no trailing whitespace at the end of a line';
        return [[Text::fromString(<<<RST
a file with just normal text
     
followed by nasty trailing whitespace

and a simple empty line.
RST
), [$this->getViolationProphet($message, 2)], 'Lines which contain only whitespace are not allowed'], [Text::fromString(<<<RST
a line with whitespace after it     
a tab is also whitespace\t
RST
), [$this->getViolationProphet($message, 1), $this->getViolationProphet($message, 2)], 'Whitespace at the end of a line is not allowed']];
    }
Esempio n. 9
0
    public function getExamples()
    {
        $message = 'The "%s" directive is not styled on symfony.com';
        return [[Text::fromString(<<<RST
.. warning::

    I am stoffing you!

.. caution::

    Yes, prefect.

.. danger::

    I may put a comment on each line of your PR
RST
), [$this->getViolationProphet(sprintf($message, 'warning'), 1), $this->getViolationProphet(sprintf($message, 'danger'), 10)], 'Usage of unstyled directives is not allowed.']];
    }
Esempio n. 10
0
    public function getExamples()
    {
        $message = 'There should be an empty line between the body and the start of a directive (except from versionadded directives)';
        return [[Text::fromString(<<<RST
.. note::
    The contents of the note.

.. code-block::

    // correct!
RST
), [$this->getViolationProphet($message, 1)], 'Admonitions started with `.. xxx::` require a blank line'], [Text::fromString(<<<RST
Let's try one more time::
    // come on, you know better...
RST
), [$this->getViolationProphet($message, 1)], 'Code blocks started with `::` require a blank line'], [Text::fromString(<<<RST
.. versionadded:: 2.5
    Do you know what was added in 2.5?

.. versionadded:: 2.5

    Do you know what was added in 2.5?
RST
), [$this->getViolationProphet('There should be no empty line between the start of a versionadded directive and the body', 4)], 'Version added directive should not have a blank line'], [Text::fromString(<<<RST
.. code-block:: php
    :linenums:

    // some code!
RST
), [], 'Directive options are allowed to be placed directly after the start'], [Text::fromString(<<<RST
.. index::
    single: Hello

.. index::

    single: Hello
RST
), [], 'Index directives do not require a blank line']];
    }
Esempio n. 11
0
    public function getExamples()
    {
        $levelMessage = 'The "%s" character should be used for a title level %d';
        $invalidMessage = 'Only =, -, ~, . and " should be used as title underlines';
        $incFile = File::fromString(<<<RST
Title level 3
~~~~~~~~~~~~~
RST
);
        $incFile->setFilename('file.rst.inc');
        return [[Text::fromString(<<<RST
Title Level 1
=============

Title level 2
~~~~~~~~~~~~~
RST
), [$this->getViolationProphet(sprintf($levelMessage, '-', 2), 2)], 'It finds wrongly used underline level'], [Text::fromString(<<<RST
Title Level 1
+++++++++++++
RST
), [$this->getViolationProphet($invalidMessage, 2)], 'It finds unused underline levels that are valid in reStructured Text'], [Text::fromString(<<<RST
Title level 1
=============

Title level 2
-------------

Title level 3
~~~~~~~~~~~~~

Title level 4
.............

Title level 2
-------------
RST
), [], 'It accepts jumping multiple levels back'], [$incFile, [], 'Inc files are allowed to start at deeper levels']];
    }
Esempio n. 12
0
    public function getExamples()
    {
        $proseMessage = 'A line should be wrapped after the first word that crosses the 72th character';
        $codeMessage = 'In order to avoid horizontal scrollbars, you should wrap the code on a 85 character limit';
        return [[Text::fromString(<<<RST
A line that does not reach the limit
A line that goes over the limit with a lot of words, as you can see in this sentence...
RST
), [$this->getViolationProphet($proseMessage, 2)], 'Prose lines should not have new words after the 72th character'], [Text::fromString('Tetaumatawhakatangihangakoauaotamateaurehaeaturipukapihimaungahoronukupokaiwhenuaakitanatahu'), [], 'Long words are allowed to have more than 72 characters'], [Text::fromString('**type**: ``string`` **default**: ``This is a long constraint error message, but it should be allowed.``'), [], 'Definitions are allowed to cross 72 characters'], [Text::fromString(<<<RST
.. code-block:: php

    // a line that is around 80 characters long, so there should not be an error here
    // but this should error, as it is longer than 80 characters long. Oh dear, what did I do?

Same applies to::

    // a line that is around 80 characters long, so there should not be an error here
    // but this should error, as it is longer than 80 characters long. Oh dear, what did I do?
RST
), [$this->getViolationProphet($codeMessage, 4), $this->getViolationProphet($codeMessage, 9)], 'Code uses a limit for 85 characters'], [Text::fromString(<<<RST
    .. code-block:: php

        // a line that is around 80 characters long, so there should not be an error here
            // the same line, but now indented, so that it should give us this very nice error
RST
), [$this->getViolationProphet($codeMessage, 4)], 'Indentation should be stripped from code blocks'], [Text::fromString(<<<RST
.. code-block:: xml

    <?xml version="1.0" encoding="UTF-8"?>
    <srv:container xmlns="http://symfony.com/schema/dic/security"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:srv="http://symfony.com/schema/dic/services"
        xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    </srv:container>
RST
), [], 'XML schemaLocation definitions are allowed to cross the 85 character limit']];
    }
Esempio n. 13
0
 public function getExamples()
 {
     $message = 'Serial (Oxford) comma\'s should be avoided: "[...] %s [...]"';
     return [[Text::fromString('One has an o, n, and e.'), [$this->getViolationProphet(sprintf($message, 'n and'), 1)], 'A comma before and in a list is a serial comma'], [Text::fromString('One is not two, three, or four.'), [$this->getViolationProphet(sprintf($message, 'three or'), 1)], 'A comma before or in a list is a serial comma']];
 }
Esempio n. 14
0
 public function getExamples()
 {
     return [[Text::fromString('This is probably some `wrong` backtick usage.'), [$this->getViolationProphet('Found unrecognized usage of backticks. Did you mean to create a link (`wrong`_) or a literal (``wrong``)?', 1)], 'Single backticks that are not roles or references were probably meant as literal'], [Text::fromString('This is some :ref:`correct` backtick usage.'), [], 'Roles are correct'], [Text::fromString('This is some `correct`_ backtick usage.'), [], 'References are correct']];
 }