Skip to content
Merged
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
20 changes: 18 additions & 2 deletions README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions src/Standard/A11yBasicStandard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace TwigA11y\Standard;

use TwigA11y\Rules\Media\ImgAltRule;
use TwigA11y\Rules\Structure\BannedTagsRule;
use TwigCsFixer\Rules\RuleInterface;
use TwigCsFixer\Standard\StandardInterface;

Expand All @@ -16,9 +14,6 @@ final class A11yBasicStandard implements StandardInterface
*/
public function getRules(): array
{
return [
new ImgAltRule(),
new BannedTagsRule(),
];
return StandardRuleSets::basic();
}
}
10 changes: 1 addition & 9 deletions src/Standard/A11yRecommendedStandard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace TwigA11y\Standard;

use TwigA11y\Rules\Media\ImgAltRule;
use TwigA11y\Rules\Structure\BannedTagsRule;
use TwigA11y\Rules\Structure\HeadingOrderRule;
use TwigCsFixer\Rules\RuleInterface;
use TwigCsFixer\Standard\StandardInterface;

Expand All @@ -17,11 +14,6 @@ final class A11yRecommendedStandard implements StandardInterface
*/
public function getRules(): array
{
// Recommended includes basic rules plus heading order.
return [
new ImgAltRule(),
new BannedTagsRule(),
new HeadingOrderRule(),
];
return StandardRuleSets::recommended();
}
}
10 changes: 1 addition & 9 deletions src/Standard/A11yStandard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace TwigA11y\Standard;

use TwigA11y\Rules\Media\ImgAltRule;
use TwigA11y\Rules\Structure\BannedTagsRule;
use TwigA11y\Rules\Structure\HeadingOrderRule;
use TwigCsFixer\Rules\RuleInterface;
use TwigCsFixer\Standard\StandardInterface;

Expand All @@ -22,11 +19,6 @@ final class A11yStandard implements StandardInterface
*/
public function getRules(): array
{
return [
// Keep these unitary rules here.
new ImgAltRule(),
new BannedTagsRule(),
new HeadingOrderRule(),
];
return StandardRuleSets::standard();
}
}
50 changes: 1 addition & 49 deletions src/Standard/A11yStrict.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@

namespace TwigA11y\Standard;

use TwigA11y\Rules\Aria\AriaHiddenFocusRule;
use TwigA11y\Rules\Aria\AriaLabelRule;
use TwigA11y\Rules\Aria\AriaRequiredAttrRule;
use TwigA11y\Rules\Aria\AriaRoleRule;
use TwigA11y\Rules\Aria\TabIndexRule;
use TwigA11y\Rules\Forms\FormLabelRule;
use TwigA11y\Rules\Forms\InputLabelRule;
use TwigA11y\Rules\Forms\SelectLabelRule;
use TwigA11y\Rules\Forms\TextareaLabelRule;
use TwigA11y\Rules\Media\AutoplayRule;
use TwigA11y\Rules\Media\ImgAltRule;
use TwigA11y\Rules\Media\ObjectAltRule;
use TwigA11y\Rules\Structure\AnchorContentRule;
use TwigA11y\Rules\Structure\BannedTagsRule;
use TwigA11y\Rules\Structure\ButtonContentRule;
use TwigA11y\Rules\Structure\HeadingEmptyRule;
use TwigA11y\Rules\Structure\HeadingOrderRule;
use TwigA11y\Rules\Structure\IframeTitleRule;
use TwigA11y\Rules\Structure\LangAttributeRule;
use TwigA11y\Rules\Structure\MetaViewportRule;
use TwigCsFixer\Rules\RuleInterface;
use TwigCsFixer\Standard\StandardInterface;

Expand All @@ -42,34 +22,6 @@ final class A11yStrict implements StandardInterface
*/
public function getRules(): array
{
return [
// Media
new ImgAltRule(),
new AutoplayRule(),
new ObjectAltRule(),

// Structure
new BannedTagsRule(),
new ButtonContentRule(),
new AnchorContentRule(),
new HeadingOrderRule(),
new HeadingEmptyRule(),
new LangAttributeRule(),
new IframeTitleRule(),
new MetaViewportRule(),

// ARIA
new TabIndexRule(),
new AriaRoleRule(),
new AriaLabelRule(),
new AriaHiddenFocusRule(),
new AriaRequiredAttrRule(),

// Forms
new FormLabelRule(),
new InputLabelRule(),
new SelectLabelRule(),
new TextareaLabelRule(),
];
return StandardRuleSets::strict();
}
}
129 changes: 129 additions & 0 deletions src/Standard/StandardRuleSets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

declare(strict_types=1);

namespace TwigA11y\Standard;

use TwigA11y\Rules\Aria\AriaHiddenFocusRule;
use TwigA11y\Rules\Aria\AriaLabelRule;
use TwigA11y\Rules\Aria\AriaRequiredAttrRule;
use TwigA11y\Rules\Aria\AriaRoleRule;
use TwigA11y\Rules\Aria\TabIndexRule;
use TwigA11y\Rules\Forms\FormLabelRule;
use TwigA11y\Rules\Forms\InputLabelRule;
use TwigA11y\Rules\Forms\InputTypeRule;
use TwigA11y\Rules\Forms\SelectLabelRule;
use TwigA11y\Rules\Forms\TextareaLabelRule;
use TwigA11y\Rules\Media\AutoplayRule;
use TwigA11y\Rules\Media\ImgAltRule;
use TwigA11y\Rules\Media\ObjectAltRule;
use TwigA11y\Rules\Media\VideoTrackRule;
use TwigA11y\Rules\Structure\AnchorContentRule;
use TwigA11y\Rules\Structure\BannedTagsRule;
use TwigA11y\Rules\Structure\ButtonContentRule;
use TwigA11y\Rules\Structure\DuplicateIdRule;
use TwigA11y\Rules\Structure\HeadingEmptyRule;
use TwigA11y\Rules\Structure\HeadingOrderRule;
use TwigA11y\Rules\Structure\IframeTitleRule;
use TwigA11y\Rules\Structure\LandmarkRule;
use TwigA11y\Rules\Structure\LangAttributeRule;
use TwigA11y\Rules\Structure\MetaViewportRule;
use TwigA11y\Rules\Structure\SkipLinkRule;
use TwigA11y\Rules\Structure\TableHeaderRule;
use TwigA11y\Rules\Ui\ColorContrastRule;
use TwigCsFixer\Rules\RuleInterface;

final class StandardRuleSets
{
/**
* @return list<RuleInterface>
*/
public static function basic(): array
{
return self::instantiate([
ImgAltRule::class,
BannedTagsRule::class,
ButtonContentRule::class,
InputLabelRule::class,
LangAttributeRule::class,
]);
}

/**
* @return list<RuleInterface>
*/
public static function recommended(): array
{
return self::instantiate([
...self::classes(self::basic()),
ObjectAltRule::class,
VideoTrackRule::class,
HeadingOrderRule::class,
IframeTitleRule::class,
DuplicateIdRule::class,
LandmarkRule::class,
FormLabelRule::class,
SelectLabelRule::class,
TextareaLabelRule::class,
]);
}

/**
* @return list<RuleInterface>
*/
public static function standard(): array
{
return self::instantiate([
...self::classes(self::recommended()),
AutoplayRule::class,
AnchorContentRule::class,
HeadingEmptyRule::class,
MetaViewportRule::class,
SkipLinkRule::class,
TableHeaderRule::class,
TabIndexRule::class,
InputTypeRule::class,
]);
}

/**
* @return list<RuleInterface>
*/
public static function strict(): array
{
return self::instantiate([
...self::classes(self::standard()),
AriaRoleRule::class,
AriaLabelRule::class,
AriaHiddenFocusRule::class,
AriaRequiredAttrRule::class,
ColorContrastRule::class,
]);
}

/**
* @param list<class-string<RuleInterface>> $classes
*
* @return list<RuleInterface>
*/
private static function instantiate(array $classes): array
{
return array_map(
static fn (string $class): RuleInterface => new $class(),
$classes
);
}

/**
* @param list<RuleInterface> $rules
*
* @return list<class-string<RuleInterface>>
*/
private static function classes(array $rules): array
{
return array_map(
static fn (RuleInterface $rule): string => $rule::class,
$rules
);
}
}
Loading
Loading