You've already forked simple-icons
mirror of
https://github.com/simple-icons/simple-icons.git
synced 2025-11-23 21:34:49 +02:00
Add types to source code (#10637)
This commit is contained in:
committed by
GitHub
parent
1224e341d7
commit
236f5fc715
@@ -1,21 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @fileoverview
|
||||
* @file
|
||||
* Linters for the package that can't easily be implemented in the existing
|
||||
* linters (e.g. jsonlint/svglint).
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import("../../sdk.mjs").IconData} IconData
|
||||
* @typedef {import("../../types.js").CustomLicense} CustomLicense
|
||||
* @typedef {IconData[]} IconsData
|
||||
*/
|
||||
|
||||
import process from 'node:process';
|
||||
import fakeDiff from 'fake-diff';
|
||||
import {collator, getIconsDataString, normalizeNewlines} from '../../sdk.mjs';
|
||||
|
||||
/**
|
||||
* Contains our tests so they can be isolated from each other.
|
||||
* @type {{[k:string]: () => (string|undefined)}}
|
||||
* @type {{[k: string]: (arg0: {icons: IconsData}, arg1: string) => string | undefined}}
|
||||
*/
|
||||
const TESTS = {
|
||||
/* Tests whether our icons are in alphabetical order */
|
||||
/**
|
||||
* Tests whether our icons are in alphabetical order
|
||||
* @param {{icons: IconsData}} data Icons data
|
||||
* @returns {string|undefined} Error message or undefined
|
||||
*/
|
||||
alphabetical(data) {
|
||||
/**
|
||||
* Collects invalid alphabet ordered icons
|
||||
* @param {IconData[]} invalidEntries Invalid icons reference
|
||||
* @param {IconData} icon Icon to check
|
||||
* @param {number} index Index of the icon
|
||||
* @param {IconData[]} array Array of icons
|
||||
* @returns {IconData[]} Invalid icons
|
||||
*/
|
||||
const collector = (invalidEntries, icon, index, array) => {
|
||||
if (index > 0) {
|
||||
const previous = array[index - 1];
|
||||
@@ -34,6 +52,11 @@ const TESTS = {
|
||||
return invalidEntries;
|
||||
};
|
||||
|
||||
/**
|
||||
* Format an icon for display in the error message
|
||||
* @param {IconData} icon Icon to format
|
||||
* @returns {string} Formatted icon
|
||||
*/
|
||||
const format = (icon) => {
|
||||
if (icon.slug) {
|
||||
return `${icon.title} (${icon.slug})`;
|
||||
@@ -63,6 +86,11 @@ const TESTS = {
|
||||
|
||||
/* Check redundant trailing slash in URL */
|
||||
checkUrl(data) {
|
||||
/**
|
||||
* Check if an URL has a redundant trailing slash.
|
||||
* @param {string} url URL to check
|
||||
* @returns {boolean} Whether the URL has a redundant trailing slash
|
||||
*/
|
||||
const hasRedundantTrailingSlash = (url) => {
|
||||
const {origin} = new global.URL(url);
|
||||
return /^\/+$/.test(url.replace(origin, ''));
|
||||
@@ -71,7 +99,17 @@ const TESTS = {
|
||||
const allUrlFields = [
|
||||
...new Set(
|
||||
data.icons
|
||||
.flatMap((icon) => [icon.source, icon.guidelines, icon.license?.url])
|
||||
.flatMap((icon) => {
|
||||
// TODO: `Omit` is not working smoothly here
|
||||
const license =
|
||||
// @ts-ignore
|
||||
icon.license && icon.license.url
|
||||
? // @ts-ignore
|
||||
[icon.license.url]
|
||||
: [];
|
||||
return [icon.source, icon.guidelines, ...license];
|
||||
})
|
||||
|
||||
.filter(Boolean),
|
||||
),
|
||||
];
|
||||
@@ -88,11 +126,13 @@ const TESTS = {
|
||||
},
|
||||
};
|
||||
|
||||
const dataString = await getIconsDataString();
|
||||
const data = JSON.parse(dataString);
|
||||
const iconsDataString = await getIconsDataString();
|
||||
const iconsData = JSON.parse(iconsDataString);
|
||||
|
||||
const errors = (
|
||||
await Promise.all(Object.values(TESTS).map((test) => test(data, dataString)))
|
||||
await Promise.all(
|
||||
Object.values(TESTS).map((test) => test(iconsData, iconsDataString)),
|
||||
)
|
||||
)
|
||||
// eslint-disable-next-line unicorn/no-await-expression-member
|
||||
.filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user