@khanacademy/perseus-linter 7.0.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,46 @@
1
1
  import { addLibraryVersionToPerseusDebug as e } from "@khanacademy/perseus-utils";
2
2
  import { CoreWidgetRegistry as t, Errors as n, PerseusError as r, SORTER_MAX_CARDS as i, makeSafeUrl as a } from "@khanacademy/perseus-core";
3
- import * as o from "@khanacademy/kas";
4
- import { parse as s, traverseContent as c } from "@khanacademy/pure-markdown";
3
+ import { parse as o, traverseContent as s } from "@khanacademy/pure-markdown";
4
+ import * as c from "@khanacademy/kas";
5
5
  import { vector as l } from "@khanacademy/kmath";
6
6
  //#region \0rolldown/runtime.js
7
- var u = "@khanacademy/perseus-linter", d = "7.0.1";
7
+ var u = "@khanacademy/perseus-linter", d = "8.0.0";
8
8
  e(u, d);
9
9
  //#endregion
10
10
  //#region packages/perseus-linter/src/proptypes.ts
11
- var f = {
11
+ var ee = {
12
12
  contentType: "",
13
13
  highlightLint: !1,
14
14
  stack: []
15
- }, Selector = class {
15
+ }, f = {
16
+ ERROR: 1,
17
+ WARNING: 2,
18
+ GUIDELINE: 3
19
+ };
20
+ function linterWarning(e, t) {
21
+ return {
22
+ message: e,
23
+ severity: f.WARNING,
24
+ ...t
25
+ };
26
+ }
27
+ function linterError(e, t) {
28
+ return {
29
+ message: e,
30
+ severity: f.ERROR,
31
+ ...t
32
+ };
33
+ }
34
+ function linterGuideline(e, t) {
35
+ return {
36
+ message: e,
37
+ severity: f.GUIDELINE,
38
+ ...t
39
+ };
40
+ }
41
+ //#endregion
42
+ //#region packages/perseus-linter/src/selector.ts
43
+ var Selector = class {
16
44
  static parse(e) {
17
45
  return new p(e).parse();
18
46
  }
@@ -180,65 +208,65 @@ var ParseError = class extends Error {
180
208
  return this.left.toString() + " ~ " + this.right.toString();
181
209
  }
182
210
  }, m, h = class Rule {
183
- constructor(e, t, i, a, o, s) {
184
- if (!i && !a) throw new r("Lint rules must have a selector or pattern", n.InvalidInput, { metadata: { name: e } });
185
- this.name = e || "unnamed rule", this.severity = t, this.selector = i || Rule.DEFAULT_SELECTOR, this.pattern = a || null, typeof o == "function" ? (this.lint = o, this.message = null) : (this.lint = (...e) => this._defaultLintFunction(...e), this.message = o), this.applies = s || function() {
186
- return !0;
187
- };
211
+ constructor(e, t, i, a) {
212
+ if (!t && !i) throw new r("Lint rules must have a selector or pattern", n.InvalidInput, { metadata: { name: e } });
213
+ this.name = e || "unnamed rule", this.selector = t || Rule.DEFAULT_SELECTOR, this.pattern = i || null, this.lint = a;
188
214
  }
189
215
  static makeRule(e) {
190
- return new Rule(e.name, e.severity, e.selector ? Selector.parse(e.selector) : null, Rule.makePattern(e.pattern), e.lint || e.message, e.applies);
216
+ return new Rule(e.name, e.selector ? Selector.parse(e.selector) : null, Rule.makePattern(e.pattern), e.lint);
191
217
  }
192
218
  static makeWidgetRule(e) {
193
- return new Rule(e.name, e.severity, Selector.parse("widget"), null, (t, n, r, i, a) => {
219
+ return new Rule(e.name, Selector.parse("widget"), null, (t, n, r, i, a) => {
194
220
  if (t.currentNode().widgetType !== e.widgetType) return;
195
221
  let o = t.currentNode().id;
196
222
  if (!o) return;
197
223
  let s = a?.widgets?.[o];
198
- if (!s) return;
199
- let c = e.lint(s);
200
- if (c) return `${o}: ${c}`;
201
- }, void 0);
224
+ if (s) return [e.lint(s, a) ?? []].flat().map((e) => ({
225
+ ...e,
226
+ message: `${o}: ${e.message}`
227
+ }));
228
+ });
202
229
  }
203
230
  check(e, t, n, r) {
204
- let i = this.selector.match(t);
205
- if (!i) return null;
206
- let a;
207
- if (a = this.pattern ? n.match(this.pattern) : Rule.FakePatternMatch(n, n, 0), !a) return null;
208
- try {
209
- let e = this.lint(t, n, i, a, r);
210
- return e ? typeof e == "string" ? {
211
- rule: this.name,
212
- severity: this.severity,
213
- message: e,
231
+ let toLinterIssue = (e) => {
232
+ let { location: t = {
214
233
  start: 0,
215
234
  end: n.length
216
- } : {
235
+ } } = e;
236
+ return {
217
237
  rule: this.name,
218
- severity: this.severity,
238
+ severity: e.severity,
219
239
  message: e.message,
220
- start: e.start,
221
- end: e.end,
222
- metadata: e.metadata
223
- } : null;
240
+ metadata: e.metadata,
241
+ ...t
242
+ };
243
+ }, toLinterIssues = (e) => e == null ? [] : Array.isArray(e) ? e.map(toLinterIssue) : [toLinterIssue(e)], i = this.selector.match(t);
244
+ if (!i) return [];
245
+ let a;
246
+ if (a = this.pattern ? n.match(this.pattern) : Rule.FakePatternMatch(n, n, 0), !a) return [];
247
+ try {
248
+ return toLinterIssues(this.lint(t, n, i, a, r));
224
249
  } catch (e) {
225
- return {
250
+ return [{
226
251
  rule: "lint-rule-failure",
227
- severity: this.severity,
252
+ severity: Rule.Severity.ERROR,
228
253
  message: `Exception in rule ${this.name}: ${e.message}
229
254
  Stack trace:
230
255
  ${e.stack}`,
231
256
  start: 0,
232
257
  end: n.length
233
- };
258
+ }];
234
259
  }
235
260
  }
236
- _defaultLintFunction(e, t, n, r, i) {
237
- return {
238
- message: this.message || "",
239
- start: r.index,
240
- end: r.index + r[0].length
241
- };
261
+ static makeLintFunction({ message: e, severity: t }) {
262
+ return (n, r, i, a, o) => ({
263
+ message: e,
264
+ severity: t,
265
+ location: {
266
+ start: a.index,
267
+ end: a.index + a[0].length
268
+ }
269
+ });
242
270
  }
243
271
  static makePattern(e) {
244
272
  if (!e) return null;
@@ -254,28 +282,55 @@ ${e.stack}`,
254
282
  return r.index = n, r.input = e, r;
255
283
  }
256
284
  };
257
- m = h, m.Severity = {
258
- ERROR: 1,
259
- WARNING: 2,
260
- GUIDELINE: 3
261
- }, h.DEFAULT_SELECTOR = Selector.parse("text");
285
+ m = h, m.Severity = f, h.DEFAULT_SELECTOR = Selector.parse("text");
262
286
  //#endregion
263
287
  //#region packages/perseus-linter/src/rules/lint-utils.ts
264
- var ee = /\/\/([^/]+)/;
288
+ var g = /\/\/([^/]+)/;
265
289
  function getHostname(e) {
266
290
  if (!e) return "";
267
- let t = e.match(ee);
291
+ let t = e.match(g);
268
292
  return t ? t[1] : "";
269
293
  }
270
294
  //#endregion
271
295
  //#region packages/perseus-linter/src/rules/absolute-url.ts
272
- var g = h.makeRule({
296
+ var te = h.makeRule({
273
297
  name: "absolute-url",
274
- severity: h.Severity.GUIDELINE,
275
298
  selector: "link, image",
276
299
  lint: function(e, t, n, r) {
277
300
  let i = n[0].target, a = getHostname(i);
278
- if (a === "khanacademy.org" || a.endsWith(".khanacademy.org")) return "Don't use absolute URLs:\nWhen linking to KA content or images, omit the\nhttps://www.khanacademy.org URL prefix.\nUse a relative URL beginning with / instead.";
301
+ if (a === "khanacademy.org" || a.endsWith(".khanacademy.org")) return linterGuideline("Don't use absolute URLs:\nWhen linking to KA content or images, omit the\nhttps://www.khanacademy.org URL prefix.\nUse a relative URL beginning with / instead.");
302
+ }
303
+ });
304
+ //#endregion
305
+ //#region packages/perseus-linter/src/lint-content.ts
306
+ function lintPerseusItem(e) {
307
+ return {
308
+ question: lintPerseusRenderer(e.question, "exercise"),
309
+ hints: e.hints.map((e) => lintPerseusRenderer(e, "exercise"))
310
+ };
311
+ }
312
+ function lintPerseusArticle(e) {
313
+ return (Array.isArray(e) ? e : [e]).map((e) => lintPerseusRenderer(e, "article"));
314
+ }
315
+ function lintPerseusRenderer(e, t) {
316
+ return [...runLinter(o(e.content), {
317
+ content: e.content,
318
+ widgets: e.widgets,
319
+ stack: [],
320
+ contentType: t
321
+ }, !1)];
322
+ }
323
+ //#endregion
324
+ //#region packages/perseus-linter/src/rules/explanation.ts
325
+ var ne = h.makeWidgetRule({
326
+ name: "explanation",
327
+ widgetType: "explanation",
328
+ lint(e, t) {
329
+ return lintPerseusRenderer({
330
+ content: e.options.explanation,
331
+ widgets: e.options.widgets,
332
+ images: {}
333
+ }, t);
279
334
  }
280
335
  });
281
336
  //#endregion
@@ -283,20 +338,18 @@ var g = h.makeRule({
283
338
  function hasExplanation(e) {
284
339
  return Object.values(e).some((e) => e.type === "explanation");
285
340
  }
286
- var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.", te = h.makeWidgetRule({
341
+ var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hint instead.", re = h.makeWidgetRule({
287
342
  name: "explanation-in-graded-group",
288
- severity: h.Severity.WARNING,
289
343
  widgetType: "graded-group",
290
344
  lint: function(e) {
291
- if (hasExplanation(e.options.widgets)) return `Contains explanation widget. ${_}`;
345
+ if (hasExplanation(e.options.widgets)) return linterWarning(`Contains explanation widget. ${_}`);
292
346
  }
293
- }), ne = h.makeWidgetRule({
347
+ }), v = h.makeWidgetRule({
294
348
  name: "explanation-in-graded-group-set",
295
- severity: h.Severity.WARNING,
296
349
  widgetType: "graded-group-set",
297
350
  lint: function(e) {
298
351
  let t = e.options.gradedGroups.map((e, t) => hasExplanation(e.widgets) ? t + 1 : 0).filter((e) => e > 0);
299
- if (t.length > 0) return `Explanation widget in group ${t.join(" and ")}. ${_}`;
352
+ if (t.length > 0) return linterWarning(`Explanation widget in group ${t.join(" and ")}. ${_}`);
300
353
  }
301
354
  });
302
355
  //#endregion
@@ -304,7 +357,7 @@ var _ = "Don't use explanation widgets in graded groups. Use the Graded Group Hi
304
357
  function buttonNotInButtonSet(e, t) {
305
358
  return `Answer requires a button not found in the button sets: ${e} (in ${t})`;
306
359
  }
307
- var re = {
360
+ var y = {
308
361
  "\\sqrt": "prealgebra",
309
362
  "^": "prealgebra",
310
363
  "\\sin": "trig",
@@ -312,27 +365,24 @@ var re = {
312
365
  "\\tan": "trig",
313
366
  "\\log": "logarithms",
314
367
  "\\ln": "logarithms"
315
- }, ie = h.makeWidgetRule({
368
+ }, b = h.makeWidgetRule({
316
369
  name: "expression-widget-buttons",
317
370
  widgetType: "expression",
318
- severity: h.Severity.WARNING,
319
371
  lint(e) {
320
372
  let t = e.options.answerForms, n = e.options.buttonSets;
321
- for (let e of t) for (let [t, r] of Object.entries(re)) if (e.value.includes(t) && !n.includes(r)) return buttonNotInButtonSet(t, r);
373
+ for (let e of t) for (let [t, r] of Object.entries(y)) if (e.value.includes(t) && !n.includes(r)) return linterWarning(buttonNotInButtonSet(t, r));
322
374
  }
323
- }), v = h.makeWidgetRule({
375
+ }), x = h.makeWidgetRule({
324
376
  name: "expression-widget-correct-answer",
325
377
  widgetType: "expression",
326
- severity: h.Severity.ERROR,
327
378
  lint(e) {
328
379
  let { answerForms: t } = e.options;
329
- if (t.length === 0) return "No answers specified.";
330
- if (!t.some((e) => e.considered === "correct")) return "No correct answer specified.";
380
+ if (t.length === 0) return linterError("No answers specified.");
381
+ if (!t.some((e) => e.considered === "correct")) return linterError("No correct answer specified.");
331
382
  }
332
- }), y = h.makeWidgetRule({
383
+ }), S = h.makeWidgetRule({
333
384
  name: "expression-widget-answer-forms",
334
385
  widgetType: "expression",
335
- severity: h.Severity.ERROR,
336
386
  lint(e) {
337
387
  let { answerForms: t, functions: n } = e.options, r = [];
338
388
  return t.forEach((e, t) => {
@@ -340,48 +390,91 @@ var re = {
340
390
  r.push(`Answer ${t + 1} is empty.`);
341
391
  return;
342
392
  }
343
- let i = o.parse(e.value, { functions: n });
393
+ let i = c.parse(e.value, { functions: n });
344
394
  i.parsed ? e.simplify && !i.expr.isSimplified() && r.push(`${e.value} isn't simplified, but is required to be.`) : r.push(`Couldn't parse ${e.value}.`);
345
- }), r.join("\n\n");
346
- }
347
- }), b = /\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/, x = h.makeRule({
395
+ }), r.map((e) => linterError(e));
396
+ }
397
+ }), C = h.makeWidgetRule({
398
+ name: "fill-in-the-blank",
399
+ widgetType: "fill-in-the-blank",
400
+ lint(e, t) {
401
+ return lintPerseusRenderer({
402
+ content: e.options.content,
403
+ widgets: e.options.widgets,
404
+ images: {}
405
+ }, t);
406
+ }
407
+ }), w = /\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/, T = h.makeWidgetRule({
348
408
  name: "free-response-widget-error",
349
- severity: h.Severity.ERROR,
350
- selector: "widget",
351
- lint: function(e, t, n, r, i) {
352
- if (e.currentNode().widgetType !== "free-response") return;
353
- let a = e.currentNode().id;
354
- if (!a) return;
355
- let o = i && i.widgets && i.widgets[a];
356
- if (!o) return;
357
- let s = o.options.question;
358
- if (!s) return "The question is empty";
359
- if (s.match(b) != null) return "The question contains a widget";
409
+ widgetType: "free-response",
410
+ lint(e) {
411
+ let t = e.options.question;
412
+ if (!t) return linterError("The question is empty");
413
+ if (t.match(w) != null) return linterError("The question contains a widget");
360
414
  }
361
- }), S = h.makeRule({
415
+ });
416
+ //#endregion
417
+ //#region packages/perseus-linter/src/rules/lint-graded-group.ts
418
+ function lintGradedGroup(e, { contentType: t }) {
419
+ let { hint: n } = e, r = [...lintPerseusRenderer(e, t)];
420
+ if (n) {
421
+ let e = lintPerseusRenderer(n, t).map((e) => ({
422
+ ...e,
423
+ message: `(in hint) ${e.message}`
424
+ }));
425
+ r.push(...e);
426
+ }
427
+ return r;
428
+ }
429
+ //#endregion
430
+ //#region packages/perseus-linter/src/rules/graded-group.ts
431
+ var E = h.makeWidgetRule({
432
+ name: "graded-group",
433
+ widgetType: "graded-group",
434
+ lint: (e, t) => lintGradedGroup(e.options, t)
435
+ }), D = h.makeWidgetRule({
436
+ name: "graded-group-set",
437
+ widgetType: "graded-group-set",
438
+ lint: (e, t) => e.options.gradedGroups.flatMap((e, n) => lintGradedGroup(e, t).map(prefixGroupNumber(n + 1)))
439
+ });
440
+ function prefixGroupNumber(e) {
441
+ return (t) => ({
442
+ ...t,
443
+ message: `group ${e}: ${t.message}`
444
+ });
445
+ }
446
+ //#endregion
447
+ //#region packages/perseus-linter/src/rules/group.ts
448
+ var O = h.makeWidgetRule({
449
+ name: "group",
450
+ widgetType: "group",
451
+ lint(e, t) {
452
+ return lintPerseusRenderer(e.options, t);
453
+ }
454
+ }), k = h.makeRule({
362
455
  name: "heading-level-1",
363
- severity: h.Severity.WARNING,
364
456
  selector: "heading",
365
457
  lint: function(e, t, n, r) {
366
- if (n[0].level === 1) return "Don't use level-1 headings:\nBegin headings with two or more # characters.";
458
+ if (n[0].level === 1) return linterWarning("Don't use level-1 headings:\nBegin headings with two or more # characters.");
367
459
  }
368
- }), C = h.makeRule({
460
+ }), A = h.makeRule({
369
461
  name: "heading-level-skip",
370
- severity: h.Severity.WARNING,
371
462
  selector: "heading ~ heading",
372
463
  lint: function(e, t, n, r) {
373
464
  let i = n[1], a = n[0];
374
- if (i.level > a.level + 1) return `Skipped heading level:
465
+ if (i.level > a.level + 1) return linterWarning(`Skipped heading level:
375
466
  this heading is level ${i.level} but
376
- the previous heading was level ${a.level}`;
467
+ the previous heading was level ${a.level}`);
377
468
  }
378
- }), w = h.makeRule({
469
+ }), j = h.makeRule({
379
470
  name: "heading-sentence-case",
380
- severity: h.Severity.GUIDELINE,
381
471
  selector: "heading",
382
472
  pattern: /^\W*[a-z]/,
383
- message: "First letter is lowercase:\nthe first letter of a heading should be capitalized."
384
- }), T = {
473
+ lint: h.makeLintFunction({
474
+ severity: h.Severity.GUIDELINE,
475
+ message: "First letter is lowercase:\nthe first letter of a heading should be capitalized."
476
+ })
477
+ }), M = {
385
478
  and: !0,
386
479
  nor: !0,
387
480
  but: !0,
@@ -392,128 +485,107 @@ function isCapitalized(e) {
392
485
  let t = e[0];
393
486
  return t === t.toUpperCase();
394
487
  }
395
- var E = h.makeRule({
488
+ var N = h.makeRule({
396
489
  name: "heading-title-case",
397
- severity: h.Severity.GUIDELINE,
398
490
  selector: "heading",
399
491
  pattern: /[^\s:]\s+[A-Z]+[a-z]/,
400
492
  locale: "en",
401
493
  lint: function(e, t, n, r) {
402
494
  let i = t.trim().split(/\s+/);
403
- if (i.shift(), i = i.filter((e) => e.length > 2 && !T.hasOwnProperty(e)), i.length >= 3 && i.every((e) => isCapitalized(e))) return "Title-case heading:\nThis heading appears to be in title-case, but should be sentence-case.\nOnly capitalize the first letter and proper nouns.";
495
+ if (i.shift(), i = i.filter((e) => e.length > 2 && !M.hasOwnProperty(e)), i.length >= 3 && i.every((e) => isCapitalized(e))) return linterGuideline("Title-case heading:\nThis heading appears to be in title-case, but should be sentence-case.\nOnly capitalize the first letter and proper nouns.");
404
496
  }
405
- }), D = h.makeRule({
497
+ }), P = h.makeRule({
406
498
  name: "image-alt-text",
407
- severity: h.Severity.WARNING,
408
499
  selector: "image",
409
500
  lint: function(e, t, n, r) {
410
501
  let i = n[0];
411
- if (!i.alt || !i.alt.trim()) return "Images should have alt text:\nfor accessibility, all images should have alt text.\nSpecify alt text inside square brackets after the !.";
412
- if (i.alt.length < 8) return `Images should have alt text:
502
+ if (!i.alt || !i.alt.trim()) return linterWarning("Images should have alt text:\nfor accessibility, all images should have alt text.\nSpecify alt text inside square brackets after the !.");
503
+ if (i.alt.length < 8) return linterWarning(`Images should have alt text:
413
504
  for accessibility, all images should have descriptive alt text.
414
- This image's alt text is only ${i.alt.length} characters long.`;
505
+ This image's alt text is only ${i.alt.length} characters long.`);
415
506
  }
416
- }), O = h.makeRule({
507
+ }), F = h.makeRule({
417
508
  name: "image-markdown",
418
- severity: h.Severity.WARNING,
419
509
  selector: "image",
420
510
  lint: function(e, t, n, r, i) {
421
- if (i?.stack && i.stack.includes("widget")) return null;
422
- let a = s(i?.content || "", {}), o = !1;
423
- return c(a, (e) => {
424
- e.type === "image" && (o = !0);
425
- }), o ? "[Inline markdown image]:\nMarkdown images are not recommended - these are images that use the\n![alt](url) format. Please use the Image widget instead." : null;
511
+ if (i?.stack && i.stack.includes("widget")) return;
512
+ let a = o(i?.content || "", {}), c = !1;
513
+ if (s(a, (e) => {
514
+ e.type === "image" && (c = !0);
515
+ }), c) return linterWarning("[Inline markdown image]:\nMarkdown images are not recommended - these are images that use the\n![alt](url) format. Please use the Image widget instead.");
426
516
  }
427
- }), k = h.makeRule({
517
+ }), I = h.makeRule({
428
518
  name: "image-spaces-around-urls",
429
- severity: h.Severity.ERROR,
430
519
  selector: "image",
431
520
  lint: function(e, t, n, r, i) {
432
521
  let a = n[0].target;
433
522
  if (i && i.content) {
434
523
  let e = i.content.indexOf(a);
435
524
  if (e === -1) return;
436
- if (i.content[e - 1] !== "(" || i.content[e + a.length] !== ")") return "Whitespace before or after image url:\nFor images, don't include any space or newlines after '(' or before ')'.\nWhitespace in image URLs causes translation difficulties.";
525
+ if (i.content[e - 1] !== "(" || i.content[e + a.length] !== ")") return linterError("Whitespace before or after image url:\nFor images, don't include any space or newlines after '(' or before ')'.\nWhitespace in image URLs causes translation difficulties.");
437
526
  }
438
527
  }
439
- }), A = h.makeRule({
528
+ }), L = h.makeRule({
440
529
  name: "image-url-empty",
441
- severity: h.Severity.ERROR,
442
530
  selector: "image",
443
531
  lint: function(e, t, n) {
444
532
  let r = n[0].target;
445
- if (!r || !r.trim()) return "Images should have a URL";
533
+ if (!r || !r.trim()) return linterError("Images should have a URL");
446
534
  }
447
- }), j = h.makeRule({
535
+ }), R = h.makeWidgetRule({
448
536
  name: "image-widget-alt-text",
449
- severity: h.Severity.WARNING,
450
- selector: "widget",
451
- lint: function(e, t, n, r, i) {
452
- if (e.currentNode().widgetType !== "image") return;
453
- let a = e.currentNode().id;
454
- if (!a) return;
455
- let o = i && i.widgets && i.widgets[a];
456
- if (!o || o.options.decorative) return;
457
- let s = o.options.alt;
458
- if (!s) return "Images should have alt text:\nfor accessibility, all images should have a text description.\nAdd a description in the \"Alt Text\" box of the image widget.";
459
- if (s.trim().length < 8) return `Images should have alt text:
537
+ widgetType: "image",
538
+ lint(e) {
539
+ if (e.options.decorative) return;
540
+ let t = e.options.alt;
541
+ if (!t) return linterWarning("Images should have alt text:\nfor accessibility, all images should have a text description.\nAdd a description in the \"Alt Text\" box of the image widget.");
542
+ if (t.trim().length < 8) return linterWarning(`Images should have alt text:
460
543
  for accessibility, all images should have descriptive alt text.
461
- This image's alt text is only ${s.trim().length} characters long.`;
462
- if (s.trim().length > 125) return `Images should have alt text:
544
+ This image's alt text is only ${t.trim().length} characters long.`);
545
+ if (t.trim().length > 125) return linterWarning(`Images should have alt text:
463
546
  for accessibility, image alt text should not exceed 125 characters.
464
- This image's alt text is ${s.trim().length} characters long.
547
+ This image's alt text is ${t.trim().length} characters long.
465
548
  Please pair your alt with a long description below if you need significantly
466
- more text to sufficiently describe the image.`;
549
+ more text to sufficiently describe the image.`);
467
550
  }
468
- }), M = h.makeRule({
551
+ }), z = h.makeWidgetRule({
469
552
  name: "image-widget-empty-size",
470
- severity: h.Severity.WARNING,
471
- selector: "widget",
472
- lint: function(e, t, n, r, i) {
473
- if (e.currentNode().widgetType !== "image") return;
474
- let a = e.currentNode().id;
475
- if (!a) return;
476
- let o = i && i.widgets && i.widgets[a];
477
- if (!o || !o.options.backgroundImage.url) return;
478
- let { width: s, height: c } = o.options.backgroundImage;
479
- if (!s || !c) return `Images should have a non-zero size.
480
- This image has a width of ${s} and a height of ${c}.
481
- Please use the "Reset to original size" button to set the size of the image.`;
482
- }
483
- }), N = h.makeRule({
553
+ widgetType: "image",
554
+ lint(e) {
555
+ if (!e.options.backgroundImage.url) return;
556
+ let { width: t, height: n } = e.options.backgroundImage;
557
+ if (!t || !n) return linterWarning(`Images should have a non-zero size.
558
+ This image has a width of ${t} and a height of ${n}.
559
+ Please use the "Reset to original size" button to set the size of the image.`);
560
+ }
561
+ }), B = h.makeRule({
484
562
  name: "inaccessible-widget",
485
- severity: h.Severity.WARNING,
486
563
  selector: "widget",
487
564
  lint: function(e, n, r, i, a) {
488
565
  let o = e.currentNode(), s = o.widgetType, c = o.id;
489
566
  if (!s || !c) return;
490
567
  let l = a?.widgets?.[c];
491
- if (l && !t.isAccessible(s, l.options)) return {
492
- message: `The "${s}" widget is not accessible.`,
493
- start: 0,
494
- end: n.length,
568
+ if (l && !t.isAccessible(s, l.options)) return linterWarning(`The "${s}" widget is not accessible.`, {
569
+ location: {
570
+ start: 0,
571
+ end: n.length
572
+ },
495
573
  metadata: {
496
574
  widgetType: s,
497
575
  widgetId: c
498
576
  }
499
- };
577
+ });
500
578
  }
501
- }), P = h.makeRule({
579
+ }), V = h.makeWidgetRule({
502
580
  name: "interactive-graph-locked-figure-oob",
503
- severity: h.Severity.WARNING,
504
- selector: "widget",
505
- lint: function(e, t, n, r, i) {
506
- if (e.currentNode().widgetType !== "interactive-graph") return;
507
- let a = e.currentNode().id;
508
- if (!a) return;
509
- let o = i?.widgets?.[a];
510
- if (!o) return;
511
- let { range: s, lockedFigures: c } = o.options, l = [];
512
- for (let e of c ?? []) if (!hasPointInRange(e, s)) {
581
+ widgetType: "interactive-graph",
582
+ lint(e) {
583
+ let { range: t, lockedFigures: n } = e.options, r = [];
584
+ for (let e of n ?? []) if (!hasPointInRange(e, t)) {
513
585
  let t = getPreciseFigureType(e), n = e.type === "point" || e.type === "label";
514
- l.push(n ? `Locked ${t} is outside the graph bounds.` : `All defining points for locked ${t} are outside the graph bounds.`);
586
+ r.push(n ? `Locked ${t} is outside the graph bounds.` : `All defining points for locked ${t} are outside the graph bounds.`);
515
587
  }
516
- return l.join("\n\n");
588
+ return r.map((e) => linterWarning(e));
517
589
  }
518
590
  });
519
591
  function getPreciseFigureType(e) {
@@ -551,23 +623,17 @@ function definingPoints(e) {
551
623
  }
552
624
  //#endregion
553
625
  //#region packages/perseus-linter/src/rules/interactive-graph-widget-error.ts
554
- var F = h.makeRule({
626
+ var H = h.makeWidgetRule({
555
627
  name: "interactive-graph-widget-error",
556
- severity: h.Severity.ERROR,
557
- selector: "widget",
558
- lint: function(e, t, n, r, i) {
559
- if (e.currentNode().widgetType !== "interactive-graph") return;
560
- let a = e.currentNode().id;
561
- if (!a) return;
562
- let o = i?.widgets?.[a];
563
- if (!o) return;
564
- let s = [], { correct: c, graph: u, lockedFigures: d } = o.options;
565
- for (let e of d ?? []) e.type === "line" && l.equal(e.points[0].coord, e.points[1].coord) && s.push("Locked line cannot have length 0."), e.type === "polygon" && e.points.every((t) => l.equal(t, e.points[0])) && s.push("Locked polygon cannot have all coordinates be the same."), e.type === "ellipse" && (e.radius[0] <= 0 || e.radius[1] <= 0) && s.push("Locked ellipse must have positive radius values.");
566
- if (c?.type === "polygon" && c.numSides === "unlimited" && c.coords == null && s.push("Polygon must be closed."), u?.type === "exponential" && u.startCoords != null) {
567
- let { coords: e, asymptote: t } = u.startCoords, n = t, r = Math.min(e[0][1], e[1][1]), i = Math.max(e[0][1], e[1][1]);
568
- n >= r && n <= i && s.push("The exponential start asymptote must not fall between or on the curve's start points.");
628
+ widgetType: "interactive-graph",
629
+ lint(e) {
630
+ let t = [], { correct: n, graph: r, lockedFigures: i } = e.options;
631
+ for (let e of i ?? []) e.type === "line" && l.equal(e.points[0].coord, e.points[1].coord) && t.push("Locked line cannot have length 0."), e.type === "polygon" && e.points.every((t) => l.equal(t, e.points[0])) && t.push("Locked polygon cannot have all coordinates be the same."), e.type === "ellipse" && (e.radius[0] <= 0 || e.radius[1] <= 0) && t.push("Locked ellipse must have positive radius values.");
632
+ if (n?.type === "polygon" && n.numSides === "unlimited" && n.coords == null && t.push("Polygon must be closed."), r?.type === "exponential" && r.startCoords != null) {
633
+ let { coords: e, asymptote: n } = r.startCoords, i = n, a = Math.min(e[0][1], e[1][1]), o = Math.max(e[0][1], e[1][1]);
634
+ i >= a && i <= o && t.push("The exponential start asymptote must not fall between or on the curve's start points.");
569
635
  }
570
- return checkShowPointLabelsHasLabels(u, s), checkShowPointLabelsHasLabels(c, s), s.join("\n\n");
636
+ return checkShowPointLabelsHasLabels(r, t), checkShowPointLabelsHasLabels(n, t), t.map((e) => linterError(e));
571
637
  }
572
638
  });
573
639
  function checkShowPointLabelsHasLabels(e, t) {
@@ -601,83 +667,70 @@ function expectedLabelCount(e) {
601
667
  }
602
668
  //#endregion
603
669
  //#region packages/perseus-linter/src/rules/label-image-widget-error.ts
604
- var I = h.makeRule({
670
+ var U = h.makeWidgetRule({
605
671
  name: "label-image-widget-error",
606
- severity: h.Severity.ERROR,
607
- selector: "widget",
608
- lint: function(e, t, n, r, i) {
609
- if (e.currentNode().widgetType !== "label-image") return;
610
- let a = e.currentNode().id;
611
- if (!a) return;
612
- let o = i?.widgets?.[a];
613
- if (!o) return;
614
- let s = [], { choices: c, imageAlt: l, imageUrl: u, markers: d } = o.options;
615
- if (c.length < 2 && s.push("label-image widget must have at least two answer choices"), u ? l || s.push("No image alt text provided") : s.push("No image url provided"), !d.length) s.push("label-image widget requires at least one marker");
672
+ widgetType: "label-image",
673
+ lint(e) {
674
+ let t = [], { choices: n, imageAlt: r, imageUrl: i, markers: a } = e.options;
675
+ if (n.length < 2 && t.push("label-image widget must have at least two answer choices"), i ? r || t.push("No image alt text provided") : t.push("No image url provided"), a.length === 0) t.push("label-image widget requires at least one marker");
616
676
  else {
617
- let e = 0, t = 0;
618
- for (let n of d) n.answers.length || e++, n.label || t++;
619
- e > 0 && s.push(`label-image widget has ${e} markers with no answers selected`), t > 0 && s.push(`label-image widget has ${t} markers with no ARIA label`);
677
+ let e = 0, n = 0;
678
+ for (let t of a) t.answers.length === 0 && e++, t.label || n++;
679
+ e > 0 && t.push(`label-image widget has ${e} markers with no answers selected`), n > 0 && t.push(`label-image widget has ${n} markers with no ARIA label`);
620
680
  }
621
- return s.join("\n\n");
681
+ return t.map((e) => linterError(e));
622
682
  }
623
- }), L = "ka-perseus-images.s3.amazonaws.com", R = h.makeRule({
683
+ }), W = "ka-perseus-images.s3.amazonaws.com", G = h.makeWidgetRule({
624
684
  name: "legacy-gif-url",
625
- severity: h.Severity.GUIDELINE,
626
- selector: "widget",
627
- lint: function(e, t, n, r, i) {
628
- if (e.currentNode().widgetType !== "image") return;
629
- let a = e.currentNode().id;
630
- if (!a) return;
631
- let o = i && i.widgets && i.widgets[a];
632
- if (!o) return;
633
- let s = o.options?.backgroundImage?.url;
634
- if (s && getHostname(s) === L && s.toLowerCase().endsWith(".gif")) return `Legacy gif URL:
635
- gifs hosted at ${L} might not appear in the editor preview,
685
+ widgetType: "image",
686
+ lint(e) {
687
+ let t = e.options?.backgroundImage?.url;
688
+ if (t && getHostname(t) === W && t.toLowerCase().endsWith(".gif")) return linterGuideline(`Legacy gif URL:
689
+ gifs hosted at ${W} might not appear in the editor preview,
636
690
  but can still be viewed in the published content. Please use a
637
691
  cdn.kastatic.org/ka-perseus-images/ URL instead or confirm the
638
- image displays correctly in the published content.`;
692
+ image displays correctly in the published content.`);
639
693
  }
640
- }), z = h.makeRule({
694
+ }), ie = h.makeRule({
641
695
  name: "link-click-here",
642
- severity: h.Severity.WARNING,
643
696
  selector: "link",
644
697
  pattern: /click here/i,
645
- message: "Inappropriate link text:\nDo not use the words \"click here\" in links."
646
- }), B = h.makeRule({
698
+ lint: h.makeLintFunction({
699
+ severity: h.Severity.WARNING,
700
+ message: "Inappropriate link text:\nDo not use the words \"click here\" in links."
701
+ })
702
+ }), K = h.makeRule({
647
703
  name: "long-paragraph",
648
- severity: h.Severity.GUIDELINE,
649
704
  selector: "paragraph",
650
705
  pattern: /^.{501,}/,
651
706
  lint: function(e, t, n, r) {
652
- return `Paragraph too long:
707
+ return linterGuideline(`Paragraph too long:
653
708
  This paragraph is ${t.length} characters long.
654
- Shorten it to 500 characters or fewer.`;
709
+ Shorten it to 500 characters or fewer.`);
655
710
  }
656
- }), V = h.makeRule({
711
+ }), q = h.makeWidgetRule({
657
712
  name: "matcher-widget-error",
658
- severity: h.Severity.ERROR,
659
- selector: "widget",
660
- lint: function(e, t, n, r, i) {
661
- if (e.currentNode().widgetType !== "matcher") return;
662
- let a = e.currentNode().id;
663
- if (!a) return;
664
- let o = i?.widgets?.[a];
665
- if (o && o.options.left.length !== o.options.right.length) return "The two halves of the matcher have different numbers of cards.";
713
+ widgetType: "matcher",
714
+ lint(e) {
715
+ if (e.options.left.length !== e.options.right.length) return linterError("The two halves of the matcher have different numbers of cards.");
666
716
  }
667
- }), ae = h.makeRule({
717
+ }), J = h.makeRule({
668
718
  name: "math-adjacent",
669
- severity: h.Severity.WARNING,
670
719
  selector: "blockMath+blockMath",
671
- message: "Adjacent math blocks:\ncombine the blocks between \\begin{align} and \\end{align}"
672
- }), H = h.makeRule({
720
+ lint: h.makeLintFunction({
721
+ severity: h.Severity.WARNING,
722
+ message: "Adjacent math blocks:\ncombine the blocks between \\begin{align} and \\end{align}"
723
+ })
724
+ }), Y = h.makeRule({
673
725
  name: "math-align-extra-break",
674
- severity: h.Severity.WARNING,
675
726
  selector: "blockMath",
676
727
  pattern: /(\\{2,})\s*\\end{align}/,
677
- message: "Extra space at end of block:\nDon't end an align block with backslashes"
678
- }), U = h.makeRule({
728
+ lint: h.makeLintFunction({
729
+ severity: h.Severity.WARNING,
730
+ message: "Extra space at end of block:\nDon't end an align block with backslashes"
731
+ })
732
+ }), ae = h.makeRule({
679
733
  name: "math-align-linebreaks",
680
- severity: h.Severity.WARNING,
681
734
  selector: "blockMath",
682
735
  pattern: /\\begin{align}[\s\S]*\\\\[\s\S]+\\end{align}/,
683
736
  lint: function(e, t, n, r) {
@@ -687,244 +740,232 @@ Shorten it to 500 characters or fewer.`;
687
740
  if (e === -1) return;
688
741
  i = i.substring(e + 2);
689
742
  let t = i.match(/^\s*\\\\\s*(?!\\\\)/);
690
- if (!t) return "Use four backslashes between lines of an align block";
743
+ if (!t) return linterWarning("Use four backslashes between lines of an align block");
691
744
  i = i.substring(t[0].length);
692
745
  }
693
746
  }
694
- }), W = h.makeRule({
747
+ }), oe = h.makeRule({
695
748
  name: "math-empty",
696
- severity: h.Severity.WARNING,
697
749
  selector: "math, blockMath",
698
750
  pattern: /^$/,
699
- message: "Empty math: don't use $$ in your markdown."
700
- }), G = h.makeRule({
751
+ lint: h.makeLintFunction({
752
+ severity: h.Severity.WARNING,
753
+ message: "Empty math: don't use $$ in your markdown."
754
+ })
755
+ }), se = h.makeRule({
701
756
  name: "math-frac",
702
- severity: h.Severity.GUIDELINE,
703
757
  selector: "math, blockMath",
704
758
  pattern: /\\frac[ {]/,
705
- message: "Use \\dfrac instead of \\frac in your math expressions."
706
- }), K = h.makeRule({
759
+ lint: h.makeLintFunction({
760
+ severity: h.Severity.GUIDELINE,
761
+ message: "Use \\dfrac instead of \\frac in your math expressions."
762
+ })
763
+ }), ce = h.makeRule({
707
764
  name: "math-nested",
708
- severity: h.Severity.ERROR,
709
765
  selector: "math, blockMath",
710
766
  pattern: /\\text{[^$}]*\$[^$}]*\$[^}]*}/,
711
- message: "Nested math:\nDon't nest math expressions inside \\text{} blocks"
712
- }), q = h.makeRule({
767
+ lint: h.makeLintFunction({
768
+ severity: h.Severity.ERROR,
769
+ message: "Nested math:\nDon't nest math expressions inside \\text{} blocks"
770
+ })
771
+ }), le = h.makeRule({
713
772
  name: "math-starts-with-space",
714
- severity: h.Severity.GUIDELINE,
715
773
  selector: "math, blockMath",
716
774
  pattern: /^\s*(~|\\qquad|\\quad|\\,|\\;|\\:|\\ |\\!|\\enspace|\\phantom)/,
717
- message: "Math starts with space:\nmath should not be indented. Do not begin math expressions with\nLaTeX space commands like ~, \\;, \\quad, or \\phantom"
718
- }), J = h.makeRule({
775
+ lint: h.makeLintFunction({
776
+ severity: h.Severity.GUIDELINE,
777
+ message: "Math starts with space:\nmath should not be indented. Do not begin math expressions with\nLaTeX space commands like ~, \\;, \\quad, or \\phantom"
778
+ })
779
+ }), ue = h.makeRule({
719
780
  name: "math-text-empty",
720
- severity: h.Severity.WARNING,
721
781
  selector: "math, blockMath",
722
782
  pattern: /\\text{\s*}/,
723
- message: "Empty \\text{} block in math expression"
724
- }), oe = h.makeRule({
783
+ lint: h.makeLintFunction({
784
+ severity: h.Severity.WARNING,
785
+ message: "Empty \\text{} block in math expression"
786
+ })
787
+ }), de = h.makeRule({
725
788
  name: "math-without-dollars",
726
- severity: h.Severity.GUIDELINE,
727
789
  pattern: /\\\w+{[^}]*}|{|}/,
728
- message: "This looks like LaTeX:\ndid you mean to put it inside dollar signs?"
729
- }), se = h.makeRule({
790
+ lint: h.makeLintFunction({
791
+ severity: h.Severity.GUIDELINE,
792
+ message: "This looks like LaTeX:\ndid you mean to put it inside dollar signs?"
793
+ })
794
+ }), fe = h.makeRule({
730
795
  name: "nested-lists",
731
- severity: h.Severity.WARNING,
732
796
  selector: "list list",
733
- message: "Nested lists:\nnested lists are hard to read on mobile devices;\ndo not use additional indentation."
734
- }), ce = h.makeRule({
797
+ lint: h.makeLintFunction({
798
+ severity: h.Severity.WARNING,
799
+ message: "Nested lists:\nnested lists are hard to read on mobile devices;\ndo not use additional indentation."
800
+ })
801
+ }), pe = h.makeWidgetRule({
735
802
  name: "numeric-input-missing-label",
736
- severity: h.Severity.WARNING,
737
- selector: "widget",
738
- lint: function(e, t, n, r, i) {
739
- if (e.currentNode().widgetType !== "numeric-input") return;
740
- let a = e.currentNode().id;
741
- if (!a) return;
742
- let o = i?.widgets?.[a];
743
- if (o && !o.options.labelText) return "Inputs should have an aria label:\nWhile screen readers will fallback to a default label of 'Your answer', a more descriptive label would improve accessibility.";
803
+ widgetType: "numeric-input",
804
+ lint(e) {
805
+ if (!e.options.labelText) return linterWarning("Inputs should have an aria label:\nWhile screen readers will fallback to a default label of 'Your answer', a more descriptive label would improve accessibility.");
744
806
  }
745
- }), le = h.makeRule({
807
+ }), me = h.makeWidgetRule({
746
808
  name: "numeric-input-widget-error",
747
- severity: h.Severity.ERROR,
748
- selector: "widget",
749
- lint: function(e, t, n, r, i) {
750
- if (e.currentNode().widgetType !== "numeric-input") return;
751
- let a = e.currentNode().id;
752
- if (!a) return;
753
- let o = i?.widgets?.[a];
754
- if (!o) return;
755
- let s = [], c = o.options.answers;
756
- return c.some((e) => e.value == null) && s.push("One or more answers is empty"), c.forEach((e, t) => {
757
- e.strict && (!e.answerForms || e.answerForms.length === 0) && s.push(`Answer ${t + 1} requires a format, but no format was selected`);
758
- }), s.join("\n\n");
809
+ widgetType: "numeric-input",
810
+ lint(e) {
811
+ let t = [], n = e.options.answers;
812
+ return n.some((e) => e.value == null) && t.push("One or more answers is empty"), n.forEach((e, n) => {
813
+ e.strict && (!e.answerForms || e.answerForms.length === 0) && t.push(`Answer ${n + 1} requires a format, but no format was selected`);
814
+ }), t;
759
815
  }
760
- }), ue = h.makeRule({
816
+ }), he = h.makeWidgetRule({
761
817
  name: "phet-simulation-widget-error",
762
- severity: h.Severity.ERROR,
763
- selector: "widget",
764
- lint: function(e, t, n, r, i) {
765
- if (e.currentNode().widgetType !== "phet-simulation") return;
766
- let o = e.currentNode().id;
767
- if (!o) return;
768
- let s = i?.widgets?.[o];
769
- if (s && a(s.options.url, "en", "https://phet.colorado.edu") === null) return "The URL is not from the PhET domain.";
818
+ widgetType: "phet-simulation",
819
+ lint(e) {
820
+ if (a(e.options.url, "en", "https://phet.colorado.edu") === null) return linterError("The URL is not from the PhET domain.");
770
821
  }
771
- }), de = h.makeRule({
822
+ }), ge = h.makeWidgetRule({
772
823
  name: "python-program-widget-error",
773
- severity: h.Severity.ERROR,
774
- selector: "widget",
775
- lint: function(e, t, n, r, i) {
776
- if (e.currentNode().widgetType !== "python-program") return;
777
- let a = e.currentNode().id;
778
- if (!a) return;
779
- let o = i?.widgets?.[a];
780
- if (!o) return;
781
- let s = [], c = o.options.height;
782
- return o.options.programID === "" && s.push("The program ID is required."), (!Number.isInteger(c) || c < 1) && s.push("The height must be a positive integer."), s.join("\n\n");
824
+ widgetType: "python-program",
825
+ lint(e) {
826
+ let t = [], n = e.options.height;
827
+ return e.options.programID === "" && t.push("The program ID is required."), (!Number.isInteger(n) || n < 1) && t.push("The height must be a positive integer."), t.map((e) => linterError(e));
783
828
  }
784
- }), fe = h.makeRule({
829
+ }), _e = h.makeWidgetRule({
785
830
  name: "radio-widget-error",
786
- severity: h.Severity.ERROR,
787
- selector: "widget",
788
- lint: function(e, t, n, r, i) {
789
- if (e.currentNode().widgetType !== "radio") return;
790
- let a = e.currentNode().id;
791
- if (!a) return;
792
- let o = i?.widgets?.[a];
793
- if (!o) return;
794
- let s = o.options.choices;
795
- if (!s.some((e) => e.correct)) return "No choice is marked as correct.";
796
- let c = s.filter((e) => e.correct);
797
- if (c.some((e) => e.isNoneOfTheAbove) && c.length > 1) return "Cannot mark both None of the Above and another choice as correct.";
831
+ widgetType: "radio",
832
+ lint(e) {
833
+ let t = e.options.choices;
834
+ if (!t.some((e) => e.correct)) return linterError("No choice is marked as correct.");
835
+ let n = t.filter((e) => e.correct);
836
+ if (n.some((e) => e.isNoneOfTheAbove) && n.length > 1) return linterError("Cannot mark both None of the Above and another choice as correct.");
798
837
  }
799
- }), Y = 2;
838
+ }), X = 2;
800
839
  function hasMixedContent(e) {
801
840
  let t = [];
802
- return c(s(e.trim(), {}), (e) => {
841
+ return s(o(e.trim(), {}), (e) => {
803
842
  e.type !== "paragraph" && t.push(e);
804
843
  }), t.length > 1 && t.some((e) => e.type === "image");
805
844
  }
806
- var pe = h.makeRule({
845
+ var ve = h.makeWidgetRule({
807
846
  name: "sorter-widget-error",
808
- severity: h.Severity.ERROR,
809
- selector: "widget",
810
- lint: function(e, t, n, r, i) {
811
- if (e.currentNode().widgetType !== "sorter") return;
812
- let a = e.currentNode().id;
813
- if (!a) return;
814
- let o = i?.widgets?.[a];
815
- if (!o) return;
816
- let s = [], c = o.options.correct ?? [];
817
- return c.length < Y && s.push(`Sorter requires at least ${Y} cards.`), c.some((e) => e.trim() === "") && s.push("Sorter cards cannot be blank."), c.some(hasMixedContent) && s.push("Sorter cards cannot mix images with other content."), s.join("\n\n");
847
+ widgetType: "sorter",
848
+ lint(e) {
849
+ let t = [], n = e.options.correct ?? [];
850
+ return n.length < X && t.push(`Sorter requires at least ${X} cards.`), n.some((e) => e.trim() === "") && t.push("Sorter cards cannot be blank."), n.some(hasMixedContent) && t.push("Sorter cards cannot mix images with other content."), t.map((e) => linterError(e));
818
851
  }
819
- }), me = h.makeRule({
852
+ }), ye = h.makeWidgetRule({
820
853
  name: "sorter-widget-warning",
821
- severity: h.Severity.WARNING,
822
- selector: "widget",
823
- lint: function(e, t, n, r, a) {
824
- if (e.currentNode().widgetType !== "sorter") return;
825
- let o = e.currentNode().id;
826
- if (!o) return;
827
- let s = a?.widgets?.[o];
828
- if (!s) return;
829
- let c = [], { layout: l, correct: u = [] } = s.options;
830
- return u.length > i && c.push(`Sorter cannot have more than ${i} cards.`), l === "horizontal" && u.length > 5 && c.push("Sorter cannot have more than 5 cards in horizontal layout."), u.length > 5 && c.push("Having more than 5 cards in Sorter is discouraged."), c.join("\n\n");
831
- }
832
- }), he = h.makeRule({
854
+ widgetType: "sorter",
855
+ lint(e) {
856
+ let t = [], { layout: n, correct: r = [] } = e.options;
857
+ return r.length > i && t.push(`Sorter cannot have more than ${i} cards.`), n === "horizontal" && r.length > 5 && t.push("Sorter cannot have more than 5 cards in horizontal layout."), r.length > 5 && t.push("Having more than 5 cards in Sorter is discouraged."), t.map((e) => linterWarning(e));
858
+ }
859
+ }), be = h.makeRule({
833
860
  name: "static-widget-in-question-stem",
834
- severity: h.Severity.WARNING,
835
861
  selector: "widget",
836
862
  lint: (e, t, n, r, i) => {
837
863
  if (i?.contentType !== "exercise" || i.stack.includes("hint")) return;
838
864
  let a = e.currentNode().id;
839
865
  if (!a) return;
840
866
  let o = i?.widgets?.[a];
841
- if (o && o.static) return "Widget in question stem is static (non-interactive).";
867
+ if (o && o.static) return linterWarning("Widget in question stem is static (non-interactive).");
842
868
  }
843
- }), ge = "Table is missing a caption:\nScreen reader users rely on a caption to understand what a table contains\nbefore navigating its cells. Add one by putting a line of the form:\n|| Your caption here || directly above the table or using our Titled Table\ntemplate below.", X = "Table caption is empty:\nThis table has a caption line, but there is no text between the || markers,\nso screen reader users hear an empty caption. Please add the appropriate\ntitle for your table.";
869
+ }), xe = "Table is missing a caption:\nScreen reader users rely on a caption to understand what a table contains\nbefore navigating its cells. Add one by putting a line of the form:\n|| Your caption here || directly above the table or using our Titled Table\ntemplate below.", Se = "Table caption is empty:\nThis table has a caption line, but there is no text between the || markers,\nso screen reader users hear an empty caption. Please add the appropriate\ntitle for your table.";
844
870
  function getTextContent(e) {
845
871
  return typeof e == "string" ? e : Array.isArray(e) ? e.map(getTextContent).join("") : e && typeof e == "object" ? getTextContent(e.content) : "";
846
872
  }
847
873
  function getTitleText(e) {
848
874
  return getTextContent(e?.title).trim();
849
875
  }
850
- var _e = h.makeRule({
876
+ var Z = h.makeRule({
851
877
  name: "table-missing-caption",
852
- severity: h.Severity.GUIDELINE,
853
878
  selector: "table",
854
879
  lint: function(e) {
855
880
  let t = e.parent();
856
- if (t?.type !== "titledTable") return ge;
857
- if (getTitleText(t) === "") return X;
881
+ if (t?.type !== "titledTable") return linterGuideline(xe);
882
+ if (getTitleText(t) === "") return linterGuideline(Se);
858
883
  }
859
- }), ve = h.makeRule({
884
+ }), Ce = h.makeRule({
860
885
  name: "table-missing-cells",
861
- severity: h.Severity.WARNING,
862
886
  selector: "table",
863
887
  lint: function(e, t, n, r) {
864
888
  let i = n[0], a = i.header.length, o = i.cells.map((e) => e.length);
865
- for (let e = 0; e < o.length; e++) if (o[e] !== a) return `Table rows don't match header:
889
+ for (let e = 0; e < o.length; e++) if (o[e] !== a) return linterWarning(`Table rows don't match header:
866
890
  The table header has ${a} cells, but
867
- Row ${e + 1} has ${o[e]} cells.`;
891
+ Row ${e + 1} has ${o[e]} cells.`);
868
892
  }
869
- }), ye = h.makeRule({
893
+ }), we = h.makeRule({
870
894
  name: "unbalanced-code-delimiters",
871
- severity: h.Severity.ERROR,
872
895
  pattern: /[`~]+/,
873
- message: "Unbalanced code delimiters:\ncode blocks should begin and end with the same type and number of delimiters"
874
- }), Z = [
875
- g,
876
- A,
877
- ie,
878
- v,
879
- S,
880
- C,
881
- w,
882
- E,
883
- D,
884
- O,
885
- z,
886
- B,
887
- ae,
888
- H,
889
- U,
890
- W,
891
- G,
892
- K,
893
- q,
894
- J,
895
- se,
896
- he,
897
- _e,
898
- ve,
899
- h.makeRule({
900
- name: "unescaped-dollar",
896
+ lint: h.makeLintFunction({
897
+ severity: h.Severity.ERROR,
898
+ message: "Unbalanced code delimiters:\ncode blocks should begin and end with the same type and number of delimiters"
899
+ })
900
+ }), Te = h.makeRule({
901
+ name: "unescaped-dollar",
902
+ selector: "unescapedDollar",
903
+ lint: h.makeLintFunction({
901
904
  severity: h.Severity.ERROR,
902
- selector: "unescapedDollar",
903
905
  message: "Unescaped dollar sign:\nDollar signs must appear in pairs or be escaped as \\$"
904
- }),
905
- oe,
906
- ye,
907
- k,
908
- j,
909
- M,
910
- R,
911
- N,
912
- fe,
913
- y,
914
- x,
915
- V,
916
- ce,
917
- le,
918
- ue,
919
- de,
920
- I,
921
- F,
922
- P,
923
- pe,
924
- me,
925
- te,
926
- ne
927
- ], Q = class TreeTransformer {
906
+ })
907
+ });
908
+ //#endregion
909
+ //#region packages/perseus-linter/src/rules/all-rules.ts
910
+ function allRules() {
911
+ return [
912
+ te,
913
+ re,
914
+ v,
915
+ ne,
916
+ S,
917
+ b,
918
+ x,
919
+ C,
920
+ T,
921
+ D,
922
+ E,
923
+ O,
924
+ k,
925
+ A,
926
+ j,
927
+ N,
928
+ P,
929
+ F,
930
+ I,
931
+ L,
932
+ R,
933
+ z,
934
+ B,
935
+ V,
936
+ H,
937
+ U,
938
+ G,
939
+ ie,
940
+ K,
941
+ q,
942
+ J,
943
+ Y,
944
+ ae,
945
+ oe,
946
+ se,
947
+ ce,
948
+ le,
949
+ ue,
950
+ de,
951
+ fe,
952
+ pe,
953
+ me,
954
+ he,
955
+ ge,
956
+ _e,
957
+ ve,
958
+ ye,
959
+ be,
960
+ Z,
961
+ Ce,
962
+ we,
963
+ Te
964
+ ];
965
+ }
966
+ //#endregion
967
+ //#region packages/perseus-linter/src/tree-transformer.ts
968
+ var Q = class TreeTransformer {
928
969
  constructor(e) {
929
970
  this.root = e;
930
971
  }
@@ -935,7 +976,7 @@ Row ${e + 1} has ${o[e]} cells.`;
935
976
  return TreeTransformer.isNode(e) && e.type === "text" && typeof e.content == "string";
936
977
  }
937
978
  traverse(e) {
938
- this._traverse(this.root, new be(this.root), e);
979
+ this._traverse(this.root, new Ee(this.root), e);
939
980
  }
940
981
  _traverse(e, t, n) {
941
982
  let r = "";
@@ -955,7 +996,7 @@ Row ${e + 1} has ${o[e]} cells.`;
955
996
  }
956
997
  return r;
957
998
  }
958
- }, be = class TraversalState {
999
+ }, Ee = class TraversalState {
959
1000
  constructor(e) {
960
1001
  this.root = e, this._currentNode = null, this._containers = new $(), this._indexes = new $(), this._ancestors = new $();
961
1002
  }
@@ -1055,76 +1096,57 @@ Row ${e + 1} has ${o[e]} cells.`;
1055
1096
  };
1056
1097
  //#endregion
1057
1098
  //#region packages/perseus-linter/src/run-linter.ts
1058
- function runLinter(e, t, n, r = Z) {
1059
- let i = [], a = new Q(e);
1060
- a.traverse((e, t, n) => {
1099
+ function runLinter(e, t, n) {
1100
+ let r = [], i = new Q(e);
1101
+ i.traverse((e, t, n) => {
1061
1102
  if (Q.isTextNode(e)) {
1062
1103
  let n = t.nextSibling();
1063
1104
  for (; Q.isTextNode(n);) e.content += n.content, t.removeNextSibling(), n = t.nextSibling();
1064
1105
  }
1065
1106
  });
1066
- let o = [], s = !1;
1067
- return a.traverse((e, a, c) => {
1068
- let l = [], u = r.filter((e) => e.applies(t)), d = [...t.stack];
1069
- d.push(e.type);
1070
- let f = {
1107
+ let a = [], o = !1;
1108
+ return i.traverse((e, i, s) => {
1109
+ let c = [], l = [...t.stack];
1110
+ l.push(e.type);
1111
+ let u = {
1071
1112
  ...t,
1072
- stack: d.join(".")
1113
+ stack: l.join(".")
1073
1114
  };
1074
- if (u.forEach((t) => {
1075
- let r = t.check(e, a, c, f);
1076
- r && ((r.start || r.end) && (r.target = c.substring(r.start, r.end)), i.push(r), n && l.push(r));
1077
- }), n && (e.type === "table" ? (o.length && l.push(...o), s = !1, o = []) : s || (s = a.ancestors().some((e) => e.type === "table")), s && l.length > 0 && o.push(...l), l.length > 0)) {
1078
- if (l.sort((e, t) => e.severity - t.severity), e.type !== "text" || l.length > 1) a.replace({
1115
+ if (allRules().forEach((t) => {
1116
+ let a = t.check(e, i, s, u);
1117
+ for (let e of a) (e.start || e.end) && (e.target = s.substring(e.start, e.end)), r.push(e), n && c.push(e);
1118
+ }), n && (e.type === "table" ? (a.length && c.push(...a), o = !1, a = []) : o || (o = i.ancestors().some((e) => e.type === "table")), o && c.length > 0 && a.push(...c), c.length > 0)) {
1119
+ if (c.sort((e, t) => e.severity - t.severity), e.type !== "text" || c.length > 1) i.replace({
1079
1120
  type: "lint",
1080
1121
  content: e,
1081
- message: l.map((e) => e.message).join("\n\n"),
1082
- ruleName: l[0].rule,
1083
- blockHighlight: f.blockHighlight,
1084
- insideTable: s,
1085
- severity: l[0].severity
1122
+ message: c.map((e) => e.message).join("\n\n"),
1123
+ ruleName: c[0].rule,
1124
+ blockHighlight: u.blockHighlight,
1125
+ insideTable: o,
1126
+ severity: c[0].severity
1086
1127
  });
1087
1128
  else {
1088
- let t = e.content, n = l[0], r = n.start, i = n.end, o = t.substring(0, r), c = t.substring(r, i), u = t.substring(i), d = [];
1089
- o && d.push({
1129
+ let t = e.content, n = c[0], r = n.start, a = n.end, s = t.substring(0, r), l = t.substring(r, a), u = t.substring(a), d = [];
1130
+ s && d.push({
1090
1131
  type: "text",
1091
- content: o
1132
+ content: s
1092
1133
  }), d.push({
1093
1134
  type: "lint",
1094
1135
  content: {
1095
1136
  type: "text",
1096
- content: c
1137
+ content: l
1097
1138
  },
1098
1139
  message: n.message,
1099
1140
  ruleName: n.rule,
1100
- insideTable: s,
1141
+ insideTable: o,
1101
1142
  severity: n.severity
1102
1143
  }), u && d.push({
1103
1144
  type: "text",
1104
1145
  content: u
1105
- }), a.replace(...d);
1146
+ }), i.replace(...d);
1106
1147
  }
1107
1148
  }
1108
- }), i;
1109
- }
1110
- //#endregion
1111
- //#region packages/perseus-linter/src/lint-content.ts
1112
- function lintPerseusItem(e) {
1113
- return {
1114
- question: lintPerseusRenderer(e.question, "exercise"),
1115
- hints: e.hints.map((e) => lintPerseusRenderer(e, "exercise"))
1116
- };
1117
- }
1118
- function lintPerseusArticle(e) {
1119
- return (Array.isArray(e) ? e : [e]).map((e) => lintPerseusRenderer(e, "article"));
1120
- }
1121
- function lintPerseusRenderer(e, t) {
1122
- return [...runLinter(s(e.content), {
1123
- content: e.content,
1124
- widgets: e.widgets,
1125
- stack: [],
1126
- contentType: t
1127
- }, !1)];
1149
+ }), r;
1128
1150
  }
1129
1151
  //#endregion
1130
1152
  //#region packages/perseus-linter/src/index.ts
@@ -1136,6 +1158,6 @@ function pushContextStack(e, t) {
1136
1158
  };
1137
1159
  }
1138
1160
  //#endregion
1139
- export { h as Rule, d as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer, f as linterContextDefault, pushContextStack, Z as rules, runLinter };
1161
+ export { h as Rule, d as libVersion, lintPerseusArticle, lintPerseusItem, lintPerseusRenderer, ee as linterContextDefault, pushContextStack, runLinter };
1140
1162
 
1141
1163
  //# sourceMappingURL=index.js.map