Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Helper/PhpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace App\Helper;

use App\Rst\RstParser;
use App\Value\Line;
use App\Value\Lines;

Expand Down Expand Up @@ -116,4 +117,27 @@ public function isPartOfMultilineComment(Lines $lines, int $number): bool

return false;
}

public function isPartOfTable(Lines $lines, int $number): bool
{
$lines->seek($number);

$i = $number;

while (1 <= $i) {
--$i;

$lines->seek($i);

if ($lines->current()->isBlank()) {
continue;
}

if (RstParser::isTable($lines->current())) {
return true;
}
}

return false;
}
}
5 changes: 5 additions & 0 deletions src/Rule/Indention.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Indention extends AbstractRule implements Configurable, LineContentRule
{
use DirectiveTrait;
use ListTrait;

private int $size;

public function configureOptions(OptionsResolver $resolver): OptionsResolver
Expand Down Expand Up @@ -136,6 +137,10 @@ public function check(Lines $lines, int $number, string $filename): ViolationInt
$minus = 3;
}

if ((new PhpHelper())->isPartOfTable($lines, $number)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tests are broken, because sections https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#sections are considered as table in RstParser

Do you have an idea ?

Copy link
Owner

Choose a reason for hiding this comment

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

Indeed, I believe this is the precise issue I encountered when I previously attempted to address this situation.

Lets not invest too much time then

return NullViolation::create();
}

if (0 < $indention && 0 < (($indention - $minus) % $this->size)) {
$message = $customMessage ?? sprintf('Please add %s spaces for every indention.', $this->size);

Expand Down
19 changes: 19 additions & 0 deletions tests/Rule/IndentionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,25 @@ public function onKernelController(FilterControllerEvent $event)
RST
, 5),
];
yield 'table multiline' => [
NullViolation::create(),
4,
new RstSample(<<<'RST'
Possible options to configure with the attribute are:

============================ ====================================================================================================
Option Description
============================ ====================================================================================================
``bus`` Name of the bus from which the handler can receive messages, by default all buses.
``fromTransport`` Name of the transport from which the handler can receive messages, by default all transports.
``handles`` Type of messages (FQCN) that can be processed by the handler, only needed if can't be guessed by
type-hint.
``method`` Name of the method that will process the message, only if the target is a class.
``priority`` Priority of the handler when multiple handlers can process the same message.
============================ ====================================================================================================
RST
, 8),
];
}

/**
Expand Down