mirror of
				https://github.com/Mibew/simple-icons.git
				synced 2025-10-31 10:31:06 +03:00 
			
		
		
		
	Add lint rule to prohibit negative zeros within paths (#4350)
* Add lint to check negative zeros in paths * Bump minimum NodeJS version to test locally to v12.4.0 * Simplify regular expression * Add resolution tip to error message * Convert iterator to array directly * Improve comment * Remove GodotEngine from lint ignores file * Improve resolution tip message if previous character is a number
This commit is contained in:
		
							parent
							
								
									da86aafdcc
								
							
						
					
					
						commit
						fb2e2b6cd0
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -8,6 +8,7 @@ const { svgPathBbox } = require("svg-path-bbox"); | ||||
| 
 | ||||
| const titleRegexp = /(.+) icon$/; | ||||
| const svgRegexp = /^<svg( [^\s]*=".*"){3}><title>.*<\/title><path d=".*"\/><\/svg>\r?\n?$/; | ||||
| const negativeZerosRegexp = /-0(?=[^\.]|[\s\d\w]|$)/g; | ||||
| 
 | ||||
| const iconSize = 24; | ||||
| const iconFloatPrecision = 3; | ||||
| @ -308,6 +309,30 @@ module.exports = { | ||||
|               reporter.error("Unexpected character(s), most likely extraneous whitespace, detected in SVG markup"); | ||||
|             } | ||||
|           }, | ||||
|           function(reporter, $, ast) { | ||||
|             reporter.name = "negative-zeros"; | ||||
| 
 | ||||
|             const iconPath = $.find("path").attr("d"); | ||||
|             if (!updateIgnoreFile && isIgnored(reporter.name, iconPath)) { | ||||
|               return; | ||||
|             } | ||||
| 
 | ||||
|             // Find negative zeros inside path
 | ||||
|             const negativeZeroMatches = Array.from(iconPath.matchAll(negativeZerosRegexp)); | ||||
|             if (negativeZeroMatches.length) { | ||||
|               // Calculate the index for each match in the file
 | ||||
|               const pathDStart = '<path d="'; | ||||
|               const svgFileHtml = $.html(); | ||||
|               const pathDIndex = svgFileHtml.indexOf(pathDStart) + pathDStart.length; | ||||
| 
 | ||||
|               negativeZeroMatches.forEach((match) => { | ||||
|                 const negativeZeroFileIndex = match.index + pathDIndex; | ||||
|                 const previousChar = svgFileHtml[negativeZeroFileIndex - 1]; | ||||
|                 const replacement = "0123456789".includes(previousChar) ? " 0" : "0"; | ||||
|                 reporter.error(`Found "-0" at index ${negativeZeroFileIndex} (should be "${replacement}")`); | ||||
|               }) | ||||
|             } | ||||
|           }, | ||||
|           function(reporter, $, ast) { | ||||
|             reporter.name = "icon-centered"; | ||||
| 
 | ||||
|  | ||||
| @ -237,7 +237,7 @@ If you have an affiliation to the brand you contributing that allows you to spea | ||||
| 
 | ||||
| ## Testing Package Locally | ||||
| 
 | ||||
| * Make sure you have [NodeJS](https://nodejs.org/en/download/) installed. At least version 11.15.0 is required. | ||||
| * Make sure you have [NodeJS](https://nodejs.org/en/download/) installed. At least version 12.4.0 is required. | ||||
| * Install the dependencies using `$ npm install`. | ||||
| * Build and test the package using `$ npm test`. | ||||
| * Run the project linting process using `$ npm run lint`. | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user