Skip to content

Commit

Permalink
Merge pull request #117 from Lullabot/handle-deprecation
Browse files Browse the repository at this point in the history
Issue deprecation tag warnings
  • Loading branch information
sidkshatriya committed Jun 29, 2016
2 parents 30344de + d9d6ea3 commit d481454
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function clear()
$this->options = [];
$this->component_js = [];
$this->validation_result = new SValidationResult();
$this->validation_result->status = ValidationResultStatus::FAIL;
$this->validation_result->status = ValidationResultStatus::UNKNOWN;
$this->context = null;
$this->scope = Scope::BODY_SCOPE;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Pass/StandardScanPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function pass()
// This will be used by the StatisticsPass
$this->context->setNumTagsProcessed($count);
$this->parsed_rules->maybeEmitGlobalTagValidationErrors($this->context, $this->validation_result, $this);
$this->parsed_rules->endValidation($this->validation_result);

return [];
}
}
5 changes: 2 additions & 3 deletions src/Validate/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ public function ignoreError()
}

/**
* @param $line
* @param $validation_error_code
* @param int|string $line
* @param string $validation_error_code
* @param array $params
* @param $spec_url
* @param SValidationResult $validation_result
Expand Down Expand Up @@ -516,7 +516,6 @@ public function getTagspecsValidated()
*/
public static function severityFor($validation_error_code)
{
// @todo make more error codes less severe as we're going to be able to fix some of them
if ($validation_error_code === ValidationErrorCode::DEPRECATED_TAG) {
return ValidationErrorSeverity::WARNING;
} else if ($validation_error_code == ValidationErrorCode::DEPRECATED_ATTR) {
Expand Down
18 changes: 18 additions & 0 deletions src/Validate/ParsedValidatorRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ public function validateTagAgainstSpec(ParsedTagSpec $parsed_spec, Context $cont
$result_for_best_attempt->status = $result_for_attempt->status;
$result_for_best_attempt->errors = $result_for_attempt->errors;

/** @var TagSpec $spec */
$spec = $parsed_spec->getSpec();
if (!empty($spec->deprecation)) {
$context->addError(ValidationErrorCode::DEPRECATED_TAG, [ParsedTagSpec::getTagSpecName($spec), $spec->deprecation], $spec->deprecation_url, $result_for_best_attempt);
// don't return as its just a warning, see Context::severityFor()
}

if ($parsed_spec->shouldRecordTagspecValidated()) {
$is_unique = $context->recordTagspecValidated($parsed_spec);
if ($parsed_spec->getSpec()->unique && $is_unique !== true) {
Expand Down Expand Up @@ -382,4 +389,15 @@ public function maybeEmitGlobalTagValidationErrors(Context $context, SValidation
}
$this->maybeEmitMandatoryAlternativesSatisfiedErrors($context, $validation_result);
}

/**
* Call this at the end of the validation
* @param SValidationResult $validation_result
*/
public function endValidation(SValidationResult $validation_result)
{
if ($validation_result->status == ValidationResultStatus::UNKNOWN) {
$validation_result->status = ValidationResultStatus::PASS;
}
}
}
7 changes: 2 additions & 5 deletions src/Validate/RenderValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ public function renderValidationResult(SValidationResult $validation_result, $fi
$this->annotateWithErrorCategories($validation_result);
$this->sortValidationWarningsByLineno($validation_result);
/** @var string $rendered */
if (empty($validation_result->errors)) {
$rendered = 'PASS' . PHP_EOL;
} else {
$rendered = $validation_result->status . PHP_EOL;
}
$rendered = $validation_result->status . PHP_EOL;

/** @var SValidationError $validation_error */
$last_context_string = null;
$last_dom_tag = null;
Expand Down
3 changes: 3 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ Note: An explicit commit is noted as these files can change.
* `test-data/full-html/mandatory-dimensions.html` https://github.com/ampproject/amphtml/blob/e1aa24df8432963423ee6cec1ce4d57529767e6e/validator/testdata/feature_tests/mandatory_dimensions.html
There is a trivial modification: `</amp-anum>` is changed to `</amp-anim>`. See https://github.com/ampproject/amphtml/issues/3609
* `test-data/full-html/minimum_valid_amp.html` https://github.com/ampproject/amphtml/blob/96335e0540532264b3b38d498070f17473692b21/validator/testdata/feature_tests/minimum_valid_amp.html
* `test-data/full-html/new_and_old_boilerplate_mixed.html` https://github.com/ampproject/amphtml/blob/3bd74c3915f9e29824eebedbf6f14f6c531a3449/validator/testdata/feature_tests/new_and_old_boilerplate_mixed.html
* `test-data/full-html/new_and_old_boilerplate_mixed2.html` https://github.com/ampproject/amphtml/blob/d17719548ca786ec8c3778743da7f2020c7d0460/validator/testdata/feature_tests/new_and_old_boilerplate_mixed2.html
* `test-data/full-html/no_custom_js.html` https://github.com/ampproject/amphtml/blob/96335e0540532264b3b38d498070f17473692b21/validator/testdata/feature_tests/no_custom_js.html
* `test-data/full-html/noscript.html` https://github.com/ampproject/amphtml/blob/e1aa24df8432963423ee6cec1ce4d57529767e6e/validator/testdata/feature_tests/noscript.html
* `test-data/full-html/old-boilerplate.amp.html` https://github.com/ampproject/amphtml/blob/0a056ca50ac8cb9ba8e5a6489baeecb5ed958556/examples/old-boilerplate.amp.html
* `test-data/full-html/regexps.html` https://github.com/ampproject/amphtml/blob/de471567c924ce51e401248ef69c001cee599cfc/validator/testdata/feature_tests/regexps.html
There is a slight custom modification made by us to this file (see our repo's 36c67aace ) and that is to close the `<amp-audio>` tags in the file that are not closed. This causes problems for PHP dom.
* `test-data/full-html/several_errors.html` from https://github.com/ampproject/amphtml/blob/96335e0540532264b3b38d498070f17473692b21/validator/testdata/feature_tests/several_errors.html
Expand Down
34 changes: 34 additions & 0 deletions tests/test-data/full-html/new_and_old_boilerplate_mixed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
-->
<!--
Test Description:
This test contains the new boilerplate in the javascript-enabled version
but the old, opacity-based one inside noscript. This is not allowed.
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style>body {opacity: 1}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello, world.
</body>
</html>
89 changes: 89 additions & 0 deletions tests/test-data/full-html/new_and_old_boilerplate_mixed.html.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<!--
Copyright 2015 The AMP HTML Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
--><!--
Test Description:
This test contains the new boilerplate in the javascript-enabled version
but the old, opacity-based one inside noscript. This is not allowed.
--><html amp><head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style>body {opacity: 1}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello, world.
</body>

</html>


ORIGINAL HTML
---------------
Line 1: <!--
Line 2: Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Line 3:
Line 4: Licensed under the Apache License, Version 2.0 (the "License");
Line 5: you may not use this file except in compliance with the License.
Line 6: You may obtain a copy of the License at
Line 7:
Line 8: http://www.apache.org/licenses/LICENSE-2.0
Line 9:
Line 10: Unless required by applicable law or agreed to in writing, software
Line 11: distributed under the License is distributed on an "AS-IS" BASIS,
Line 12: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Line 13: See the License for the specific language governing permissions and
Line 14: limitations under the license.
Line 15: -->
Line 16: <!--
Line 17: Test Description:
Line 18: This test contains the new boilerplate in the javascript-enabled version
Line 19: but the old, opacity-based one inside noscript. This is not allowed.
Line 20: -->
Line 21: <!doctype html>
Line 22: <html ⚡>
Line 23: <head>
Line 24: <meta charset="utf-8">
Line 25: <link rel="canonical" href="./regular-html-version.html" />
Line 26: <meta name="viewport" content="width=device-width,minimum-scale=1">
Line 27: <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
Line 28: <noscript><style>body {opacity: 1}</style></noscript>
Line 29: <script async src="https://cdn.ampproject.org/v0.js"></script>
Line 30: </head>
Line 31: <body>
Line 32: Hello, world.
Line 33: </body>
Line 34: </html>
Line 35:



AMP-HTML Validation Issues and Fixes
-------------------------------------
FAIL

<style> on line 28
- The tag 'noscript > style[amp-boilerplate] - old variant' is deprecated - use 'noscript > style[amp-boilerplate]' instead.
[code: DEPRECATED_TAG category: DEPRECATION see: https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md]

GLOBAL WARNING
- The tag 'noscript > style[amp-boilerplate]' is missing or incorrect, but required by 'head > style[amp-boilerplate]'.
[code: TAG_REQUIRED_BY_MISSING category: GENERIC see: https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md]

COMPONENT NAMES WITH JS PATH
------------------------------
No custom amp script includes required
35 changes: 35 additions & 0 deletions tests/test-data/full-html/new_and_old_boilerplate_mixed2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
-->
<!--
Test Description:
This test contains the old, opacity-based boilerplate in the
javascript-enabled version, but the new one inside noscript. This is
not allowed.
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style>body {opacity: 0}</style>
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello, world.
</body>
</html>
91 changes: 91 additions & 0 deletions tests/test-data/full-html/new_and_old_boilerplate_mixed2.html.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<!--
Copyright 2015 The AMP HTML Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
--><!--
Test Description:
This test contains the old, opacity-based boilerplate in the
javascript-enabled version, but the new one inside noscript. This is
not allowed.
--><html amp><head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style>body {opacity: 0}</style>
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello, world.
</body>

</html>


ORIGINAL HTML
---------------
Line 1: <!--
Line 2: Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Line 3:
Line 4: Licensed under the Apache License, Version 2.0 (the "License");
Line 5: you may not use this file except in compliance with the License.
Line 6: You may obtain a copy of the License at
Line 7:
Line 8: http://www.apache.org/licenses/LICENSE-2.0
Line 9:
Line 10: Unless required by applicable law or agreed to in writing, software
Line 11: distributed under the License is distributed on an "AS-IS" BASIS,
Line 12: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Line 13: See the License for the specific language governing permissions and
Line 14: limitations under the license.
Line 15: -->
Line 16: <!--
Line 17: Test Description:
Line 18: This test contains the old, opacity-based boilerplate in the
Line 19: javascript-enabled version, but the new one inside noscript. This is
Line 20: not allowed.
Line 21: -->
Line 22: <!doctype html>
Line 23: <html ⚡>
Line 24: <head>
Line 25: <meta charset="utf-8">
Line 26: <link rel="canonical" href="./regular-html-version.html" />
Line 27: <meta name="viewport" content="width=device-width,minimum-scale=1">
Line 28: <style>body {opacity: 0}</style>
Line 29: <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
Line 30: <script async src="https://cdn.ampproject.org/v0.js"></script>
Line 31: </head>
Line 32: <body>
Line 33: Hello, world.
Line 34: </body>
Line 35: </html>
Line 36:



AMP-HTML Validation Issues and Fixes
-------------------------------------
FAIL

<style> on line 28
- The tag 'head > style[amp-boilerplate] - old variant' is deprecated - use 'head > style[amp-boilerplate]' instead.
[code: DEPRECATED_TAG category: DEPRECATION see: https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md]

GLOBAL WARNING
- The tag 'head > style[amp-boilerplate]' is missing or incorrect, but required by 'noscript > style[amp-boilerplate]'.
[code: TAG_REQUIRED_BY_MISSING category: GENERIC see: https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md]

COMPONENT NAMES WITH JS PATH
------------------------------
No custom amp script includes required
20 changes: 20 additions & 0 deletions tests/test-data/full-html/old-boilerplate.amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<title>Twitter examples</title>
<link rel="canonical" href="amps.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
<style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h1>AMP boilerplate</h1>
<h2>Testing if the old validator is still accepted.</h2>
<p>
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
</p>
</body>
</html>
Loading

0 comments on commit d481454

Please sign in to comment.