svg_conform 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/Gemfile +2 -3
- data/Gemfile.lock +103 -76
- data/README.adoc +7 -0
- data/config/profiles/{metanorma.yml → metanorma-sample.yml} +4 -4
- data/docs/api_reference.adoc +21 -21
- data/docs/cli_guide.adoc +41 -41
- data/docs/profiles.adoc +8 -2
- data/docs/reference_manifest.adoc +3 -3
- data/lib/svg_conform/cli.rb +4 -5
- data/lib/svg_conform/errors/validation_issue.rb +6 -1
- data/lib/svg_conform/external_checkers/svgcheck/parser.rb +1 -3
- data/lib/svg_conform/quality_metrics/configuration.rb +4 -2
- data/lib/svg_conform/references/reference_manifest.rb +1 -2
- data/lib/svg_conform/validation/error_tracker.rb +37 -8
- data/lib/svg_conform/validation/svg_1_1_document_conformance.rb +0 -1
- data/lib/svg_conform/version.rb +1 -1
- data/lib/svg_conform/yaml_io.rb +20 -0
- data/lib/svg_conform.rb +1 -0
- data/spec/fixtures/quality_metrics/aliases.yml +7 -0
- data/spec/svg_conform/errors/validation_issue_spec.rb +53 -0
- data/spec/svg_conform/gemspec_spec.rb +23 -7
- data/spec/svg_conform/profiles/metanorma_profile_spec.rb +55 -7
- data/spec/svg_conform/profiles_plantuml_spec.rb +1 -1
- data/spec/svg_conform/quality_metrics/configuration_spec.rb +82 -0
- data/spec/svg_conform/references/integration_spec.rb +1 -1
- data/spec/svg_conform/requirements/id_reference_state_spec.rb +5 -5
- data/spec/svg_conform/requirements/text_as_path_requirement_spec.rb +15 -11
- data/spec/svg_conform/validator_input_types_spec.rb +11 -11
- data/spec/svg_conform/yaml_io_spec.rb +41 -0
- data/spec/svg_conform_spec.rb +3 -3
- data/svg_conform.gemspec +7 -0
- metadata +36 -3
data/docs/cli_guide.adoc
CHANGED
|
@@ -60,7 +60,7 @@ The `check` command validates SVG files against a profile and optionally applies
|
|
|
60
60
|
|
|
61
61
|
[source,bash]
|
|
62
62
|
----
|
|
63
|
-
$ svg_conform check file.svg --profile=metanorma
|
|
63
|
+
$ svg_conform check file.svg --profile=metanorma-sample
|
|
64
64
|
----
|
|
65
65
|
|
|
66
66
|
Output example:
|
|
@@ -70,7 +70,7 @@ Output example:
|
|
|
70
70
|
SVG Validation Report
|
|
71
71
|
==================================================
|
|
72
72
|
File: file.svg
|
|
73
|
-
Profile: metanorma
|
|
73
|
+
Profile: metanorma-sample
|
|
74
74
|
Valid: ✗
|
|
75
75
|
Total Errors: 2
|
|
76
76
|
|
|
@@ -88,7 +88,7 @@ Validation Errors:
|
|
|
88
88
|
|
|
89
89
|
[source,bash]
|
|
90
90
|
----
|
|
91
|
-
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma
|
|
91
|
+
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma-sample
|
|
92
92
|
----
|
|
93
93
|
|
|
94
94
|
==== Directory validation
|
|
@@ -97,7 +97,7 @@ Recursively validate all SVG files in a directory:
|
|
|
97
97
|
|
|
98
98
|
[source,bash]
|
|
99
99
|
----
|
|
100
|
-
$ svg_conform check --directory=images/ --profile=metanorma
|
|
100
|
+
$ svg_conform check --directory=images/ --profile=metanorma-sample
|
|
101
101
|
----
|
|
102
102
|
|
|
103
103
|
Output shows a summary table and statistics.
|
|
@@ -157,13 +157,13 @@ Examples:
|
|
|
157
157
|
[source,bash]
|
|
158
158
|
----
|
|
159
159
|
# JSON output to stdout
|
|
160
|
-
$ svg_conform check file.svg -p metanorma --format=json
|
|
160
|
+
$ svg_conform check file.svg -p metanorma-sample --format=json
|
|
161
161
|
|
|
162
162
|
# JSON output to file
|
|
163
|
-
$ svg_conform check file.svg -p metanorma --format=json -o report.json
|
|
163
|
+
$ svg_conform check file.svg -p metanorma-sample --format=json -o report.json
|
|
164
164
|
|
|
165
165
|
# YAML output to file
|
|
166
|
-
$ svg_conform check file.svg -p metanorma --format=yaml -o report.yaml
|
|
166
|
+
$ svg_conform check file.svg -p metanorma-sample --format=yaml -o report.yaml
|
|
167
167
|
----
|
|
168
168
|
|
|
169
169
|
==== Remediation options
|
|
@@ -194,13 +194,13 @@ Examples:
|
|
|
194
194
|
[source,bash]
|
|
195
195
|
----
|
|
196
196
|
# Single file with custom output
|
|
197
|
-
$ svg_conform check file.svg -p metanorma --fix --fix-output=cleaned.svg
|
|
197
|
+
$ svg_conform check file.svg -p metanorma-sample --fix --fix-output=cleaned.svg
|
|
198
198
|
|
|
199
199
|
# Multiple files to output directory
|
|
200
|
-
$ svg_conform check *.svg -p metanorma --fix --output-dir=fixed/
|
|
200
|
+
$ svg_conform check *.svg -p metanorma-sample --fix --output-dir=fixed/
|
|
201
201
|
|
|
202
202
|
# Directory with in-place replacement (destructive!)
|
|
203
|
-
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
203
|
+
$ svg_conform check -d images/ -p metanorma-sample --fix --in-place --force
|
|
204
204
|
----
|
|
205
205
|
|
|
206
206
|
==== Batch processing options
|
|
@@ -229,14 +229,14 @@ Examples:
|
|
|
229
229
|
[source,bash]
|
|
230
230
|
----
|
|
231
231
|
# Quiet mode - summary only
|
|
232
|
-
$ svg_conform check -d images/ -p metanorma -q
|
|
232
|
+
$ svg_conform check -d images/ -p metanorma-sample -q
|
|
233
233
|
|
|
234
234
|
# Generate detailed JSON report
|
|
235
|
-
$ svg_conform check -d images/ -p metanorma \
|
|
235
|
+
$ svg_conform check -d images/ -p metanorma-sample \
|
|
236
236
|
--report-format=json --report-output=full-report.json
|
|
237
237
|
|
|
238
238
|
# Full workflow with manifest
|
|
239
|
-
$ svg_conform check -d images/ -p metanorma --fix --output-dir=fixed/ \
|
|
239
|
+
$ svg_conform check -d images/ -p metanorma-sample --fix --output-dir=fixed/ \
|
|
240
240
|
--manifest=file-mapping.json --report-format=json --report-output=report.json
|
|
241
241
|
----
|
|
242
242
|
|
|
@@ -248,7 +248,7 @@ Process one SVG file:
|
|
|
248
248
|
|
|
249
249
|
[source,bash]
|
|
250
250
|
----
|
|
251
|
-
$ svg_conform check file.svg -p metanorma
|
|
251
|
+
$ svg_conform check file.svg -p metanorma-sample
|
|
252
252
|
----
|
|
253
253
|
|
|
254
254
|
Features:
|
|
@@ -264,7 +264,7 @@ Process multiple specified files:
|
|
|
264
264
|
|
|
265
265
|
[source,bash]
|
|
266
266
|
----
|
|
267
|
-
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma
|
|
267
|
+
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma-sample
|
|
268
268
|
----
|
|
269
269
|
|
|
270
270
|
Features:
|
|
@@ -279,7 +279,7 @@ Recursively process all SVG files in a directory:
|
|
|
279
279
|
|
|
280
280
|
[source,bash]
|
|
281
281
|
----
|
|
282
|
-
$ svg_conform check --directory=images/ -p metanorma
|
|
282
|
+
$ svg_conform check --directory=images/ -p metanorma-sample
|
|
283
283
|
----
|
|
284
284
|
|
|
285
285
|
Features:
|
|
@@ -297,7 +297,7 @@ Validate all SVGs before deployment:
|
|
|
297
297
|
|
|
298
298
|
[source,bash]
|
|
299
299
|
----
|
|
300
|
-
$ svg_conform check -d assets/images/ -p metanorma --quiet
|
|
300
|
+
$ svg_conform check -d assets/images/ -p metanorma-sample --quiet
|
|
301
301
|
|
|
302
302
|
# Exit code 0 = all valid
|
|
303
303
|
# Exit code 1 = validation failures
|
|
@@ -308,7 +308,7 @@ Use in CI/CD:
|
|
|
308
308
|
[source,bash]
|
|
309
309
|
----
|
|
310
310
|
#!/bin/bash
|
|
311
|
-
if svg_conform check -d docs/images/ -p metanorma -q; then
|
|
311
|
+
if svg_conform check -d docs/images/ -p metanorma-sample -q; then
|
|
312
312
|
echo "All SVGs valid"
|
|
313
313
|
else
|
|
314
314
|
echo "SVG validation failed"
|
|
@@ -323,10 +323,10 @@ Fix issues with review:
|
|
|
323
323
|
[source,bash]
|
|
324
324
|
----
|
|
325
325
|
# 1. Validate and see issues
|
|
326
|
-
$ svg_conform check file.svg -p metanorma
|
|
326
|
+
$ svg_conform check file.svg -p metanorma-sample
|
|
327
327
|
|
|
328
328
|
# 2. Apply fixes to new file
|
|
329
|
-
$ svg_conform check file.svg -p metanorma --fix --fix-output=file-fixed.svg
|
|
329
|
+
$ svg_conform check file.svg -p metanorma-sample --fix --fix-output=file-fixed.svg
|
|
330
330
|
|
|
331
331
|
# 3. Review the fixed file
|
|
332
332
|
$ diff file.svg file-fixed.svg
|
|
@@ -345,15 +345,15 @@ Fix all non-conforming files in a directory:
|
|
|
345
345
|
$ cp -r images/ images-backup/
|
|
346
346
|
|
|
347
347
|
# 2. Generate pre-fix report
|
|
348
|
-
$ svg_conform check -d images/ -p metanorma \
|
|
348
|
+
$ svg_conform check -d images/ -p metanorma-sample \
|
|
349
349
|
--report-format=json --report-output=before.json
|
|
350
350
|
|
|
351
351
|
# 3. Apply fixes to new directory
|
|
352
|
-
$ svg_conform check -d images/ -p metanorma \
|
|
352
|
+
$ svg_conform check -d images/ -p metanorma-sample \
|
|
353
353
|
--fix --output-dir=images-fixed/ --manifest=manifest.json
|
|
354
354
|
|
|
355
355
|
# 4. Verify fixes
|
|
356
|
-
$ svg_conform check -d images-fixed/ -p metanorma -q
|
|
356
|
+
$ svg_conform check -d images-fixed/ -p metanorma-sample -q
|
|
357
357
|
|
|
358
358
|
# 5. If satisfied, replace originals
|
|
359
359
|
$ rm -rf images/
|
|
@@ -370,10 +370,10 @@ Fix files in place (destructive):
|
|
|
370
370
|
$ cp -r images/ images-backup/
|
|
371
371
|
|
|
372
372
|
# Fix all files in place
|
|
373
|
-
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
373
|
+
$ svg_conform check -d images/ -p metanorma-sample --fix --in-place --force
|
|
374
374
|
|
|
375
375
|
# Verify
|
|
376
|
-
$ svg_conform check -d images/ -p metanorma -q
|
|
376
|
+
$ svg_conform check -d images/ -p metanorma-sample -q
|
|
377
377
|
----
|
|
378
378
|
|
|
379
379
|
==== Workflow 5: Selective remediation
|
|
@@ -383,12 +383,12 @@ Fix only specific files:
|
|
|
383
383
|
[source,bash]
|
|
384
384
|
----
|
|
385
385
|
# Find invalid files
|
|
386
|
-
$ svg_conform check -d images/ -p metanorma -q > results.txt
|
|
386
|
+
$ svg_conform check -d images/ -p metanorma-sample -q > results.txt
|
|
387
387
|
|
|
388
388
|
# Manually identify problematic files
|
|
389
389
|
# Then fix them individually
|
|
390
|
-
$ svg_conform check images/problematic1.svg -p metanorma -f
|
|
391
|
-
$ svg_conform check images/problematic2.svg -p metanorma -f
|
|
390
|
+
$ svg_conform check images/problematic1.svg -p metanorma-sample -f
|
|
391
|
+
$ svg_conform check images/problematic2.svg -p metanorma-sample -f
|
|
392
392
|
----
|
|
393
393
|
|
|
394
394
|
=== Exit codes
|
|
@@ -403,7 +403,7 @@ Use exit codes in scripts:
|
|
|
403
403
|
|
|
404
404
|
[source,bash]
|
|
405
405
|
----
|
|
406
|
-
if svg_conform check file.svg -p metanorma; then
|
|
406
|
+
if svg_conform check file.svg -p metanorma-sample; then
|
|
407
407
|
echo "Valid!"
|
|
408
408
|
else
|
|
409
409
|
echo "Invalid - see errors above"
|
|
@@ -443,7 +443,7 @@ xref:diagnostics.adoc[Diagnostics]). No timestamp is emitted by the CLI.
|
|
|
443
443
|
{
|
|
444
444
|
"schema_version": 1,
|
|
445
445
|
"producer": { "name": "svg_conform", "version": "0.2.4" },
|
|
446
|
-
"profile": { "id": "metanorma", "citations": [] },
|
|
446
|
+
"profile": { "id": "metanorma-sample", "citations": [] },
|
|
447
447
|
"valid": false,
|
|
448
448
|
"summary": { "errors": 1, "warnings": 0, "infos": 1 },
|
|
449
449
|
"diagnostics": [ ... ],
|
|
@@ -465,7 +465,7 @@ For multiple files or directories:
|
|
|
465
465
|
BATCH VALIDATION SUMMARY
|
|
466
466
|
================================================================================
|
|
467
467
|
Directory: images/
|
|
468
|
-
Profile: metanorma
|
|
468
|
+
Profile: metanorma-sample
|
|
469
469
|
Files processed: 15
|
|
470
470
|
Valid before: 8
|
|
471
471
|
Remediated: 5
|
|
@@ -527,7 +527,7 @@ Example output:
|
|
|
527
527
|
Detailed SVG Validation Profiles
|
|
528
528
|
==================================================
|
|
529
529
|
|
|
530
|
-
Profile: metanorma
|
|
530
|
+
Profile: metanorma-sample
|
|
531
531
|
------------------------------
|
|
532
532
|
Description: Metanorma document requirements
|
|
533
533
|
Requirements: 12
|
|
@@ -587,7 +587,7 @@ $ svg_conform check --directory=/absolute/path/to/images/
|
|
|
587
587
|
[source,bash]
|
|
588
588
|
----
|
|
589
589
|
# Specify output directory
|
|
590
|
-
$ svg_conform check *.svg -p metanorma --fix --output-dir=fixed/
|
|
590
|
+
$ svg_conform check *.svg -p metanorma-sample --fix --output-dir=fixed/
|
|
591
591
|
----
|
|
592
592
|
|
|
593
593
|
==== "--in-place requires --force"
|
|
@@ -599,7 +599,7 @@ $ svg_conform check *.svg -p metanorma --fix --output-dir=fixed/
|
|
|
599
599
|
[source,bash]
|
|
600
600
|
----
|
|
601
601
|
# Add --force flag
|
|
602
|
-
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
602
|
+
$ svg_conform check -d images/ -p metanorma-sample --fix --in-place --force
|
|
603
603
|
----
|
|
604
604
|
|
|
605
605
|
==== "Profile not found"
|
|
@@ -614,7 +614,7 @@ $ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
|
614
614
|
$ svg_conform profiles
|
|
615
615
|
|
|
616
616
|
# Use correct profile name
|
|
617
|
-
$ svg_conform check file.svg -p metanorma
|
|
617
|
+
$ svg_conform check file.svg -p metanorma-sample
|
|
618
618
|
----
|
|
619
619
|
|
|
620
620
|
==== Exit code 1 with valid files
|
|
@@ -636,11 +636,11 @@ For directories with many files:
|
|
|
636
636
|
[source,bash]
|
|
637
637
|
----
|
|
638
638
|
# Use quiet mode
|
|
639
|
-
$ svg_conform check -d large-dir/ -p metanorma -q
|
|
639
|
+
$ svg_conform check -d large-dir/ -p metanorma-sample -q
|
|
640
640
|
|
|
641
641
|
# Process in batches
|
|
642
642
|
$ find images/ -name "*.svg" -print0 | \
|
|
643
|
-
xargs -0 -n 50 svg_conform check -p metanorma
|
|
643
|
+
xargs -0 -n 50 svg_conform check -p metanorma-sample
|
|
644
644
|
----
|
|
645
645
|
|
|
646
646
|
==== Large SVG files
|
|
@@ -718,7 +718,7 @@ changed_svgs=$(git diff --cached --name-only --diff-filter=ACM | grep '\.svg$')
|
|
|
718
718
|
|
|
719
719
|
if [ -n "$changed_svgs" ]; then
|
|
720
720
|
echo "Validating SVG files..."
|
|
721
|
-
echo "$changed_svgs" | xargs svg_conform check -p metanorma -q
|
|
721
|
+
echo "$changed_svgs" | xargs svg_conform check -p metanorma-sample -q
|
|
722
722
|
if [ $? -ne 0 ]; then
|
|
723
723
|
echo "SVG validation failed. Commit aborted."
|
|
724
724
|
exit 1
|
|
@@ -744,7 +744,7 @@ jobs:
|
|
|
744
744
|
with:
|
|
745
745
|
ruby-version: 3.0
|
|
746
746
|
- run: gem install svg_conform
|
|
747
|
-
- run: svg_conform check -d docs/images/ -p metanorma --quiet
|
|
747
|
+
- run: svg_conform check -d docs/images/ -p metanorma-sample --quiet
|
|
748
748
|
----
|
|
749
749
|
|
|
750
750
|
==== Makefile integration
|
|
@@ -756,10 +756,10 @@ jobs:
|
|
|
756
756
|
.PHONY: validate-svg fix-svg
|
|
757
757
|
|
|
758
758
|
validate-svg:
|
|
759
|
-
svg_conform check -d images/ -p metanorma --quiet
|
|
759
|
+
svg_conform check -d images/ -p metanorma-sample --quiet
|
|
760
760
|
|
|
761
761
|
fix-svg:
|
|
762
|
-
svg_conform check -d images/ -p metanorma \
|
|
762
|
+
svg_conform check -d images/ -p metanorma-sample \
|
|
763
763
|
--fix --output-dir=images-fixed/ \
|
|
764
764
|
--manifest=manifest.json
|
|
765
765
|
@echo "Review images-fixed/ before replacing images/"
|
data/docs/profiles.adoc
CHANGED
|
@@ -342,18 +342,24 @@ See link:remediation.adoc#namespace-attribute-remediation[NamespaceAttributeReme
|
|
|
342
342
|
* Maintains valid SVG markup
|
|
343
343
|
|
|
344
344
|
[[metanorma-profile]]
|
|
345
|
-
=== Metanorma profile (`:metanorma`)
|
|
345
|
+
=== Metanorma sample profile (`:"metanorma-sample"`)
|
|
346
346
|
|
|
347
347
|
**Purpose**: Ensures SVG documents comply with Metanorma requirements for technical documents with embedded resources.
|
|
348
348
|
|
|
349
349
|
**Target use case**: Technical diagrams, flowcharts, and illustrations for Metanorma-generated standards documents (ISO, IEC, IETF, etc.).
|
|
350
350
|
|
|
351
|
+
This bundled profile is a sample and testing reference. Profiles are consumer
|
|
352
|
+
policy: the operative Metanorma profile ships and loads by path from
|
|
353
|
+
metanorma-standoc (`lib/metanorma/standoc/svg_conform_profile/metanorma.yml`),
|
|
354
|
+
so the `metanorma` name is not registered here and resolving it fails loudly
|
|
355
|
+
with `ProfileError: Profile not found`.
|
|
356
|
+
|
|
351
357
|
**Key Characteristics**:
|
|
352
358
|
* **Flexible colors**: Any colors allowed (unlike RFC 7996 black/white restriction)
|
|
353
359
|
* **Flexible fonts**: Any font families allowed (unlike RFC 7996 generic-only restriction)
|
|
354
360
|
* **Flexible styles**: Any CSS styles allowed
|
|
355
361
|
* **Event handlers allowed**: Supports event attributes (`on*`) for interactivity
|
|
356
|
-
* **Clipping and masking**: `clip-path` and `mask` presentation attributes allowed
|
|
362
|
+
* **Clipping and masking**: `clip-path` and `mask` presentation attributes allowed, and `clip-path`, `clip-rule`, and `opacity` allowed on container elements (`g`, `a`, `defs`)
|
|
357
363
|
* **Self-contained resources**: All CSS and fonts must be embedded
|
|
358
364
|
* **Structural compliance**: Proper namespaces and viewBox required
|
|
359
365
|
* **No external dependencies**: External CSS and fonts strictly prohibited
|
|
@@ -42,7 +42,7 @@ The manifest provides complete context:
|
|
|
42
42
|
----
|
|
43
43
|
require 'svg_conform'
|
|
44
44
|
|
|
45
|
-
validator = SvgConform::Validator.new(profile: 'metanorma')
|
|
45
|
+
validator = SvgConform::Validator.new(profile: 'metanorma-sample')
|
|
46
46
|
result = validator.validate(svg_content)
|
|
47
47
|
|
|
48
48
|
# Access the reference manifest
|
|
@@ -296,7 +296,7 @@ puts result_hash[:reference_manifest]
|
|
|
296
296
|
[source,ruby]
|
|
297
297
|
----
|
|
298
298
|
# Validate SVG document
|
|
299
|
-
result = validator.validate(svg_content, profile: 'metanorma')
|
|
299
|
+
result = validator.validate(svg_content, profile: 'metanorma-sample')
|
|
300
300
|
|
|
301
301
|
# Get external references for consumer validation
|
|
302
302
|
external_refs = result.external_references
|
|
@@ -368,4 +368,4 @@ Easy to add new reference types without modifying existing code.
|
|
|
368
368
|
* link:requirements.adoc[Requirements Documentation]
|
|
369
369
|
* link:api_reference.adoc[API Reference]
|
|
370
370
|
* link:../README.adoc[Main README]
|
|
371
|
-
* link:../config/profiles/metanorma.yml[Metanorma Profile Configuration]
|
|
371
|
+
* link:../config/profiles/metanorma-sample.yml[Metanorma Profile Configuration]
|
data/lib/svg_conform/cli.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "thor"
|
|
4
4
|
require "json"
|
|
5
|
-
require "yaml"
|
|
6
5
|
require "paint"
|
|
7
6
|
require_relative "commands/check"
|
|
8
7
|
require_relative "commands/svgcheck"
|
|
@@ -50,10 +49,10 @@ module SvgConform
|
|
|
50
49
|
- yaml: LensCore diagnostics YAML (schema version 1)
|
|
51
50
|
|
|
52
51
|
EXAMPLES:
|
|
53
|
-
svg_conform check file.svg -p metanorma
|
|
54
|
-
svg_conform check *.svg -p metanorma -f --output-dir fixed/
|
|
55
|
-
svg_conform check -d images/ -p metanorma --report-format json --report-output report.json
|
|
56
|
-
svg_conform check -d images/ -p metanorma -f --in-place --force
|
|
52
|
+
svg_conform check file.svg -p metanorma-sample
|
|
53
|
+
svg_conform check *.svg -p metanorma-sample -f --output-dir fixed/
|
|
54
|
+
svg_conform check -d images/ -p metanorma-sample --report-format json --report-output report.json
|
|
55
|
+
svg_conform check -d images/ -p metanorma-sample -f --in-place --force
|
|
57
56
|
DESC
|
|
58
57
|
option :directory, aliases: "-d", type: :string,
|
|
59
58
|
desc: "Directory to scan recursively for SVG files"
|
|
@@ -205,7 +205,12 @@ requirement_id: nil, severity: nil, violation_type: nil)
|
|
|
205
205
|
:font_violation
|
|
206
206
|
when /forbidden|content/
|
|
207
207
|
:content_violation
|
|
208
|
-
|
|
208
|
+
# The bare substring /id/ misclassified any requirement whose id
|
|
209
|
+
# merely contains it ("namespace_val[id]ation", "link_val[id]ation")
|
|
210
|
+
# as :reference_violation — the type consumers drop for the separate
|
|
211
|
+
# reference pass, so their verdicts vanished from downstream logs
|
|
212
|
+
# (#133). Match the id token only as a whole word segment.
|
|
213
|
+
when /reference/, /(^|_)id($|_)/
|
|
209
214
|
:reference_violation
|
|
210
215
|
when /namespace/
|
|
211
216
|
:namespace_violation
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "yaml"
|
|
4
|
-
|
|
5
3
|
module SvgConform
|
|
6
4
|
module ExternalCheckers
|
|
7
5
|
module Svgcheck
|
|
@@ -26,7 +24,7 @@ module SvgConform
|
|
|
26
24
|
|
|
27
25
|
def load_mapping_config
|
|
28
26
|
@mapping_config = if File.exist?(@mapping_config_path)
|
|
29
|
-
|
|
27
|
+
SvgConform::YamlIO.load_file(@mapping_config_path)
|
|
30
28
|
else
|
|
31
29
|
# Fallback to empty config if file doesn't exist
|
|
32
30
|
{
|
|
@@ -39,8 +39,10 @@ module SvgConform
|
|
|
39
39
|
raise ArgumentError, "Configuration file not found: #{path}"
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
hash =
|
|
43
|
-
|
|
42
|
+
hash = SvgConform::YamlIO.safe_load_file(
|
|
43
|
+
path, permitted_classes: [Symbol], permitted_symbols: [],
|
|
44
|
+
aliases: true
|
|
45
|
+
)
|
|
44
46
|
new(hash)
|
|
45
47
|
end
|
|
46
48
|
|
|
@@ -18,13 +18,38 @@ module SvgConform
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Add an error to the context
|
|
21
|
+
#
|
|
22
|
+
# A declared severity of :warning is a quality advisory (see
|
|
23
|
+
# TextAsPathRequirement) and must surface as a warning, not an error:
|
|
24
|
+
# otherwise schema-valid documents are reported as corrupt by consumers
|
|
25
|
+
# that log result.errors (metanorma, metanorma-pdfa#106). Other
|
|
26
|
+
# severities keep their existing routing: :validity_error stays out of
|
|
27
|
+
# the main error bucket, and :info remains in errors because the style
|
|
28
|
+
# remediation flow consumes it there.
|
|
21
29
|
def add_error(node:, message:, rule: nil, requirement: nil,
|
|
22
30
|
requirement_id: nil, severity: nil, fix: nil, data: {})
|
|
23
31
|
# Support both old rule system and new requirements system
|
|
24
32
|
rule_or_requirement = requirement || rule
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
if severity == :warning
|
|
35
|
+
warning = ::SvgConform::Errors::ValidationIssue.new(
|
|
36
|
+
type: :warning,
|
|
37
|
+
rule: rule_or_requirement,
|
|
38
|
+
node: node,
|
|
39
|
+
message: message,
|
|
40
|
+
fix: fix,
|
|
41
|
+
data: data,
|
|
42
|
+
requirement_id: requirement_id,
|
|
43
|
+
severity: severity,
|
|
44
|
+
)
|
|
45
|
+
@warnings << warning
|
|
46
|
+
return warning
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
type, bucket = severity_bucket(severity)
|
|
50
|
+
|
|
51
|
+
issue = ::SvgConform::Errors::ValidationIssue.new(
|
|
52
|
+
type: type,
|
|
28
53
|
rule: rule_or_requirement,
|
|
29
54
|
node: node,
|
|
30
55
|
message: message,
|
|
@@ -34,14 +59,18 @@ module SvgConform
|
|
|
34
59
|
severity: severity,
|
|
35
60
|
)
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
bucket << issue
|
|
63
|
+
issue
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Map a declared severity to the issue type and tracker bucket
|
|
67
|
+
def severity_bucket(severity)
|
|
68
|
+
case severity
|
|
69
|
+
when :validity_error
|
|
70
|
+
[:error, @validity_errors]
|
|
40
71
|
else
|
|
41
|
-
@errors
|
|
72
|
+
[:error, @errors]
|
|
42
73
|
end
|
|
43
|
-
|
|
44
|
-
error
|
|
45
74
|
end
|
|
46
75
|
|
|
47
76
|
# Add a warning to the context
|
data/lib/svg_conform/version.rb
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "yeptris/psych"
|
|
4
|
+
|
|
5
|
+
module SvgConform
|
|
6
|
+
# YAML operations through Yeptris without installing its global drop-in.
|
|
7
|
+
module YamlIO
|
|
8
|
+
def self.load_file(...)
|
|
9
|
+
Yeptris::Psych.load_file(...)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.safe_load_file(...)
|
|
13
|
+
Yeptris::Psych.safe_load_file(...)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.dump(...)
|
|
17
|
+
Yeptris::Psych.dump(...)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/svg_conform.rb
CHANGED
|
@@ -64,6 +64,7 @@ module SvgConform
|
|
|
64
64
|
require_relative "svg_conform/diagnostics/lens_core_adapter"
|
|
65
65
|
|
|
66
66
|
# Autoload core classes
|
|
67
|
+
autoload :YamlIO, File.expand_path("svg_conform/yaml_io", __dir__)
|
|
67
68
|
autoload :Validator, File.expand_path("svg_conform/validator", __dir__)
|
|
68
69
|
autoload :Fixer, "svg_conform/fixer"
|
|
69
70
|
autoload :RemediationEngine, "svg_conform/remediation_engine"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
require "svg_conform/errors/validation_issue"
|
|
4
|
+
|
|
5
|
+
RSpec.describe SvgConform::Errors::ValidationIssue do
|
|
6
|
+
let(:node) { Struct.new(:name, :line, :column).new("g", 1, 1) }
|
|
7
|
+
|
|
8
|
+
def issue_for(requirement_id, message)
|
|
9
|
+
described_class.new(
|
|
10
|
+
type: :error,
|
|
11
|
+
rule: Struct.new(:id).new(requirement_id),
|
|
12
|
+
node: node,
|
|
13
|
+
message: message,
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# metanorma's svg_error drops :reference_violation entries (the separate
|
|
18
|
+
# reference pass covers them); a misclassification here silently deletes
|
|
19
|
+
# profile verdicts from downstream logs (#133).
|
|
20
|
+
it "classifies reference requirements by the whole id token" do
|
|
21
|
+
expect(issue_for("id_references", "broken id reference").violation_type)
|
|
22
|
+
.to eq(:reference_violation)
|
|
23
|
+
expect(issue_for("id_collection", "collected").violation_type)
|
|
24
|
+
.to eq(:reference_violation)
|
|
25
|
+
expect(issue_for("external_references", "external reference").violation_type)
|
|
26
|
+
.to eq(:reference_violation)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "does not misclassify ids that merely contain the substring id" do
|
|
30
|
+
expect(issue_for("namespace_validation", "namespace issue").violation_type)
|
|
31
|
+
.to eq(:namespace_violation)
|
|
32
|
+
expect(issue_for("link_validation", "bad link").violation_type)
|
|
33
|
+
.to eq(:unknown_violation)
|
|
34
|
+
expect(issue_for("allowed_elements", "Attribute 'opacity' is not allowed").violation_type)
|
|
35
|
+
.to eq(:unknown_violation)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "keeps the message-based classification anchored on reference wording" do
|
|
39
|
+
expect(issue_for("unknown_rule", "broken reference to #missing").violation_type)
|
|
40
|
+
.to eq(:reference_violation)
|
|
41
|
+
expect(issue_for("unknown_rule", "broken href target").violation_type)
|
|
42
|
+
.to eq(:reference_violation)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "classifies the other requirement families as before" do
|
|
46
|
+
expect(issue_for("forbidden_content", "Attribute 'fill' is not allowed").violation_type)
|
|
47
|
+
.to eq(:content_violation)
|
|
48
|
+
expect(issue_for("font_embedding", "font not embedded").violation_type)
|
|
49
|
+
.to eq(:font_violation)
|
|
50
|
+
expect(issue_for("viewbox_required", "missing viewBox").violation_type)
|
|
51
|
+
.to eq(:viewbox_violation)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -5,13 +5,29 @@ require "spec_helper"
|
|
|
5
5
|
RSpec.describe "svg_conform.gemspec" do # rubocop:disable RSpec/DescribeClass
|
|
6
6
|
let(:specification) { Gem::Specification.load("svg_conform.gemspec") }
|
|
7
7
|
|
|
8
|
-
it "
|
|
9
|
-
# lens_core is
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
it "declares the published lens_core gem as a runtime dependency" do
|
|
9
|
+
# lens_core 0.1.0 is on rubygems, so the 0.2.5-era optionality is
|
|
10
|
+
# obsolete: leaving it undeclared crashed the CLI on strict bundler
|
|
11
|
+
# deployments (rescue LoadError misses Bundler::GemNotFound,
|
|
12
|
+
# claricle/svg_conform#130). The guard in svg_conform.rb stays as a
|
|
13
|
+
# version-compatibility courtesy, not as the dependency mechanism.
|
|
14
|
+
dependency = specification.runtime_dependencies.find { |d| d.name == "lens_core" }
|
|
15
|
+
|
|
16
|
+
expect(dependency).not_to be_nil
|
|
17
|
+
expect(dependency.requirement).to eq(Gem::Requirement.new("~> 0.1"))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "declares yeptris as a runtime dependency" do
|
|
21
|
+
dependency = specification.runtime_dependencies.find { |d| d.name == "yeptris" }
|
|
22
|
+
|
|
23
|
+
expect(dependency).not_to be_nil
|
|
24
|
+
expect(dependency.requirement).to eq(Gem::Requirement.new("~> 0.6.36"))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "loads the Psych-compatible yeptris API" do
|
|
28
|
+
require "yeptris/psych"
|
|
29
|
+
|
|
30
|
+
expect(defined?(Yeptris::Psych)).to be_truthy
|
|
15
31
|
end
|
|
16
32
|
|
|
17
33
|
it "exposes the lens_core availability probe" do
|