-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
277d664
commit b1f1f57
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of DOCtor-RST. | ||
* | ||
* (c) Oskar Stark <oskarstark@googlemail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Rule; | ||
|
||
use App\Attribute\Rule\Description; | ||
use App\Attribute\Rule\InvalidExample; | ||
use App\Rst\RstParser; | ||
use App\Value\Lines; | ||
use App\Value\NullViolation; | ||
use App\Value\RuleGroup; | ||
use App\Value\Violation; | ||
use App\Value\ViolationInterface; | ||
#[Description('Make sure there is no footnotes')] | ||
#[InvalidExample('.. [5] A numerical footnote. Note')] | ||
class NoFootnotes extends AbstractRule implements LineContentRule | ||
{ | ||
public static function getGroups(): array | ||
{ | ||
return [ | ||
RuleGroup::Symfony(), | ||
]; | ||
} | ||
|
||
public function check(Lines $lines, int $number, string $filename): ViolationInterface | ||
{ | ||
$lines->seek($number); | ||
$line = $lines->current(); | ||
|
||
if (RstParser::isFootnote($lines->current())) { | ||
return Violation::from( | ||
"Please don't use footnotes as they are not supported", | ||
$filename, | ||
$number + 1, | ||
$line, | ||
); | ||
} | ||
|
||
return NullViolation::create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of DOCtor-RST. | ||
* | ||
* (c) Oskar Stark <oskarstark@googlemail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Tests\Rule; | ||
|
||
use App\Rule\NoFootnotes; | ||
use App\Tests\RstSample; | ||
use App\Value\NullViolation; | ||
use App\Value\Violation; | ||
use App\Value\ViolationInterface; | ||
|
||
final class NoFootnotesTest extends \App\Tests\UnitTestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider checkProvider | ||
*/ | ||
public function check(ViolationInterface $expected, RstSample $sample): void | ||
{ | ||
self::assertEquals( | ||
$expected, | ||
(new NoFootnotes())->check($sample->lines(), $sample->lineNumber(), 'filename'), | ||
); | ||
} | ||
|
||
public static function checkProvider(): array | ||
{ | ||
return [ | ||
[ | ||
Violation::from( | ||
"Please don't use footnotes as they are not supported", | ||
'filename', | ||
1, | ||
'.. [5] A numerical footnote. Note', | ||
), | ||
new RstSample('.. [5] A numerical footnote. Note'), | ||
], | ||
[ | ||
NullViolation::create(), | ||
new RstSample('.. _`Symfony`: https://symfony.com'), | ||
], | ||
]; | ||
} | ||
} |