Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validator spec via code generation #100

Merged
merged 109 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
3b8c1a6
Add script to generate validator spec
schlessera Dec 16, 2020
a46d07f
Add PHP generator dependency
schlessera Dec 16, 2020
8acc8d6
Add initial tag section support
schlessera Dec 16, 2020
02871ac
Reuse section class name
schlessera Dec 16, 2020
80dcc0f
Add IDs to tags and sort them accordingly
schlessera Dec 18, 2020
2a374c1
Add hashed data for tag access by tag name or spec name
schlessera Dec 18, 2020
367a715
Add retrieval methods for tags
schlessera Dec 18, 2020
f367ea8
Use relative namespaces in typehints
schlessera Dec 18, 2020
411c8c6
Add unit tests for spec sections
schlessera Dec 18, 2020
bdda53b
Add tests for tag retrieval
schlessera Dec 18, 2020
bc9cfaa
Create tags array in one assignment
schlessera Dec 18, 2020
df3619b
Make bySpecName() return a single Tag instead of an array
schlessera Dec 18, 2020
92c747c
Add docblock for dump() method
schlessera Dec 18, 2020
1dc873b
Add temporary internal data for all sections
schlessera Dec 23, 2020
ba6fb89
Extract compat testing out of regular PHPCS config
schlessera Jan 6, 2021
88358f1
Use existing tag constants
schlessera Jan 6, 2021
3917b65
Use constants as tag index
schlessera Jan 9, 2021
7c06565
Reuse constants in tag keys
schlessera Jan 9, 2021
27f8d00
Reuse constants in tag reference keys
schlessera Jan 9, 2021
cebe2cd
Reuse constants in spec reference keys
schlessera Jan 9, 2021
4ea4113
Add interface with constants for AMP formats.
schlessera Jan 9, 2021
067f3d0
Use format constants in tag definitions
schlessera Jan 9, 2021
bf53d92
Use constants for mandatoryParent
schlessera Jan 14, 2021
2178598
Use constants for mandatoryAncestor
schlessera Jan 14, 2021
7d452be
Use constants for mandatoryAncestorSuggestedAlternative
schlessera Jan 14, 2021
8ed42c8
Avoid constants for (broken) multi-word tags
schlessera Jan 14, 2021
1dafa33
Use custom array dumping with callback support
schlessera Jan 15, 2021
7feebc3
Use constants for ampLayout > supportedLayouts
schlessera Jan 15, 2021
50570fe
Refactor main generator loop
schlessera Jan 15, 2021
522cbe4
Use helper method for creating Tag class file
schlessera Jan 15, 2021
1a9a544
Add interface with error code constants
schlessera Jan 15, 2021
30cc18f
Improve error mappings
schlessera Jan 15, 2021
5508c6e
Refactor single-value sections into properties
schlessera Jan 15, 2021
effc3e4
Rearrange descendant tag lists
schlessera Jan 15, 2021
ae78c65
Rearrange and refactor declaration lists
schlessera Jan 15, 2021
09f4681
Write tests for retrieving declaration lists
schlessera Jan 15, 2021
3534f44
Add tests for declaration list
schlessera Jan 16, 2021
8c13ec0
Add CSS rules management
schlessera Jan 16, 2021
38ed92e
Rename cssRules section back to css
schlessera Jan 16, 2021
a66af99
Refactor declaration lists and include attribute lists
schlessera Jan 16, 2021
7d2e844
Add spec rule constants
schlessera Jan 16, 2021
bdd7e0b
Include more spec rules
schlessera Jan 16, 2021
0500995
Add querying of tags by HTML format
schlessera Jan 17, 2021
c7ed552
Add tests for byFormat querying
schlessera Jan 17, 2021
f20cf7d
Avoid cast to array
schlessera Jan 18, 2021
c8cf8bb
Use extension name for script tag IDs
schlessera Jan 20, 2021
4aefda7
Refactor file handling into a separate FileManager object
schlessera Jan 20, 2021
463fff1
Refactor VariableDumping trait into a Dumper instance
schlessera Jan 21, 2021
492b4fe
Adapt spec attributes within tag classes
schlessera Jan 25, 2021
6429401
Automatically add missing imports
schlessera Jan 26, 2021
bf8d18d
Avoid php language constructs as class names
schlessera Jan 26, 2021
3704a45
Refactor tags internal storage
schlessera Jan 26, 2021
2e68588
Use constants for protocol
schlessera Jan 26, 2021
09a3510
Use constants for requiresExtension
schlessera Jan 26, 2021
0f59e0b
Add missing spec rule constants
schlessera Jan 26, 2021
ab83fbe
Add constants for trigger rule
schlessera Jan 26, 2021
7c8abfe
Add constants for alternative names rule
schlessera Jan 26, 2021
d908aad
Reuse same dumping logic for all sections
schlessera Jan 26, 2021
b0c63ce
Use constants for i-amphtml-layout rule
schlessera Jan 26, 2021
e45bec8
Use constants for enabledBy & disabledBy rules
schlessera Jan 26, 2021
d4e8d7e
Use constants for name rule
schlessera Jan 26, 2021
5411fdf
Add more spec rule constants
schlessera Jan 26, 2021
c0f68f7
Add more defaults values to tag class
schlessera Jan 26, 2021
519d752
Add extension spec access
schlessera Jan 28, 2021
f37f500
Remove unused code in FileManager
schlessera Jan 29, 2021
23c1941
Turn lists into arrays of constants
schlessera Feb 3, 2021
4db3d01
Adapt handling of extension specs
schlessera Feb 15, 2021
901d148
Update to latest spec
schlessera Feb 18, 2021
a14149b
Fix getLatestVersion and add test
schlessera Feb 18, 2021
1ec5306
Add name and type queries to extension spec trait
schlessera Feb 19, 2021
4652f7f
Add missing interface method declarations for extension spec
schlessera Feb 19, 2021
d6abd11
Add link to PHPStan bug issue in ignore config
schlessera Feb 19, 2021
4967dad
Point to new issue in PHPStan config comment
schlessera Feb 19, 2021
90ed747
Re-add attribute constant that was lost on rebase
schlessera Mar 16, 2021
cbe4433
Update from JSON spec - 2021-03-16
schlessera Mar 16, 2021
c94741b
Use lower version of PHP generator engine
schlessera Mar 16, 2021
c5389bc
Add PHP code generator package to Composer suggestions
schlessera Mar 17, 2021
6e2b7c2
Fail gracefully when PHP generator is not present
schlessera Mar 17, 2021
513b12a
Update constants in Tags section
schlessera Mar 17, 2021
159a54e
Ignore bin/ folder for code coverage
schlessera Mar 29, 2021
315a4e1
Make Tags object iterable
schlessera Mar 29, 2021
b8637be
Update to latest spec - 2021-03-29
schlessera Mar 29, 2021
5fec999
Add tests for exceptions
schlessera Mar 29, 2021
c1c50a1
Refactor iteration array initialization
schlessera Mar 29, 2021
4f1f5e8
Fix test failures
schlessera Apr 30, 2021
2b29c7a
Update to latest spec - 2021-04-30
schlessera Apr 30, 2021
7a95cca
Add missing spec rule keys to dumper
schlessera Apr 30, 2021
895ce1c
Improve attribute lists section
schlessera May 3, 2021
1f86857
Update spec
schlessera May 20, 2021
8733946
Remove bad extend
schlessera May 20, 2021
0325f36
Refactor declaration and descendant tag lists
schlessera May 20, 2021
2be3767
Use constants for attribute list IDs
schlessera May 20, 2021
31bf3b3
Remove PHP code generator dependency again
schlessera May 20, 2021
35e806a
Add missing docblocks
schlessera May 21, 2021
6406cdf
Refactor ID retrieval
schlessera May 21, 2021
4083fe8
Reuse tag IDs as constants
schlessera May 21, 2021
039eda8
Improve tests for individual entities
schlessera May 21, 2021
a2c6db1
Improve test cover annotations
schlessera May 21, 2021
1ba80ec
Refactor CSS rulesets
schlessera May 21, 2021
2eb8982
Refactor doc section
schlessera May 21, 2021
a0a69ef
Add missing exception tests
schlessera May 21, 2021
ca64667
Refactor errors section
schlessera May 21, 2021
3944808
Remove duplicate bin exclusion in codecov config
schlessera May 26, 2021
901b2cf
Remove unneeded files
schlessera May 26, 2021
1312057
Improve automatic import additions
schlessera May 26, 2021
65839b7
Improve docblocks for generated classes
schlessera May 26, 2021
801419d
Fix spelling
westonruter Jun 1, 2021
7d9a1c1
Add progress messages to generate-validator-spec.php
westonruter Jun 1, 2021
1004f23
Fix blank line CS fail
schlessera Jun 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 15 additions & 11 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
<exclude name="PSR12.Properties.ConstantVisibility.NotFound" />
</rule>

<!-- Include sniffs for PHP cross-version compatibility. -->
<config name="testVersion" value="5.6-"/>
<rule ref="PHPCompatibilityWP">
<exclude-pattern>bin/*</exclude-pattern>
</rule>

<arg value="p"/>
<arg value="s"/>
<arg name="extensions" value="php"/>

Expand All @@ -25,14 +20,23 @@
<arg name="basepath" value="./"/>

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20"/>
<arg name="parallel" value="1"/>

<!-- Executable scripts are meant to have side-effects. -->
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>bin/*</exclude-pattern>
</rule>
<!-- Executable scripts are meant to have side-effects. -->
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>bin/*</exclude-pattern>
</rule>

<!-- Line length can not easily be controlled in generated code. -->
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>src/Validator/ErrorCode.php</exclude-pattern>
<exclude-pattern>src/Validator/Spec.php</exclude-pattern>
<exclude-pattern>src/Validator/Spec/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Class names that conflict with PHP reserved keywords need to be sufixed. -->
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>src/Validator/Spec/Tag/*_.php</exclude-pattern>
</rule>
</ruleset>
50 changes: 50 additions & 0 deletions bin/generate-validator-spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env php
<?php

use AmpProject\Tooling\Validator\SpecGenerator;

require dirname(__DIR__) . '/vendor/autoload.php';

if (! class_exists('Nette\PhpGenerator\ClassType')) {
echo "ERROR: The optional package nette/php-generator is needed for code generation.\n";
echo "Install the package via the following Composer command:\n";
echo "composer require --dev nette/php-generator:^3.5\n";
exit -1;
}

$specGenerator = new SpecGenerator();
$destination = !empty($argv[1]) ? $argv[1] : dirname(__DIR__) . '/src/Validator';

function recursivelyRemoveDirectory($directory)
{
if (is_dir($directory)) {
$objects = scandir($directory);

foreach ($objects as $object) {
if ($object !== '.' && $object !== '..') {
$filePath = "{$directory}/{$object}";

if (is_dir($filePath) && ! is_link($filePath)) {
recursivelyRemoveDirectory($filePath);
} else {
unlink($filePath);
}
}
}

rmdir($directory);
}
}

try {
recursivelyRemoveDirectory($destination);

$specGenerator->generate(
json_decode(file_get_contents('https://cdn.ampproject.org/v0/validator.json'), true),
'AmpProject\Validator',
$destination
);
} catch (Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
exit -1;
}
Loading