Skip to content

Commit cff4803

Browse files
Merge pull request #3 from PhilDaiguille/feat/enhancement-code
Feat/enhancement code
2 parents 7e92aa0 + 672b757 commit cff4803

41 files changed

Lines changed: 108 additions & 140 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
php: [8.2, 8.3, 8.4, 8.5]
14+
php: [8.2, 8.3, 8.4]
1515

1616
steps:
1717
- name: Checkout

.gitignore

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rules/Aria/AriaLabelRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void
2424
return;
2525
}
2626

27-
$tag = $this->collectUntil($tokenIndex, $tokens, '/>');
27+
$tag = $this->collectUntil($tokenIndex, $tokens, '>');
2828

2929
// If aria-label present and non-empty - OK
3030
if (preg_match('/aria-label\s*=\s*(?:"|\')([^"\']*)(?:"|\')/i', $tag, $m)) {

src/Rules/Aria/AriaRequiredAttrRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace TwigA11y\Rules\Aria;
66

7-
use TwigCsFixer\Rules\AbstractRule;
7+
use TwigA11y\Rules\AbstractA11yRule;
88
use TwigCsFixer\Token\Tokens;
99

10-
final class AriaRequiredAttrRule extends AbstractRule
10+
final class AriaRequiredAttrRule extends AbstractA11yRule
1111
{
1212
protected function process(int $tokenIndex, Tokens $tokens): void
1313
{
@@ -48,7 +48,8 @@ protected function process(int $tokenIndex, Tokens $tokens): void
4848
$tokenRef = $tokens->get(0);
4949
$this->addError(sprintf('Role "%s" requires attribute "%s".', $role, $attr), $tokenRef, 'AriaRequired.Missing');
5050

51-
break 2; // one error per file for tests
51+
// stop after first missing attribute found for test determinism
52+
return;
5253
}
5354
}
5455
}

src/Rules/Aria/AriaRoleRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace TwigA11y\Rules\Aria;
66

7-
use TwigCsFixer\Rules\AbstractRule;
7+
use TwigA11y\Rules\AbstractA11yRule;
88
use TwigCsFixer\Token\Token;
99
use TwigCsFixer\Token\Tokens;
1010

11-
final class AriaRoleRule extends AbstractRule
11+
final class AriaRoleRule extends AbstractA11yRule
1212
{
1313
protected function process(int $tokenIndex, Tokens $tokens): void
1414
{
@@ -43,7 +43,8 @@ protected function process(int $tokenIndex, Tokens $tokens): void
4343
$tokenRef = $tokens->get(0);
4444
$this->addError(sprintf('Invalid ARIA role "%s".', $role), $tokenRef, 'AriaRole.InvalidRole');
4545

46-
break; // one error per file for tests
46+
// stop after first invalid role for determinism in tests
47+
return;
4748
}
4849
}
4950
}

src/Rules/Aria/TabIndexRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function evaluate(Tokens $tokens, int $tokenIndex, callable $emit): void
2323
return;
2424
}
2525

26-
$tag = $this->collectUntil($tokenIndex, $tokens, '/>', 50);
26+
$tag = $this->collectUntil($tokenIndex, $tokens, '>', 50);
2727

2828
if (preg_match('/tabindex\s*=\s*(?:"|\')?([\-0-9]+)(?:"|\')?/i', $tag, $m)) {
2929
$num = (int) $m[1];

src/Rules/Forms/FormLabelRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void
2323
return;
2424
}
2525

26-
$opening = $this->collectUntil($tokenIndex, $tokens, '/>/');
26+
$opening = $this->collectUntil($tokenIndex, $tokens, '>');
2727

2828
// Check for for attribute
2929
if (preg_match('/\bfor\s*=\s*(?:"|\')([^"\']+)(?:"|\')/i', $opening)) {

src/Rules/Forms/InputLabelRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ protected function process(int $tokenIndex, Tokens $tokens): void
2323
return;
2424
}
2525

26-
$opening = $this->collectUntil($tokenIndex, $tokens, '/>', 50);
26+
// Use a simple literal terminator to avoid malformed regex patterns
27+
$opening = $this->collectUntil($tokenIndex, $tokens, '>', 50);
2728

2829
// Has aria-label? then OK
2930
if (preg_match('/\baria-label\s*=\s*("|\')/i', $opening)) {

src/Rules/Forms/SelectLabelRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void
2323
}
2424

2525
// Collect opening tag
26-
$opening = $this->collectUntil($tokenIndex, $tokens, '/>/');
26+
$opening = $this->collectUntil($tokenIndex, $tokens, '>');
2727

2828
$id = null;
2929
if (preg_match('/\bid\s*=\s*(?:"|\')([^"\']+)(?:"|\')/i', $opening, $m)) {

0 commit comments

Comments
 (0)