Skip to content

Commit cf66ade

Browse files
committed
Use new twoslash API
1 parent 872991e commit cf66ade

File tree

1 file changed

+54
-51
lines changed

1 file changed

+54
-51
lines changed

packages/glossary/scripts/lint.js

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { readdirSync, readFileSync } = require("fs");
1212
const { join } = require("path");
1313

1414
const remark = require("remark");
15-
const remarkTwoSlash = require("gatsby-remark-shiki-twoslash");
15+
const remarkTwoSlash = require("remark-shiki-twoslash");
1616

1717
const { read } = require("gray-matter");
1818

@@ -25,62 +25,65 @@ const filterString = process.argv[2] ? process.argv[2] : "";
2525

2626
const errorReports = [];
2727

28-
languages.forEach((lang) => {
29-
console.log("\n\nLanguage: " + chalk.bold(lang) + "\n");
28+
const go = async () => {
29+
for (const lang of languages) {
30+
console.log("\n\nLanguage: " + chalk.bold(lang) + "\n");
3031

31-
const locale = join(__dirname, "..", "copy", lang);
32-
let options;
32+
const locale = join(__dirname, "..", "copy", lang);
33+
let options;
3334

34-
try {
35-
options = readdirSync(join(locale)).filter((f) => !f.startsWith("."));
36-
} catch {
37-
errorReports.push({
38-
path: join(locale, "options"),
39-
error: `Options directory ${join(locale, "options")} doesn't exist`,
40-
});
41-
return;
42-
}
35+
try {
36+
options = readdirSync(join(locale)).filter((f) => !f.startsWith("."));
37+
} catch {
38+
errorReports.push({
39+
path: join(locale, "options"),
40+
error: `Options directory ${join(locale, "options")} doesn't exist`,
41+
});
42+
return;
43+
}
4344

44-
options.forEach((option) => {
45-
if (filterString.length && !option.includes(filterString)) return;
45+
for (const option of options) {
46+
if (filterString.length && !option.includes(filterString)) return;
4647

47-
const optionPath = join(locale, option);
48+
const optionPath = join(locale, option);
4849

49-
const markdown = readFileSync(optionPath, "utf8");
50-
const markdownAST = remark().parse(markdown);
51-
let hasError = false;
50+
const markdown = readFileSync(optionPath, "utf8");
51+
const markdownAST = remark().parse(markdown);
52+
let hasError = false;
5253

53-
try {
54-
remarkTwoSlash.runTwoSlashAcrossDocument({ markdownAST }, {});
55-
} catch (error) {
56-
hasError = true;
57-
errorReports.push({ path: optionPath, error });
58-
}
54+
try {
55+
await remarkTwoSlash.default({})(markdownAST);
56+
} catch (error) {
57+
hasError = true;
58+
errorReports.push({ path: optionPath, error });
59+
}
5960

60-
const optionFile = read(optionPath);
61-
if (!optionFile.data.display) {
62-
hasError = true;
63-
// prettier-ignore
64-
errorReports.push({ path: optionPath, error: new Error("Did not have a 'display' property in the YML header") });
61+
const optionFile = read(optionPath);
62+
if (!optionFile.data.display) {
63+
hasError = true;
64+
// prettier-ignore
65+
errorReports.push({ path: optionPath, error: new Error("Did not have a 'display' property in the YML header") });
66+
}
67+
68+
const sigil = hasError ? cross : tick;
69+
const name = hasError ? chalk.red(option) : option;
70+
process.stdout.write(name + " " + sigil + ", ");
6571
}
72+
}
73+
74+
if (errorReports.length) {
75+
process.exitCode = 1;
6676

67-
const sigil = hasError ? cross : tick;
68-
const name = hasError ? chalk.red(option) : option;
69-
process.stdout.write(name + " " + sigil + ", ");
70-
});
71-
});
72-
73-
if (errorReports.length) {
74-
process.exitCode = 1;
75-
76-
errorReports.forEach((err) => {
77-
console.log(`\n> ${chalk.bold.red(err.path)}\n`);
78-
err.error.stack = undefined;
79-
console.log(err.error);
80-
});
81-
console.log("\n\n");
82-
83-
console.log(
84-
"Note: you can add an extra argument to the lint script ( yarn workspace glossary lint [opt] ) to just run one lint."
85-
);
86-
}
77+
errorReports.forEach((err) => {
78+
console.log(`\n> ${chalk.bold.red(err.path)}\n`);
79+
err.error.stack = undefined;
80+
console.log(err.error);
81+
});
82+
console.log("\n\n");
83+
84+
console.log(
85+
"Note: you can add an extra argument to the lint script ( yarn workspace glossary lint [opt] ) to just run one lint."
86+
);
87+
}
88+
};
89+
go();

0 commit comments

Comments
 (0)