1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2025-07-12 22:21:23 +02:00

Check JSDoc types with TypeScript (#12840)

This commit is contained in:
Álvaro Mondéjar Rubio
2025-03-04 03:12:53 +01:00
committed by GitHub
parent 561076b8b4
commit 18a5c39e21
23 changed files with 67 additions and 21 deletions

View File

@ -3,11 +3,12 @@
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
"checkJs": true,
"skipLibCheck": false,
"checkJs": false,
"skipLibCheck": true,
"strict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"noEmit": true
}
}

View File

@ -98,7 +98,7 @@
"get-filename": "node scripts/get-filename.js",
"jslint": "xo",
"jsonlint": "node scripts/lint/jsonlint.js",
"lint": "npm run ourlint && npm run prettierlint && npm run jslint && npm run jsonlint && npm run svglint && npm run wslint && npm run markdownlint",
"lint": "npm run ourlint && npm run prettierlint && npm run jslint && npm run jsonlint && npm run svglint && npm run wslint && npm run tslint && npm run markdownlint",
"markdownlint": "markdownlint-cli2 '**/*.md' '#node_modules'",
"ourlint": "node scripts/lint/ourlint.js",
"prepare": "husky",
@ -111,6 +111,7 @@
"pretest": "npm run prepublishOnly",
"test": "mocha tests --reporter tests/min-reporter.cjs --inline-diffs",
"posttest": "npm run postpublish",
"tslint": "tsc -p jsconfig.json",
"wslint": "editorconfig-checker",
"xo:fix": "xo --fix"
},

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Script to add data for a new icon to the simple-icons dataset.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Clean files built by the build process.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Simple Icons package build script.

View File

@ -1,3 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Format _data/simple-icons.json.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Script that takes a brand name as argument and outputs the corresponding

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* CLI tool to run jsonschema on the simple-icons.json data file.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Linters for the package that can't easily be implemented in the existing ones.
@ -239,14 +240,14 @@ ${invalids.map((icon) => `${format(icon)} ${findPositon(expectedOrder, icon)}`).
async checkLicense(icons) {
const spdxLicenseIds = new Set(await getSpdxLicenseIds());
const badLicenses = [];
for (const {title, slug, license} of icons) {
for (const icon of icons) {
if (
license &&
license.type !== 'custom' &&
!spdxLicenseIds.has(license.type)
icon.license &&
icon.license.type !== 'custom' &&
!spdxLicenseIds.has(icon.license.type)
) {
badLicenses.push(
`${title} (${getIconSlug({title, slug})}) has not a valid SPDX license.`,
`${icon.title} (${getIconSlug(icon)}) has not a valid SPDX license.`,
);
}
}
@ -258,7 +259,7 @@ ${invalids.map((icon) => `${format(icon)} ${findPositon(expectedOrder, icon)}`).
/* Ensure that fields are sorted in the same way for all icons */
fieldsSorted(icons) {
const formatted = formatIconData(icons, true);
const formatted = formatIconData(icons);
const previous = JSON.stringify(icons, null, '\t');
const sorted = JSON.stringify(formatted, null, '\t');
if (previous !== sorted) {

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Send release message to Discord #releases channel.
@ -11,6 +12,18 @@ const discordReleasesRoleId = process.env.DISCORD_RELEASES_ROLE_ID;
const discordReleasesWebhookUrl = process.env.DISCORD_RELEASES_WEBHOOK_URL;
const githubReleaseUrl = `https://github.com/simple-icons/simple-icons/releases/tag/${releaseVersion}`;
if (discordReleasesRoleId === undefined) {
console.error('DISCORD_RELEASES_ROLE_ID environment variable is not set.');
process.exit(1);
}
if (discordReleasesWebhookUrl === undefined) {
console.error(
'DISCORD_RELEASES_WEBHOOK_URL environment variable is not set.',
);
process.exit(1);
}
try {
await globalThis.fetch(discordReleasesWebhookUrl, {
method: 'post',

View File

@ -1,3 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Minify _data/simple-icons.json file.
@ -6,4 +8,4 @@ import {getIconsData} from '../../sdk.mjs';
import {writeIconsData} from '../utils.js';
const icons = await getIconsData();
await writeIconsData(icons, undefined, true);
await writeIconsData(icons, true);

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Rewrite some Markdown files.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Updates the CDN URLs in the README.md to match the major version in the

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Updates the SDK Typescript definitions located in the file sdk.d.ts

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Generates a MarkDown file that lists every brand name and their slug.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Replaces the SVG count milestone "Over <NUMBER> SVG icons..." located

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
// @ts-check
/**
* @file
* Script to remove an icon and its data.
@ -27,7 +28,6 @@ const icons = iconsData.map((icon, index) => {
const found = await autocomplete({
message: 'Select an icon to remove:',
name: 'icon',
async source(input) {
if (!input) return icons;
return search(input, icons, {

View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file Internal utilities.
*
@ -35,13 +36,13 @@ export const getJsonSchemaData = async (
/**
* Write icons data to _data/simple-icons.json.
* @param {IconData[]} iconsData Icons data array.
* @param {string} rootDirectory Path to the root directory of the project.
* @param {boolean} minify Whether to minify the JSON output.
* @param {boolean} [minify] Whether to minify the JSON output.
* @param {string} [rootDirectory] Path to the root directory of the project.
*/
export const writeIconsData = async (
iconsData,
minify = false,
rootDirectory = path.resolve(__dirname, '..'),
minify,
) => {
await fs.writeFile(
getIconsDataPath(rootDirectory),
@ -99,11 +100,13 @@ const sortIcon = (icon) => {
// This is not appears in icon data but it's in the alias object.
'loc',
];
const sortedIcon = Object.fromEntries(
Object.entries(icon).sort(
([key1], [key2]) => keyOrder.indexOf(key1) - keyOrder.indexOf(key2),
),
);
// @ts-ignore
return sortedIcon;
};
@ -120,6 +123,7 @@ const sortLicense = (license) => {
([key1], [key2]) => keyOrder.indexOf(key1) - keyOrder.indexOf(key2),
),
);
// @ts-ignore
return sortedLicense;
};
@ -150,13 +154,20 @@ export const formatIconData = (iconsData) => {
? sortAlphabetically({
aka: icon.aliases.aka?.sort(collator.compare),
dup: icon.aliases.dup
? icon.aliases.dup.sort(sortIconsCompare).map((d) =>
? icon.aliases.dup
.sort(
// @ts-ignore
sortIconsCompare,
)
.map((d) =>
sortIcon({
...d,
// @ts-ignore
loc: sortAlphabetically(d.loc),
}),
)
: undefined,
// @ts-ignore
loc: sortAlphabetically(icon.aliases.loc),
old: icon.aliases.old?.sort(collator.compare),
})

1
sdk.d.ts vendored
View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file
* Types for Simple Icons SDK.

View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file
* Simple Icons SDK.

View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file
* Linting rules for SVGLint to check SVG icons.

View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file SVGO configuration for Simple Icons.
*/

1
types.d.ts vendored
View File

@ -1,3 +1,4 @@
// @ts-check
/**
* @file Types for Simple Icons package.
*/