diff --git a/.svglintrc.js b/.svglintrc.js index ce8d45e5..0a18a7ce 100644 --- a/.svglintrc.js +++ b/.svglintrc.js @@ -473,6 +473,40 @@ module.exports = { ignoreIcon(reporter.name, iconPath, $); } } + }, + function(reporter, $, ast) { + reporter.name = "path-format"; + + const iconPath = $.find("path").attr("d"); + + const validPathFormatRegex = /^[Mm][MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/; + if (!validPathFormatRegex.test(iconPath)) { + let errorMsg = "Invalid path format", reason; + + if (!(/^[Mm]/.test(iconPath))) { + // doesn't start with moveto + reason = `should start with \"moveto\" command (\"M\" or \"m\"), but starts with \"${iconPath[0]}\"`; + reporter.error(`${errorMsg}: ${reason}`); + } + + const validPathCharacters = "MmZzLlHhVvCcSsQqTtAaEe0123456789-,. ", + invalidCharactersMsgs = [], + pathDStart = ' 0) { + reason = `unexpected character${invalidCharactersMsgs.length > 1 ? 's' : ''} found`; + reason += ` (${invalidCharactersMsgs.join(", ")})`; + reporter.error(`${errorMsg}: ${reason}`); + } + } } ] } diff --git a/tests/icons.test.js b/tests/icons.test.js index 41b8267b..b7b7a2c9 100644 --- a/tests/icons.test.js +++ b/tests/icons.test.js @@ -24,7 +24,6 @@ icons.forEach(icon => { test(`${icon.title} has a "path"`, () => { expect(typeof subject.path).toBe('string'); - expect(subject.path).toMatch(/[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]/g); }); test(`${icon.title} has a "slug"`, () => {