Extract the bits using the custom asciidoctor to a dedicated file.
This new script uses `set -e` to catch unexpected errors.
It is also covered with integration tests that get executed on the CI.
This serves as the groundwork to integrate more advanced validation
tests.
The previous validation code was taking about 3 minutes when running on
all rules, which is the case when modifying anything outside rules/,
including shared_content/.
The runtime was marginal when only the content specific to one rule was
modified, e.g. only rules/S100/cfamily/rule.adoc is modified.
The new validation code always takes about 30 seconds on the CI. This is
a slight increase for small PR but a large reduction for PR affecting
the whole system.
Furthermore, the new approach validates includes and cross-references
properly. An issue is now raised when:
* The last include to shared_content/lang/foo.adoc is removed.
* A shared_content doc includes a file from another rule, e.g.
rules/S100/lang/rule.adoc includes shared_content/lang/foo.adoc,
which includes rules/S200/bar.adoc.
This is achieved with proper Asciidoc extensions written in Ruby.
See https://docs.asciidoctor.org/asciidoctor/latest/extensions/
* Regroup read-only variable declaration. `declare -xr` is used for
an exported read-only variable.
* Use more accurate log messages.
* Use consistent indentation of 2 spaces.
* Fail fast if dependencies cannot be installed.
* Regroup HTML generation & its validation.
* Document the main validation points.
* Simplify some commands and address some ShellCheck warnings.
* Regroup readonly variable declaration. `declare -xr` is used for exported readonly variable.
* Use more accurate log messages.
* Use consistent indentation of 2 spaces.
* Fail fast if dependencies cannot be installed.
* Regroup HTML generation & its validation.
* Document the main validation points.
* Simplify some commands and address some ShellCheck warnings.
The point of this branch is the second commit that changes
validate_asciidoc.sh. The first one is taken from another PR and should
not be reviewed.
The previous version of the validation could handle the following case:
```asciidoc
:path: path/to/file.adoc
include::{path}[]
```
This new validation also adds support for the case of a variable inside
a path:
```asciidoc
:language: csharp
include::rules/S1000/{language}/file.adoc[]
```
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.