From 2d91a307b81217f961b461600d3308aff8a55b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Tue, 14 Sep 2021 22:40:48 +0200 Subject: [PATCH] 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 --- .svglintrc.js | 12 +++++++++++- icons/autoprefixer.svg | 2 +- icons/cytoscapedotjs.svg | 2 +- icons/equinixmetal.svg | 2 +- icons/semaphoreci.svg | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.svglintrc.js b/.svglintrc.js index 6d5651447..e3cca01e3 100644 --- a/.svglintrc.js +++ b/.svglintrc.js @@ -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 '' closing tag + if (ast.source.includes('')) { + const reason = `found a closing "path" tag at index ${ast.source.indexOf('')}.` + + ' The path should be self-closing, use \'/>\' instead of \'>\'.'; + reporter.error(`Invalid SVG content format: ${reason}`); + } } ] } diff --git a/icons/autoprefixer.svg b/icons/autoprefixer.svg index d8fe367a5..b88cb1755 100644 --- a/icons/autoprefixer.svg +++ b/icons/autoprefixer.svg @@ -1 +1 @@ -Autoprefixer \ No newline at end of file +Autoprefixer \ No newline at end of file diff --git a/icons/cytoscapedotjs.svg b/icons/cytoscapedotjs.svg index b71c7701d..fa4b8c903 100644 --- a/icons/cytoscapedotjs.svg +++ b/icons/cytoscapedotjs.svg @@ -1 +1 @@ -Cytoscape.js +Cytoscape.js \ No newline at end of file diff --git a/icons/equinixmetal.svg b/icons/equinixmetal.svg index 0a1e5fa5f..0dc9b6bd2 100644 --- a/icons/equinixmetal.svg +++ b/icons/equinixmetal.svg @@ -1 +1 @@ -Equinix Metal \ No newline at end of file +Equinix Metal \ No newline at end of file diff --git a/icons/semaphoreci.svg b/icons/semaphoreci.svg index fe6ed9e40..a5daf1cbd 100644 --- a/icons/semaphoreci.svg +++ b/icons/semaphoreci.svg @@ -1 +1 @@ -Semaphore CI \ No newline at end of file +Semaphore CI \ No newline at end of file