mirror of
				https://github.com/Mibew/simple-icons.git
				synced 2025-10-31 02:25:59 +03:00 
			
		
		
		
	Add lint for checking redundant slashes (#8692)
* Add lint for checking redundant slashes * Update function names * Better condition * Fix typo
This commit is contained in:
		
							parent
							
								
									11b65e7da7
								
							
						
					
					
						commit
						7330e01f85
					
				
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -5,6 +5,7 @@ | |||||||
|  * linters (e.g. jsonlint/svglint). |  * linters (e.g. jsonlint/svglint). | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | import { URL } from 'node:url'; | ||||||
| import fakeDiff from 'fake-diff'; | import fakeDiff from 'fake-diff'; | ||||||
| import { getIconsDataString, normalizeNewlines, collator } from '../../sdk.mjs'; | import { getIconsDataString, normalizeNewlines, collator } from '../../sdk.mjs'; | ||||||
| 
 | 
 | ||||||
| @ -55,6 +56,33 @@ const TESTS = { | |||||||
|       return `Data file is formatted incorrectly:\n\n${dataDiff}`; |       return `Data file is formatted incorrectly:\n\n${dataDiff}`; | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|  | 
 | ||||||
|  |   /* Check redundant trailing slash in URL */ | ||||||
|  |   checkUrl: (data) => { | ||||||
|  |     const hasRedundantTrailingSlash = (url) => { | ||||||
|  |       const origin = new URL(url).origin; | ||||||
|  |       return /^\/+$/.test(url.replace(origin, '')); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     const allUrlFields = [ | ||||||
|  |       ...new Set( | ||||||
|  |         data.icons | ||||||
|  |           .map((icon) => [icon.source, icon.guidelines, icon.license?.url]) | ||||||
|  |           .flat() | ||||||
|  |           .filter(Boolean), | ||||||
|  |       ), | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|  |     const invalidUrls = allUrlFields.filter((url) => | ||||||
|  |       hasRedundantTrailingSlash(url), | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     if (invalidUrls.length > 0) { | ||||||
|  |       return `Some URLs have a redundant trailing slash:\n\n${invalidUrls.join( | ||||||
|  |         '\n', | ||||||
|  |       )}`;
 | ||||||
|  |     } | ||||||
|  |   }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // execute all tests and log all errors
 | // execute all tests and log all errors
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user