Skip to content

Commit

Permalink
New rule: No footnotes (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault authored Sep 12, 2023
1 parent 277d664 commit b1f1f57
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* [no_directive_after_shorthand](#no_directive_after_shorthand)
* [no_duplicate_use_statements](#no_duplicate_use_statements)
* [no_explicit_use_of_code_block_php](#no_explicit_use_of_code_block_php)
* [no_footnotes](#no_footnotes)
* [no_inheritdoc_in_code_examples](#no_inheritdoc_in_code_examples)
* [no_merge_conflict](#no_merge_conflict)
* [no_namespace_after_use_statements](#no_namespace_after_use_statements)
Expand Down Expand Up @@ -654,6 +655,18 @@ It's an example

#### Groups [`@Symfony`]

## `no_footnotes`

> _Make sure there is no footnotes_
#### Groups [`@Symfony`]

##### Invalid Examples :-1:

```rst
.. [5] A numerical footnote. Note
```

## `no_inheritdoc_in_code_examples`

#### Groups [`@Sonata`, `@Symfony`]
Expand Down
51 changes: 51 additions & 0 deletions src/Rule/NoFootnotes.php
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();
}
}
55 changes: 55 additions & 0 deletions tests/Rule/NoFootnotesTest.php
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'),
],
];
}
}

0 comments on commit b1f1f57

Please sign in to comment.