Skip to content

Commit 18a5c39

Browse files
authored
Check JSDoc types with TypeScript (simple-icons#12840)
1 parent 561076b commit 18a5c39

23 files changed

+67
-21
lines changed

jsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"target": "es2022",
44
"module": "node16",
55
"moduleResolution": "node16",
6-
"checkJs": true,
7-
"skipLibCheck": false,
6+
"checkJs": false,
7+
"skipLibCheck": true,
88
"strict": true,
99
"noImplicitAny": true,
1010
"noImplicitThis": true,
11-
"forceConsistentCasingInFileNames": true
11+
"forceConsistentCasingInFileNames": true,
12+
"noEmit": true
1213
}
1314
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"get-filename": "node scripts/get-filename.js",
9999
"jslint": "xo",
100100
"jsonlint": "node scripts/lint/jsonlint.js",
101-
"lint": "npm run ourlint && npm run prettierlint && npm run jslint && npm run jsonlint && npm run svglint && npm run wslint && npm run markdownlint",
101+
"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",
102102
"markdownlint": "markdownlint-cli2 '**/*.md' '#node_modules'",
103103
"ourlint": "node scripts/lint/ourlint.js",
104104
"prepare": "husky",
@@ -111,6 +111,7 @@
111111
"pretest": "npm run prepublishOnly",
112112
"test": "mocha tests --reporter tests/min-reporter.cjs --inline-diffs",
113113
"posttest": "npm run postpublish",
114+
"tslint": "tsc -p jsconfig.json",
114115
"wslint": "editorconfig-checker",
115116
"xo:fix": "xo --fix"
116117
},

scripts/add-icon-data.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Script to add data for a new icon to the simple-icons dataset.

scripts/build/clean.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Clean files built by the build process.

scripts/build/package.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Simple Icons package build script.

scripts/format-icon-data.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
// @ts-check
13
/**
24
* @file
35
* Format _data/simple-icons.json.

scripts/get-filename.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Script that takes a brand name as argument and outputs the corresponding

scripts/lint/jsonlint.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* CLI tool to run jsonschema on the simple-icons.json data file.

scripts/lint/ourlint.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* 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)}`).
239240
async checkLicense(icons) {
240241
const spdxLicenseIds = new Set(await getSpdxLicenseIds());
241242
const badLicenses = [];
242-
for (const {title, slug, license} of icons) {
243+
for (const icon of icons) {
243244
if (
244-
license &&
245-
license.type !== 'custom' &&
246-
!spdxLicenseIds.has(license.type)
245+
icon.license &&
246+
icon.license.type !== 'custom' &&
247+
!spdxLicenseIds.has(icon.license.type)
247248
) {
248249
badLicenses.push(
249-
`${title} (${getIconSlug({title, slug})}) has not a valid SPDX license.`,
250+
`${icon.title} (${getIconSlug(icon)}) has not a valid SPDX license.`,
250251
);
251252
}
252253
}
@@ -258,7 +259,7 @@ ${invalids.map((icon) => `${format(icon)} ${findPositon(expectedOrder, icon)}`).
258259

259260
/* Ensure that fields are sorted in the same way for all icons */
260261
fieldsSorted(icons) {
261-
const formatted = formatIconData(icons, true);
262+
const formatted = formatIconData(icons);
262263
const previous = JSON.stringify(icons, null, '\t');
263264
const sorted = JSON.stringify(formatted, null, '\t');
264265
if (previous !== sorted) {

scripts/release/discord-release-message.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Send release message to Discord #releases channel.
@@ -11,6 +12,18 @@ const discordReleasesRoleId = process.env.DISCORD_RELEASES_ROLE_ID;
1112
const discordReleasesWebhookUrl = process.env.DISCORD_RELEASES_WEBHOOK_URL;
1213
const githubReleaseUrl = `https://github.com/simple-icons/simple-icons/releases/tag/${releaseVersion}`;
1314

15+
if (discordReleasesRoleId === undefined) {
16+
console.error('DISCORD_RELEASES_ROLE_ID environment variable is not set.');
17+
process.exit(1);
18+
}
19+
20+
if (discordReleasesWebhookUrl === undefined) {
21+
console.error(
22+
'DISCORD_RELEASES_WEBHOOK_URL environment variable is not set.',
23+
);
24+
process.exit(1);
25+
}
26+
1427
try {
1528
await globalThis.fetch(discordReleasesWebhookUrl, {
1629
method: 'post',

scripts/release/minify-icons-data.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
// @ts-check
13
/**
24
* @file
35
* Minify _data/simple-icons.json file.
@@ -6,4 +8,4 @@ import {getIconsData} from '../../sdk.mjs';
68
import {writeIconsData} from '../utils.js';
79

810
const icons = await getIconsData();
9-
await writeIconsData(icons, undefined, true);
11+
await writeIconsData(icons, true);

scripts/release/reformat-markdown.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Rewrite some Markdown files.

scripts/release/update-cdn-urls.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Updates the CDN URLs in the README.md to match the major version in the

scripts/release/update-sdk-ts-defs.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Updates the SDK Typescript definitions located in the file sdk.d.ts

scripts/release/update-slugs-table.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Generates a MarkDown file that lists every brand name and their slug.

scripts/release/update-svgs-count.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Replaces the SVG count milestone "Over <NUMBER> SVG icons..." located

scripts/remove-icon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
/**
34
* @file
45
* Script to remove an icon and its data.
@@ -27,7 +28,6 @@ const icons = iconsData.map((icon, index) => {
2728

2829
const found = await autocomplete({
2930
message: 'Select an icon to remove:',
30-
name: 'icon',
3131
async source(input) {
3232
if (!input) return icons;
3333
return search(input, icons, {

scripts/utils.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file Internal utilities.
34
*
@@ -35,13 +36,13 @@ export const getJsonSchemaData = async (
3536
/**
3637
* Write icons data to _data/simple-icons.json.
3738
* @param {IconData[]} iconsData Icons data array.
38-
* @param {string} rootDirectory Path to the root directory of the project.
39-
* @param {boolean} minify Whether to minify the JSON output.
39+
* @param {boolean} [minify] Whether to minify the JSON output.
40+
* @param {string} [rootDirectory] Path to the root directory of the project.
4041
*/
4142
export const writeIconsData = async (
4243
iconsData,
44+
minify = false,
4345
rootDirectory = path.resolve(__dirname, '..'),
44-
minify,
4546
) => {
4647
await fs.writeFile(
4748
getIconsDataPath(rootDirectory),
@@ -99,11 +100,13 @@ const sortIcon = (icon) => {
99100
// This is not appears in icon data but it's in the alias object.
100101
'loc',
101102
];
103+
102104
const sortedIcon = Object.fromEntries(
103105
Object.entries(icon).sort(
104106
([key1], [key2]) => keyOrder.indexOf(key1) - keyOrder.indexOf(key2),
105107
),
106108
);
109+
// @ts-ignore
107110
return sortedIcon;
108111
};
109112

@@ -120,6 +123,7 @@ const sortLicense = (license) => {
120123
([key1], [key2]) => keyOrder.indexOf(key1) - keyOrder.indexOf(key2),
121124
),
122125
);
126+
// @ts-ignore
123127
return sortedLicense;
124128
};
125129

@@ -150,13 +154,20 @@ export const formatIconData = (iconsData) => {
150154
? sortAlphabetically({
151155
aka: icon.aliases.aka?.sort(collator.compare),
152156
dup: icon.aliases.dup
153-
? icon.aliases.dup.sort(sortIconsCompare).map((d) =>
154-
sortIcon({
155-
...d,
156-
loc: sortAlphabetically(d.loc),
157-
}),
158-
)
157+
? icon.aliases.dup
158+
.sort(
159+
// @ts-ignore
160+
sortIconsCompare,
161+
)
162+
.map((d) =>
163+
sortIcon({
164+
...d,
165+
// @ts-ignore
166+
loc: sortAlphabetically(d.loc),
167+
}),
168+
)
159169
: undefined,
170+
// @ts-ignore
160171
loc: sortAlphabetically(icon.aliases.loc),
161172
old: icon.aliases.old?.sort(collator.compare),
162173
})

sdk.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file
34
* Types for Simple Icons SDK.

sdk.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file
34
* Simple Icons SDK.

svglint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file
34
* Linting rules for SVGLint to check SVG icons.

svgo.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file SVGO configuration for Simple Icons.
34
*/

types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
/**
23
* @file Types for Simple Icons package.
34
*/

0 commit comments

Comments
 (0)