@khanacademy/perseus-linter 0.0.0-PR973-20240207213425 → 0.0.0-PR992-20240214202318

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.
Files changed (51) hide show
  1. package/package.json +7 -5
  2. package/.eslintrc.js +0 -12
  3. package/CHANGELOG.md +0 -168
  4. package/src/README.md +0 -41
  5. package/src/__tests__/matcher.test.ts +0 -498
  6. package/src/__tests__/rule.test.ts +0 -110
  7. package/src/__tests__/rules.test.ts +0 -548
  8. package/src/__tests__/selector-parser.test.ts +0 -51
  9. package/src/__tests__/tree-transformer.test.ts +0 -444
  10. package/src/index.ts +0 -281
  11. package/src/proptypes.ts +0 -19
  12. package/src/rule.ts +0 -419
  13. package/src/rules/absolute-url.ts +0 -23
  14. package/src/rules/all-rules.ts +0 -71
  15. package/src/rules/blockquoted-math.ts +0 -9
  16. package/src/rules/blockquoted-widget.ts +0 -9
  17. package/src/rules/double-spacing-after-terminal.ts +0 -11
  18. package/src/rules/extra-content-spacing.ts +0 -11
  19. package/src/rules/heading-level-1.ts +0 -13
  20. package/src/rules/heading-level-skip.ts +0 -19
  21. package/src/rules/heading-sentence-case.ts +0 -10
  22. package/src/rules/heading-title-case.ts +0 -68
  23. package/src/rules/image-alt-text.ts +0 -20
  24. package/src/rules/image-in-table.ts +0 -9
  25. package/src/rules/image-spaces-around-urls.ts +0 -34
  26. package/src/rules/image-widget.ts +0 -49
  27. package/src/rules/link-click-here.ts +0 -10
  28. package/src/rules/lint-utils.ts +0 -47
  29. package/src/rules/long-paragraph.ts +0 -13
  30. package/src/rules/math-adjacent.ts +0 -9
  31. package/src/rules/math-align-extra-break.ts +0 -10
  32. package/src/rules/math-align-linebreaks.ts +0 -42
  33. package/src/rules/math-empty.ts +0 -9
  34. package/src/rules/math-font-size.ts +0 -11
  35. package/src/rules/math-frac.ts +0 -9
  36. package/src/rules/math-nested.ts +0 -10
  37. package/src/rules/math-starts-with-space.ts +0 -11
  38. package/src/rules/math-text-empty.ts +0 -9
  39. package/src/rules/math-without-dollars.ts +0 -13
  40. package/src/rules/nested-lists.ts +0 -10
  41. package/src/rules/profanity.ts +0 -9
  42. package/src/rules/table-missing-cells.ts +0 -19
  43. package/src/rules/unbalanced-code-delimiters.ts +0 -13
  44. package/src/rules/unescaped-dollar.ts +0 -9
  45. package/src/rules/widget-in-table.ts +0 -9
  46. package/src/selector.ts +0 -504
  47. package/src/tree-transformer.ts +0 -583
  48. package/src/types.ts +0 -7
  49. package/src/version.ts +0 -10
  50. package/tsconfig-build.json +0 -12
  51. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,548 +0,0 @@
1
- import * as PureMarkdown from "@khanacademy/pure-markdown";
2
-
3
- import absoluteUrlRule from "../rules/absolute-url";
4
- import blockquotedMathRule from "../rules/blockquoted-math";
5
- import blockquotedWidgetRule from "../rules/blockquoted-widget";
6
- import doubleSpacingAfterTerminalRule from "../rules/double-spacing-after-terminal";
7
- import extraContentSpacingRule from "../rules/extra-content-spacing";
8
- import headingLevel1Rule from "../rules/heading-level-1";
9
- import headingLevelSkipRule from "../rules/heading-level-skip";
10
- import headingSentenceCaseRule from "../rules/heading-sentence-case";
11
- import headingTitleCaseRule from "../rules/heading-title-case";
12
- import imageAltTextRule from "../rules/image-alt-text";
13
- import imageInTableRule from "../rules/image-in-table";
14
- import imageSpacesAroundUrlsRule from "../rules/image-spaces-around-urls";
15
- import imageWidgetRule from "../rules/image-widget";
16
- import linkClickHereRule from "../rules/link-click-here";
17
- import longParagraphRule from "../rules/long-paragraph";
18
- import mathAdjacentRule from "../rules/math-adjacent";
19
- import mathAlignExtraBreakRule from "../rules/math-align-extra-break";
20
- import mathAlignLinebreaksRule from "../rules/math-align-linebreaks";
21
- import mathEmptyRule from "../rules/math-empty";
22
- import mathFontSizeRule from "../rules/math-font-size";
23
- import mathFracRule from "../rules/math-frac";
24
- import mathNestedRule from "../rules/math-nested";
25
- import mathStartsWithSpaceRule from "../rules/math-starts-with-space";
26
- import mathTextEmptyRule from "../rules/math-text-empty";
27
- import mathWithoutDollarsRule from "../rules/math-without-dollars";
28
- import nestedListsRule from "../rules/nested-lists";
29
- import profanityRule from "../rules/profanity";
30
- import tableMissingCellsRule from "../rules/table-missing-cells";
31
- import unbalancedCodeDelimitersRule from "../rules/unbalanced-code-delimiters";
32
- import unescapedDollarRule from "../rules/unescaped-dollar";
33
- import widgetInTableRule from "../rules/widget-in-table";
34
- import TreeTransformer from "../tree-transformer";
35
-
36
- type Rule = any;
37
-
38
- describe("Individual lint rules tests", () => {
39
- function testRule(rule: Rule, markdown: string, context) {
40
- const tree = PureMarkdown.parse(markdown);
41
- const tt = new TreeTransformer(tree);
42
- const warnings = [];
43
-
44
- // The markdown parser often outputs adjacent text nodes. We
45
- // coalesce them before linting for efficiency and accuracy.
46
- tt.traverse((node, state, content) => {
47
- if (TreeTransformer.isTextNode(node)) {
48
- let next = state.nextSibling();
49
- while (TreeTransformer.isTextNode(next)) {
50
- // @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'. | TS2533 - Object is possibly 'null' or 'undefined'. | TS2339 - Property 'content' does not exist on type 'TreeNode'.
51
- node.content += next.content;
52
- state.removeNextSibling();
53
- next = state.nextSibling();
54
- }
55
- }
56
- });
57
-
58
- if (context) {
59
- context.content = markdown;
60
- } else {
61
- context = {
62
- content: markdown,
63
- widgets: {},
64
- };
65
- }
66
- tt.traverse((node, state, content) => {
67
- const check = rule.check(node, state, content, context);
68
- if (check) {
69
- // @ts-expect-error - TS2345 - Argument of type 'any' is not assignable to parameter of type 'never'.
70
- warnings.push(check);
71
- }
72
- });
73
-
74
- return warnings.length === 0 ? null : warnings;
75
- }
76
-
77
- function expectWarning(rule, strings: string | Array<string>, context) {
78
- if (typeof strings === "string") {
79
- strings = [strings];
80
- }
81
-
82
- it(`Rule ${rule.name} warns`, () => {
83
- for (const string of strings) {
84
- expect(testRule(rule, string, context) !== null).toBeTruthy();
85
- }
86
- });
87
- }
88
-
89
- function expectPass(rule, strings: string | Array<string>, context) {
90
- if (typeof strings === "string") {
91
- strings = [strings];
92
- }
93
-
94
- it(`Rule ${rule.name} passes`, () => {
95
- for (const string of strings) {
96
- expect(testRule(rule, string, context) === null).toBeTruthy();
97
- }
98
- });
99
- }
100
-
101
- // 299 characters
102
- const sentence = new Array(25).fill("lorem ipsum").join(" ");
103
-
104
- // long-paragraph rule warns about paragraphs over 500 characters
105
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
106
- expectWarning(longParagraphRule, sentence + sentence);
107
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
108
- expectPass(longParagraphRule, [sentence, sentence + "\n\n" + sentence]);
109
-
110
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
111
- expectWarning(headingLevel1Rule, "# Level 1 heading");
112
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
113
- expectPass(headingLevel1Rule, "## Level 1 heading\n\n### Level 3 heading");
114
-
115
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
116
- expectWarning(headingLevelSkipRule, "## heading 1\n\n#### heading 2");
117
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
118
- expectPass(headingLevelSkipRule, [
119
- "## heading 1\n\n### heading 2\n\n#### heading 3\n\n### heading 4",
120
- "## heading 1\n\n##heading 2\n\n##heading3",
121
- ]);
122
-
123
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
124
- expectWarning(
125
- headingTitleCaseRule,
126
- "## This Heading is in Title Case and the but nor for Too",
127
- );
128
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
129
- expectPass(headingTitleCaseRule, [
130
- "## This heading is in sentence case",
131
- "## Acronyms: The CIA, NSA, DNI, and FBI",
132
- "## The Great War",
133
- ]);
134
-
135
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
136
- expectWarning(headingSentenceCaseRule, [
137
- "## this heading is uncapitalized",
138
- "## 'this' heading is uncapitalized",
139
- "## this heading is uncapitalized",
140
- ]);
141
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
142
- expectPass(headingSentenceCaseRule, [
143
- "## This heading is in sentence case",
144
- "## 'This heading too'",
145
- "## 2 + 2 = 4",
146
- ]);
147
-
148
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
149
- expectWarning(nestedListsRule, [
150
- "1. outer\n * nested\n *nested",
151
- " + outer\n\n 1. nested",
152
- ]);
153
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
154
- expectPass(nestedListsRule, [
155
- "-one\n-two\n-three",
156
- "1. one\n 2. two\n3. three",
157
- " * one\n\n * two\n\n * three",
158
- ]);
159
-
160
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
161
- expectWarning(imageAltTextRule, [
162
- "![](http://google.com/)",
163
- '![](http://google.com/ "title")',
164
- "![][url-ref]",
165
- "![ ](http://google.com/)",
166
- "![ \t\n ](http://google.com/)", // all whitespace
167
- "![blah](http://google.com/)", // too short to be meaningful
168
- ]);
169
-
170
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
171
- expectPass(imageAltTextRule, [
172
- "![alt-text](http://google.com)",
173
- '![alternative text](http://google.com/ "title")',
174
- "![alt alt alt][url-ref]",
175
- ]);
176
-
177
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
178
- expectWarning(blockquotedMathRule, ["> $1$", "Quote:\n\n> $x$\n\n"]);
179
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
180
- expectPass(blockquotedMathRule, [
181
- "$x$",
182
- "\n$x$\n $y$\n",
183
- "> bq #1\n\n$x+y=1$\n\n> bq #2",
184
- ]);
185
-
186
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
187
- expectWarning(blockquotedWidgetRule, ["> [[☃ passage 1]]"]);
188
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
189
- expectPass(blockquotedWidgetRule, [
190
- "[[☃ passage 1]]",
191
- "> bq #1\n\nTesting [[☃ passage 1]] testing\n\n> bq #2",
192
- ]);
193
-
194
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
195
- expectWarning(linkClickHereRule, [
196
- "[click here](http://google.com)",
197
- "[Click here, please](http://google.com)",
198
- "[For a good time, Click Here](http://google.com)",
199
- ]);
200
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
201
- expectPass(linkClickHereRule, [
202
- "[click to activate this link here](http://google.com)",
203
- ]);
204
-
205
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
206
- expectWarning(absoluteUrlRule, [
207
- // Warn about absolute khanacademy.org urls
208
- "[target](http://khanacademy.org/about)",
209
- "[target](https://khanacademy.org/about)",
210
- "[target](http://www.khanacademy.org/about)",
211
- "[target](https://www.khanacademy.org/about)",
212
- "[target](http://es.khanacademy.org/about)",
213
- "[target](https://es.khanacademy.org/about)",
214
- "[target](//www.khanacademy.org/about)",
215
- "[target](//www.khanacademy.org/about)",
216
-
217
- // We should get the same warnings for images
218
- "![alt text](http://khanacademy.org/about)",
219
- "![alt text](https://www.khanacademy.org/about)",
220
- "![alt text](https://es.khanacademy.org/about)",
221
- ]);
222
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
223
- expectPass(absoluteUrlRule, [
224
- "[target](/about)", // relative URLs okay
225
- "[target](https://kasandbox.org/path)",
226
- "[target](https://fastly.kastatic.org/path)",
227
- "[target](https://cdn.kastatic.org/path)",
228
- "[target](https://ka-perseus-images.s3.amazonaws.com/path)",
229
- "[target](https://ka-youtube-converted.storage.googleapis.com)",
230
-
231
- // Same warnings for images
232
- "![alt text](/about)",
233
- "![alt text](https://cdn.kastatic.org/path)",
234
- "![alt text](https://ka-perseus-images.s3.amazonaws.com/path)",
235
- ]);
236
-
237
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
238
- expectWarning(imageInTableRule, [
239
- "|col1|col2|\n|----|----|\n|![alt-text](/link.gif)|cell2|",
240
- ]);
241
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
242
- expectPass(imageInTableRule, [
243
- "![alt-text](/link.gif)\n|col1|col2|\n|----|----|\n|cell1|cell2|",
244
- ]);
245
-
246
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
247
- expectWarning(widgetInTableRule, [
248
- "|col1|col2|\n|----|----|\n|[[☃ passage 1]]|cell2|",
249
- ]);
250
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
251
- expectPass(widgetInTableRule, [
252
- "[[☃ passage 1]]\n|col1|col2|\n|----|----|\n|cell1|cell2|",
253
- ]);
254
-
255
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
256
- expectWarning(tableMissingCellsRule, [
257
- "|col1|col2|col3|\n|----|----|----|\n|col1|col2|col3|\n|cell1|cell2|",
258
- "|col1|col2|col3|\n|----|----|----|\n|col1|col2|\n|cell1|cell2|",
259
- "|col1|col2|\n|----|----|\n|cell1|cell2|\n|cell1|cell2|cell3|",
260
- "|col1|\n|----|----|\n|col1|\n|cell1|cell2|",
261
- "|col1|col2|\n|----|----|\n|col1|\n|cell1|cell2|",
262
- ]);
263
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
264
- expectPass(tableMissingCellsRule, [
265
- "|col1|col2|\n|----|----|\n|cell1|cell2|\n|cell1|cell2|",
266
- "|cell1|\n|----|\n|cell2|\n|cell3|",
267
- ]);
268
-
269
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
270
- expectWarning(unescapedDollarRule, ["It costs $10", "It costs $$10$"]);
271
-
272
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
273
- expectPass(unescapedDollarRule, ["It costs \\$10", "It costs $10x$"]);
274
-
275
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
276
- expectWarning(mathStartsWithSpaceRule, [
277
- "foo$~ x$bar",
278
- "$\\qquad x$",
279
- "$\\quad x$",
280
- "$\\, x$",
281
- "$\\; x$",
282
- "$\\: x$",
283
- "$\\ x$",
284
- "$\\! x$",
285
- "$\\enspace x$",
286
- "$\\phantom{xyz} x$",
287
- ]);
288
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
289
- expectPass(mathStartsWithSpaceRule, [
290
- "$a~ x$",
291
- "$a\\qquad x$",
292
- "$a\\quad x$",
293
- "$a\\, x$",
294
- "$a\\; x$",
295
- "$a\\: x$",
296
- "$a\\ x$",
297
- "$a\\! x$",
298
- "$a\\enspace x$",
299
- "$a\\phantom{xyz} x$",
300
- ]);
301
-
302
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
303
- expectWarning(mathEmptyRule, [
304
- "foo $$ bar",
305
- "foo\n\n$$\n\nbar",
306
- "$$ | $$ | $$\n- | - | -\ndata 1 | data 2 | data 3",
307
- ]);
308
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
309
- expectPass(mathEmptyRule, [
310
- "foo $x$ bar",
311
- "foo\n\n$x$\n\nbar",
312
- "$x$ | $y$ | $z$\n- | - | -\ndata 1 | data 2 | data 3",
313
- ]);
314
-
315
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
316
- expectWarning(mathFracRule, ["$\\frac 12$", "$\\frac{1}{2}$"]);
317
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
318
- expectPass(mathFracRule, [
319
- "$\\dfrac 12$",
320
- "$\\dfrac{1}{2}$",
321
- "$\\fraction 12$",
322
- ]);
323
-
324
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
325
- expectWarning(mathTextEmptyRule, [
326
- "$x\\text{}y$",
327
- "$x\\text{ }y$",
328
- "$x\\text{\n}y$",
329
- "$x\\text{\t}y$",
330
- ]);
331
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
332
- expectPass(mathTextEmptyRule, ["$x\\text{z}y$"]);
333
-
334
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
335
- expectWarning(mathAdjacentRule, ["$x=b+c$\n\n$x-b=c$"]);
336
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
337
- expectPass(mathAdjacentRule, ["$x=b+c$\n\nnew paragraph\n\n$x-b=c$"]);
338
-
339
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
340
- expectWarning(mathAlignLinebreaksRule, [
341
- "$\\begin{align}x\\\\y\\end{align}$",
342
- "$\\begin{align} x \\\\ y \\end{align}$",
343
- "$\\begin{align}x\\\\\\\\\\\\y\\end{align}$",
344
- "$\\begin{align}\nx\\\\\n\\\\\\\\\ny\n\\end{align}$",
345
- ]);
346
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
347
- expectPass(mathAlignLinebreaksRule, [
348
- "$\\begin{align}x\\sqrty\\end{align}$",
349
- "$\\begin{align}x\\\\\\\\y\\end{align}$",
350
- "$\\begin{align}x\\\\\n\\\\y\\end{align}$",
351
- "$\\begin{align}x \\\\ \\\\ y\\end{align}$",
352
- ]);
353
-
354
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
355
- expectWarning(mathAlignExtraBreakRule, [
356
- "$\\begin{align}x \\\\\\\\ y \\\\ \\end{align}$",
357
- "$\\begin{align}x \\\\\\\\ y \\\\\\\\ \\end{align}$",
358
- ]);
359
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
360
- expectPass(mathAlignExtraBreakRule, [
361
- "$\\begin{align} x \\\\\\\\ y \\end{align}$",
362
- ]);
363
-
364
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
365
- expectWarning(mathNestedRule, [
366
- "$\\text{4$x$}$",
367
- "inline $\\text{4$x$}$ math",
368
- "$\\text{$$}$",
369
- ]);
370
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
371
- expectPass(mathNestedRule, ["$\\text{4}x$", "inline $\\text{4}x$ math"]);
372
-
373
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
374
- expectWarning(mathFontSizeRule, [
375
- "$\\tiny{x}$",
376
- "inline $\\Tiny{x}$ math",
377
- "$a \\small{x} b$",
378
- "$\\large{ xyz }$",
379
- "$ \\Large { x } $",
380
- "$\\LARGE{x}$",
381
- "$\\huge{x}$",
382
- "$\\Huge{x}$",
383
- "$\\normalsize{x}$",
384
- "$\\scriptsize{x}$",
385
- ]);
386
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
387
- expectPass(mathFontSizeRule, ["$\\sqrt{x}$", "inline $\\sqrt{x}$ math"]);
388
-
389
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
390
- expectWarning(profanityRule, [
391
- "Shit",
392
- "taking a piss",
393
- "He said 'Fuck that!'",
394
- "cunt",
395
- "cocksucker",
396
- "motherfucker",
397
- ]);
398
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
399
- expectPass(profanityRule, ["spit", "miss", "duck"]);
400
-
401
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
402
- expectWarning(mathWithoutDollarsRule, [
403
- "One half: \\frac{1}{2}!",
404
- "\\Large{BIG}!",
405
- "This looks like someone's ear: {",
406
- "Here's the other ear: }. Weird!",
407
- ]);
408
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
409
- expectPass(mathWithoutDollarsRule, [
410
- "One half: $\\frac{1}{2}$",
411
- "$\\Large{BIG}$!",
412
- "`{`",
413
- "`\\frac{1}{2}`",
414
- "``\\frac{1}{2}``",
415
- "```\n\\frac{1}{2}\n```",
416
- "~~~\n\\frac{1}{2}\n~~~",
417
- "\n \\frac{1}{2}\n {\n }\n",
418
- ]);
419
-
420
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
421
- expectWarning(unbalancedCodeDelimitersRule, [
422
- "`code``",
423
- "``code```",
424
- "```code\n",
425
- "~~~\ncode\n~~",
426
- ]);
427
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
428
- expectPass(unbalancedCodeDelimitersRule, [
429
- "`code`",
430
- "``code``",
431
- "```code```",
432
- "```\ncode\n```",
433
- "~~~\ncode\n~~~",
434
- "``co`de``",
435
- "`co~de`",
436
- "$`~$",
437
- ]);
438
-
439
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
440
- expectWarning(imageSpacesAroundUrlsRule, [
441
- "![alternative]( http://example.com/image.jpg )",
442
- "![alternative]( http://example.com/image.jpg)",
443
- "![alternative](http://example.com/image.jpg )",
444
- "![alternative](\thttp://example.com/image.jpg)",
445
- "![alternative](http://example.com/image.jpg\t)",
446
- "![alternative](\nhttp://example.com/image.jpg)",
447
- "![alternative](http://example.com/image.jpg\n)",
448
- ]);
449
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
450
- expectPass(imageSpacesAroundUrlsRule, [
451
- "![alternative](http://example.com/image.jpg)",
452
- "![alternative](image.jpg)",
453
- "![alternative](--image.jpg--)",
454
- ]);
455
-
456
- // Warn for image widget with no alt text
457
- expectWarning(imageWidgetRule, "[[☃ image 1]]", {
458
- widgets: {
459
- "image 1": {
460
- options: {},
461
- },
462
- },
463
- });
464
-
465
- // Warn for image widget with short alt text
466
- expectWarning(imageWidgetRule, "[[☃ image 1]]", {
467
- widgets: {
468
- "image 1": {
469
- options: {
470
- alt: "1234567",
471
- },
472
- },
473
- },
474
- });
475
-
476
- // Pass for image widget with long alt text
477
- expectPass(imageWidgetRule, "[[☃ image 1]]", {
478
- widgets: {
479
- "image 1": {
480
- options: {
481
- alt: "1234567890",
482
- },
483
- },
484
- },
485
- });
486
-
487
- // Warn for image widget with math in its caption
488
- expectWarning(imageWidgetRule, "[[☃ image 1]]", {
489
- widgets: {
490
- "image 1": {
491
- options: {
492
- alt: "1234567890",
493
- caption: "Test: $x$",
494
- },
495
- },
496
- },
497
- });
498
-
499
- // Pass for image widget with caption and no math
500
- expectPass(imageWidgetRule, "[[☃ image 1]]", {
501
- widgets: {
502
- "image 1": {
503
- options: {
504
- alt: "1234567890",
505
- caption: "Test: x",
506
- },
507
- },
508
- },
509
- });
510
-
511
- // Pass for image widget with escaped dollar in its caption
512
- expectPass(imageWidgetRule, "[[☃ image 1]]", {
513
- widgets: {
514
- "image 1": {
515
- options: {
516
- alt: "1234567890",
517
- caption: "Test: \\$10",
518
- },
519
- },
520
- },
521
- });
522
-
523
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
524
- expectWarning(doubleSpacingAfterTerminalRule, [
525
- "Good times. Great oldies.",
526
- "End of the line! ",
527
- "You? Me!",
528
- ]);
529
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
530
- expectPass(doubleSpacingAfterTerminalRule, [
531
- "This is okay.",
532
- "This is definitely okay. Yeah.",
533
- "$a == 3. 125$",
534
- ]);
535
-
536
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
537
- expectWarning(extraContentSpacingRule, [
538
- "There's extra spaces here. ",
539
- "There's extra spaces here ",
540
- " ",
541
- ]);
542
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
543
- expectPass(extraContentSpacingRule, [
544
- "This is okay.",
545
- "This is definitely okay. Yeah.",
546
- "$a == 3. 125$",
547
- ]);
548
- });
@@ -1,51 +0,0 @@
1
- import Selector from "../selector";
2
-
3
- describe("PerseusLinter selector parser", () => {
4
- const validExpressions = [
5
- "*",
6
- " * ",
7
- "para",
8
- "list para",
9
- "\tlist para\n",
10
- "list > para",
11
- "list + para",
12
- "list ~ para",
13
- "list list para",
14
- "para~heading~para~heading",
15
- "list, para",
16
- "list > para, list text, heading *, heading+para",
17
- ];
18
-
19
- const invalidExpressions = [
20
- "", // Expected node type
21
- "", // Expected node type
22
- "<", // Expected node type
23
- "+", // Expected node type
24
- "~", // Expected node type
25
- "**", // Unexpected token
26
- "foo*", // Unexpected token
27
- "*/foo/", // Unexpected token
28
- "()", // Unexpected token
29
- ",",
30
- "list,",
31
- ",list",
32
- ];
33
-
34
- validExpressions.forEach((s) => {
35
- it("parses '" + s + "'", () => {
36
- const e = Selector.parse(s);
37
- expect(e instanceof Selector).toBeTruthy();
38
- expect(e.toString().replace(/\s/g, "")).toEqual(
39
- s.replace(/\s/g, ""),
40
- );
41
- });
42
- });
43
-
44
- invalidExpressions.forEach((s) => {
45
- it("rejects '" + s + "'", () => {
46
- expect(() => {
47
- Selector.parse(s);
48
- }).toThrow();
49
- });
50
- });
51
- });