Add lint rule to unify self-closing tags format (#6513)

* Add lint rule to unify closing tags format

* Apply suggestions from code review

* Simplify lint rule logic

* Clarify error message

* Fix 'extraneous' rule and remove part of 'svg-format'

Co-authored-by: Eric Cornelissen <ericornelissen@gmail.com>
This commit is contained in:
Álvaro Mondéjar 2021-09-14 22:40:48 +02:00 committed by GitHub
parent e64b98144f
commit 2d91a307b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 5 deletions

View file

@ -485,7 +485,7 @@ module.exports = {
function(reporter, $, ast) {
reporter.name = "extraneous";
if (!svgRegexp.test($.html())) {
if (!svgRegexp.test(ast.source)) {
reporter.error("Unexpected character(s), most likely extraneous whitespace, detected in SVG markup");
}
},
@ -569,6 +569,16 @@ module.exports = {
reporter.error(`${errorMsg}: ${reason}`);
}
}
},
function(reporter, $, ast) {
reporter.name = 'svg-format';
// Don't allow explicit '</path>' closing tag
if (ast.source.includes('</path>')) {
const reason = `found a closing "path" tag at index ${ast.source.indexOf('</path>')}.`
+ ' The path should be self-closing, use \'/>\' instead of \'></path>\'.';
reporter.error(`Invalid SVG content format: ${reason}`);
}
}
]
}

View file

@ -1 +1 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Autoprefixer</title><path d="M5.87 21.045h2.923l.959-3.068h4.503l.949 3.068h2.922L11.94 2.955l-6.07 18.09zm6.162-10.12 1.543 4.917h-3.153l1.553-4.916h.057zM24 17.617l-.378-1.182-6.266-.59.733 2.127 5.91-.354zM6.644 15.843l-6.266.591L0 17.616l5.911.355.733-2.128z" /></svg>
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Autoprefixer</title><path d="M5.87 21.045h2.923l.959-3.068h4.503l.949 3.068h2.922L11.94 2.955l-6.07 18.09zm6.162-10.12 1.543 4.917h-3.153l1.553-4.916h.057zM24 17.617l-.378-1.182-6.266-.59.733 2.127 5.91-.354zM6.644 15.843l-6.266.591L0 17.616l5.911.355.733-2.128z"/></svg>

Before

Width:  |  Height:  |  Size: 350 B

After

Width:  |  Height:  |  Size: 349 B

View file

@ -1 +1 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Cytoscape.js</title><path d="M24 0v24H0V0h24zm-4.8416 7.2596c-.939 0-1.7199.6988-1.8416 1.61l-2.7097.6834a1.8574 1.8574 0 00-1.5505-.834c-1.026 0-1.858.832-1.858 1.858 0 1.0259.832 1.8579 1.858 1.8579.2554 0 .5063-.052.7388-.1528l1.792 1.8298a2.0325 2.0325 0 00-.0493.0932l-2.3452-.316c-.1616-.868-.9238-1.5154-1.8264-1.5154-1.0259 0-1.858.832-1.858 1.858 0 1.0258.8321 1.858 1.858 1.858a1.859 1.859 0 001.6365-.9776l2.3456.316c.0214.1408.0573.2788.1074.412l-.984.8666a1.136 1.136 0 00-.3179-.0454c-.626 0-1.1337.5077-1.1337 1.1338 0 .6258.5078 1.1336 1.1337 1.1336.626 0 1.1336-.5078 1.1336-1.1336 0-.0496-.0031-.0988-.0096-.1476l.9446-.832c.34.2325.7417.3572 1.1578.3572.082 0 .1638-.0048.245-.0145l.8342 1.665a1.8536 1.8536 0 00-.5009 1.269c0 1.0258.8322 1.858 1.8581 1.858 1.026 0 1.858-.8322 1.858-1.858 0-1.026-.832-1.8581-1.858-1.8581-.0873 0-.1743.006-.2604.0182l-.8039-1.6046a2.0519 2.0519 0 00.6834-1.5305 2.0553 2.0553 0 00-.9357-1.724l.7343-2.4191c.9905-.04 1.7818-.856 1.7818-1.8565 0-1.0259-.8321-1.858-1.858-1.858zm-1.582 2.8326c.1244.2014.2862.3776.4762.5185l-.7442 2.4523a2.046 2.046 0 00-.8189.2015l-1.787-1.8249a1.8483 1.8483 0 00.2025-.6736z"></path></svg>
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Cytoscape.js</title><path d="M24 0v24H0V0h24zm-4.8416 7.2596c-.939 0-1.7199.6988-1.8416 1.61l-2.7097.6834a1.8574 1.8574 0 00-1.5505-.834c-1.026 0-1.858.832-1.858 1.858 0 1.0259.832 1.8579 1.858 1.8579.2554 0 .5063-.052.7388-.1528l1.792 1.8298a2.0325 2.0325 0 00-.0493.0932l-2.3452-.316c-.1616-.868-.9238-1.5154-1.8264-1.5154-1.0259 0-1.858.832-1.858 1.858 0 1.0258.8321 1.858 1.858 1.858a1.859 1.859 0 001.6365-.9776l2.3456.316c.0214.1408.0573.2788.1074.412l-.984.8666a1.136 1.136 0 00-.3179-.0454c-.626 0-1.1337.5077-1.1337 1.1338 0 .6258.5078 1.1336 1.1337 1.1336.626 0 1.1336-.5078 1.1336-1.1336 0-.0496-.0031-.0988-.0096-.1476l.9446-.832c.34.2325.7417.3572 1.1578.3572.082 0 .1638-.0048.245-.0145l.8342 1.665a1.8536 1.8536 0 00-.5009 1.269c0 1.0258.8322 1.858 1.8581 1.858 1.026 0 1.858-.8322 1.858-1.858 0-1.026-.832-1.8581-1.858-1.8581-.0873 0-.1743.006-.2604.0182l-.8039-1.6046a2.0519 2.0519 0 00.6834-1.5305 2.0553 2.0553 0 00-.9357-1.724l.7343-2.4191c.9905-.04 1.7818-.856 1.7818-1.8565 0-1.0259-.8321-1.858-1.858-1.858zm-1.582 2.8326c.1244.2014.2862.3776.4762.5185l-.7442 2.4523a2.046 2.046 0 00-.8189.2015l-1.787-1.8249a1.8483 1.8483 0 00.2025-.6736z"/></svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -1 +1 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Equinix Metal</title><path d="M22.399 7.789v7.005l-1.599.56V7.231L16 5.557v11.472l-1.601.557V4.996L12 4.16l-2.4.836v12.59l-1.599-.557V5.557L3.2 7.232v8.121l-1.599-.56V7.79L0 8.349v7.582l4.801 1.676v-9.24l1.6-.558v10.356L11.2 19.84V6.133l.8-.28.8.28v13.708l4.801-1.676V7.809l1.599.558v9.24L24 15.93V8.349z" /></svg>
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Equinix Metal</title><path d="M22.399 7.789v7.005l-1.599.56V7.231L16 5.557v11.472l-1.601.557V4.996L12 4.16l-2.4.836v12.59l-1.599-.557V5.557L3.2 7.232v8.121l-1.599-.56V7.79L0 8.349v7.582l4.801 1.676v-9.24l1.6-.558v10.356L11.2 19.84V6.133l.8-.28.8.28v13.708l4.801-1.676V7.809l1.599.558v9.24L24 15.93V8.349z"/></svg>

Before

Width:  |  Height:  |  Size: 392 B

After

Width:  |  Height:  |  Size: 391 B

View file

@ -1 +1 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Semaphore CI</title><path d="m21.50314 13.2549-4.15781-4.22828a3.03814 3.03814 0 0 0-4.3591 0L9.6943 12.374a1.20701 1.20701 0 0 1-1.7213 0l-1.63096-1.6587 4.1578-4.22866a6.53247 6.53247 0 0 1 9.34234 0L24 10.71531zM8.82879 19.47925a6.52947 6.52947 0 0 1-4.67098-1.9657L0 13.295l2.48674-2.52872 4.15744 4.21816a3.05613 3.05613 0 0 0 4.3591 0l3.29191-3.34814a1.20701 1.20701 0 0 1 1.7213 0l1.63097 1.6587-4.14732 4.22866a6.5186 6.5186 0 0 1-4.67135 1.95558z" /></svg>
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Semaphore CI</title><path d="m21.50314 13.2549-4.15781-4.22828a3.03814 3.03814 0 0 0-4.3591 0L9.6943 12.374a1.20701 1.20701 0 0 1-1.7213 0l-1.63096-1.6587 4.1578-4.22866a6.53247 6.53247 0 0 1 9.34234 0L24 10.71531zM8.82879 19.47925a6.52947 6.52947 0 0 1-4.67098-1.9657L0 13.295l2.48674-2.52872 4.15744 4.21816a3.05613 3.05613 0 0 0 4.3591 0l3.29191-3.34814a1.20701 1.20701 0 0 1 1.7213 0l1.63097 1.6587-4.14732 4.22866a6.5186 6.5186 0 0 1-4.67135 1.95558z"/></svg>

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 542 B