MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / validateQuotes

Function validateQuotes

frontend/scripts/check-assets.ts:166–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

164}
165
166async function validateQuotes(): Promise<void> {
167 const problems = new Problems<string, never>("Quotes", {});
168
169 const shortQuotes = JSON.parse(
170 fs.readFileSync("./scripts/short-quotes.json", "utf8"),
171 ) as Record<QuoteData["language"], number[]>;
172
173 const quotesFiles = fs.readdirSync("./static/quotes/");
174 for (let quotefilename of quotesFiles) {
175 quotefilename = quotefilename.split(".")[0] as string;
176 let quoteData;
177
178 try {
179 quoteData = JSON.parse(
180 fs.readFileSync(`./static/quotes/${quotefilename}.json`, {
181 encoding: "utf8",
182 flag: "r",
183 }),
184 ) as QuoteData;
185 } catch (e) {
186 problems.add(
187 quotefilename,
188 `Unable to parse ${e instanceof Error ? e.message : e}`,
189 );
190 continue;
191 }
192
193 //check filename matching language
194 if (quoteData.language !== quotefilename) {
195 problems.add(
196 quotefilename,
197 `Name not matching language ${quoteData.language}`,
198 );
199 }
200
201 //check schema
202 problems.addValidation(quotefilename, QuoteDataSchema.safeParse(quoteData));
203
204 //check for duplicate ids
205 const duplicates = findDuplicates(quoteData.quotes.map((it) => it.id));
206 if (duplicates.length !== 0) {
207 problems.add(
208 quotefilename,
209 `contains ${duplicates.length} duplicates:\n ${duplicates.join(",")}`,
210 );
211 }
212
213 //check quote length
214 quoteData.quotes.forEach((quote) => {
215 if (quote.text.length !== quote.length) {
216 problems.add(
217 quotefilename,
218 `ID ${quote.id}: expected length ${quote.text.length}`,
219 );
220 }
221
222 if (!shortQuotes[quoteData.language]?.includes(quote.id)) {
223 if (quote.text.length < 60) {

Callers

nothing calls this directly

Calls 5

addMethod · 0.95
addValidationMethod · 0.95
toStringMethod · 0.95
hasErrorMethod · 0.95
findDuplicatesFunction · 0.85

Tested by

no test coverage detected