@khanacademy/perseus-linter 0.3.0 → 0.3.2

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 (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/es/index.js +420 -240
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.js +15 -20
  5. package/dist/index.js.map +1 -1
  6. package/dist/tree-transformer.d.ts +1 -1
  7. package/package.json +3 -3
  8. package/src/__tests__/matcher.test.ts +57 -57
  9. package/src/__tests__/rules.test.ts +62 -62
  10. package/src/__tests__/tree-transformer.test.ts +5 -5
  11. package/src/index.ts +4 -4
  12. package/src/rule.ts +2 -2
  13. package/src/tree-transformer.ts +9 -13
  14. package/tsconfig-build.json +11 -0
  15. package/{tsconfig.tsbuildinfo → tsconfig-build.tsbuildinfo} +1 -1
  16. package/dist/index.js.flow +0 -18
  17. package/dist/proptypes.js.flow +0 -17
  18. package/dist/rule.js.flow +0 -86
  19. package/dist/rules/absolute-url.js.flow +0 -9
  20. package/dist/rules/all-rules.js.flow +0 -9
  21. package/dist/rules/blockquoted-math.js.flow +0 -9
  22. package/dist/rules/blockquoted-widget.js.flow +0 -9
  23. package/dist/rules/double-spacing-after-terminal.js.flow +0 -9
  24. package/dist/rules/extra-content-spacing.js.flow +0 -9
  25. package/dist/rules/heading-level-1.js.flow +0 -9
  26. package/dist/rules/heading-level-skip.js.flow +0 -9
  27. package/dist/rules/heading-sentence-case.js.flow +0 -9
  28. package/dist/rules/heading-title-case.js.flow +0 -9
  29. package/dist/rules/image-alt-text.js.flow +0 -9
  30. package/dist/rules/image-in-table.js.flow +0 -9
  31. package/dist/rules/image-spaces-around-urls.js.flow +0 -9
  32. package/dist/rules/image-widget.js.flow +0 -9
  33. package/dist/rules/link-click-here.js.flow +0 -9
  34. package/dist/rules/lint-utils.js.flow +0 -8
  35. package/dist/rules/long-paragraph.js.flow +0 -9
  36. package/dist/rules/math-adjacent.js.flow +0 -9
  37. package/dist/rules/math-align-extra-break.js.flow +0 -9
  38. package/dist/rules/math-align-linebreaks.js.flow +0 -9
  39. package/dist/rules/math-empty.js.flow +0 -9
  40. package/dist/rules/math-font-size.js.flow +0 -9
  41. package/dist/rules/math-frac.js.flow +0 -9
  42. package/dist/rules/math-nested.js.flow +0 -9
  43. package/dist/rules/math-starts-with-space.js.flow +0 -9
  44. package/dist/rules/math-text-empty.js.flow +0 -9
  45. package/dist/rules/math-without-dollars.js.flow +0 -9
  46. package/dist/rules/nested-lists.js.flow +0 -9
  47. package/dist/rules/profanity.js.flow +0 -9
  48. package/dist/rules/table-missing-cells.js.flow +0 -9
  49. package/dist/rules/unbalanced-code-delimiters.js.flow +0 -9
  50. package/dist/rules/unescaped-dollar.js.flow +0 -9
  51. package/dist/rules/widget-in-table.js.flow +0 -9
  52. package/dist/selector.js.flow +0 -31
  53. package/dist/tree-transformer.js.flow +0 -253
  54. package/dist/types.js.flow +0 -12
  55. package/tsconfig.json +0 -12
@@ -73,7 +73,7 @@ export default class TreeTransformer {
73
73
  * for that traversal, and the instance is passed to the traversal callback
74
74
  * function for each node that is traversed. This class is not intended to be
75
75
  * instantiated directly, but is exported so that its type can be used for
76
- * Flow annotaions.
76
+ * type annotaions.
77
77
  **/
78
78
  export declare class TraversalState {
79
79
  root: TreeNode;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Linter engine for Perseus",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "0.3.0",
6
+ "version": "0.3.2",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -21,10 +21,10 @@
21
21
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
22
22
  },
23
23
  "dependencies": {
24
- "@khanacademy/perseus-error": "^0.2.0"
24
+ "@khanacademy/perseus-error": "^0.2.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@khanacademy/pure-markdown": "^0.2.0",
27
+ "@khanacademy/pure-markdown": "^0.2.4",
28
28
  "prop-types": "^15.6.1"
29
29
  },
30
30
  "peerDependencies": {
@@ -32,7 +32,7 @@ C
32
32
  const tt = new TreeTransformer(tree);
33
33
  tt.traverse((n, state, content) => {
34
34
  // The wildcard selector should match at every node
35
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
35
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
36
36
  expect(selector.match(state)[0]).toEqual(n);
37
37
  });
38
38
  });
@@ -82,13 +82,13 @@ C
82
82
  tt.traverse((n, state, content) => {
83
83
  const match = selector.match(state);
84
84
  const parent = state.parent();
85
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
85
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
86
86
  if (n.type === "text" && parent.type === "paragraph") {
87
87
  expect(Array.isArray(match)).toBeTruthy();
88
88
  expect(match).toHaveLength(2);
89
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
89
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
90
90
  expect(match[0]).toEqual(parent);
91
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
91
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
92
92
  expect(match[1]).toEqual(n);
93
93
  matchedText += content;
94
94
  numMatches++;
@@ -116,18 +116,18 @@ C
116
116
  const grandparent = ancestors.pop();
117
117
  if (
118
118
  n.type === "text" &&
119
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
119
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
120
120
  parent.type === "em" &&
121
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
121
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
122
122
  grandparent.type === "paragraph"
123
123
  ) {
124
124
  expect(Array.isArray(match)).toBeTruthy();
125
125
  expect(match).toHaveLength(3);
126
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
126
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
127
127
  expect(match[0]).toEqual(grandparent);
128
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
128
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
129
129
  expect(match[1]).toEqual(parent);
130
- // @ts-expect-error [FEI-5003] - TS2533 - Object is possibly 'null' or 'undefined'.
130
+ // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
131
131
  expect(match[2]).toEqual(n);
132
132
  matchedText += content;
133
133
  numMatches++;
@@ -152,11 +152,11 @@ C
152
152
  if (match !== null) {
153
153
  expect(Array.isArray(match)).toBeTruthy();
154
154
  expect(match).toHaveLength(2);
155
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
155
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
156
156
  expect(match[0].type).toEqual("paragraph");
157
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
157
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
158
158
  expect(match[1].type).toEqual("text");
159
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
159
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
160
160
  expect(match[1]).toEqual(n);
161
161
  matchedText += content;
162
162
  numMatches++;
@@ -179,13 +179,13 @@ C
179
179
  if (match !== null) {
180
180
  expect(Array.isArray(match)).toBeTruthy();
181
181
  expect(match).toHaveLength(3);
182
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
182
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
183
183
  expect(match[0].type).toEqual("paragraph");
184
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
184
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
185
185
  expect(match[1].type).toEqual("em");
186
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
186
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
187
187
  expect(match[2].type).toEqual("text");
188
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
188
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
189
189
  expect(match[2]).toEqual(n);
190
190
  matchedText += content;
191
191
  numMatches++;
@@ -208,13 +208,13 @@ C
208
208
  if (match !== null) {
209
209
  expect(Array.isArray(match)).toBeTruthy();
210
210
  expect(match).toHaveLength(2);
211
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
211
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
212
212
  expect(match[0].type).toEqual("heading");
213
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
213
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
214
214
  expect(match[0]).toEqual(state.previousSibling());
215
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
215
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
216
216
  expect(match[1].type).toEqual("paragraph");
217
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
217
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
218
218
  expect(match[1]).toEqual(n);
219
219
  matchedText += content;
220
220
  numMatches++;
@@ -237,15 +237,15 @@ C
237
237
  if (match !== null) {
238
238
  expect(Array.isArray(match)).toBeTruthy();
239
239
  expect(match).toHaveLength(3);
240
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
240
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
241
241
  expect(match[0].type).toEqual("heading");
242
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
242
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
243
243
  expect(match[1].type).toEqual("paragraph");
244
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
244
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
245
245
  expect(match[1]).toEqual(state.previousSibling());
246
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
246
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
247
247
  expect(match[2].type).toEqual("paragraph");
248
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
248
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
249
249
  expect(match[2]).toEqual(n);
250
250
  matchedText += content;
251
251
  numMatches++;
@@ -268,11 +268,11 @@ C
268
268
  if (match !== null) {
269
269
  expect(Array.isArray(match)).toBeTruthy();
270
270
  expect(match).toHaveLength(2);
271
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
271
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
272
272
  expect(match[0].type).toEqual("heading");
273
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
273
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
274
274
  expect(match[1].type).toEqual("paragraph");
275
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
275
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
276
276
  expect(match[1]).toEqual(n);
277
277
  matchedText += content;
278
278
  numMatches++;
@@ -295,13 +295,13 @@ C
295
295
  if (match !== null) {
296
296
  expect(Array.isArray(match)).toBeTruthy();
297
297
  expect(match).toHaveLength(3);
298
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
298
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
299
299
  expect(match[0].type).toEqual("heading");
300
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
300
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
301
301
  expect(match[1].type).toEqual("paragraph");
302
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
302
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
303
303
  expect(match[2].type).toEqual("paragraph");
304
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
304
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
305
305
  expect(match[2]).toEqual(n);
306
306
  matchedText += content;
307
307
  numMatches++;
@@ -324,15 +324,15 @@ C
324
324
  if (match !== null) {
325
325
  expect(Array.isArray(match)).toBeTruthy();
326
326
  expect(match).toHaveLength(3);
327
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
327
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
328
328
  expect(match[0].type).toEqual("list");
329
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
329
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
330
330
  expect(match[1].type).toEqual("paragraph");
331
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
331
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
332
332
  expect(match[1]).toEqual(state.parent());
333
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
333
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
334
334
  expect(match[2].type).toEqual("em");
335
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
335
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
336
336
  expect(match[2]).toEqual(n);
337
337
  matchedText += content;
338
338
  numMatches++;
@@ -355,15 +355,15 @@ C
355
355
  if (match !== null) {
356
356
  expect(Array.isArray(match)).toBeTruthy();
357
357
  expect(match).toHaveLength(3);
358
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
358
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
359
359
  expect(match[0].type).toEqual("list");
360
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
360
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
361
361
  expect(match[1].type).toEqual("paragraph");
362
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
362
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
363
363
  expect(match[1]).toEqual(state.parent());
364
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
364
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
365
365
  expect(match[2].type).toEqual("em");
366
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
366
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
367
367
  expect(match[2]).toEqual(n);
368
368
  matchedText += content;
369
369
  numMatches++;
@@ -386,17 +386,17 @@ C
386
386
  if (match !== null) {
387
387
  expect(Array.isArray(match)).toBeTruthy();
388
388
  expect(match).toHaveLength(3);
389
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
389
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
390
390
  expect(match[0].type).toEqual("paragraph");
391
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
391
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
392
392
  expect(match[0]).toEqual(state.parent());
393
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
393
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
394
394
  expect(match[1].type).toEqual("em");
395
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
395
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
396
396
  expect(match[1]).toEqual(state.previousSibling());
397
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
397
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
398
398
  expect(match[2].type).toEqual("text");
399
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
399
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
400
400
  expect(match[2]).toEqual(n);
401
401
  matchedText += content;
402
402
  numMatches++;
@@ -419,17 +419,17 @@ C
419
419
  if (match !== null) {
420
420
  expect(Array.isArray(match)).toBeTruthy();
421
421
  expect(match).toHaveLength(3);
422
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
422
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
423
423
  expect(match[0].type).toEqual("paragraph");
424
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
424
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
425
425
  expect(match[0]).toEqual(state.parent());
426
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
426
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
427
427
  expect(match[1].type).toEqual("em");
428
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
428
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
429
429
  expect(match[1]).toEqual(state.previousSibling());
430
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
430
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
431
431
  expect(match[2].type).toEqual("text");
432
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
432
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
433
433
  expect(match[2]).toEqual(n);
434
434
  matchedText += content;
435
435
  numMatches++;
@@ -452,7 +452,7 @@ C
452
452
  if (match !== null) {
453
453
  expect(Array.isArray(match)).toBeTruthy();
454
454
  expect(match).toHaveLength(1);
455
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
455
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
456
456
  expect(match[0]).toEqual(n);
457
457
  expect(
458
458
  n.type === "paragraph" || n.type === "list",
@@ -479,11 +479,11 @@ C
479
479
  expect(Array.isArray(match)).toBeTruthy();
480
480
  if (n.type === "heading") {
481
481
  expect(match).toHaveLength(1);
482
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
482
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
483
483
  expect(match[0]).toEqual(n);
484
484
  } else {
485
485
  expect(match).toHaveLength(2);
486
- // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
486
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
487
487
  expect(match[1]).toEqual(n);
488
488
  expect(n.type).toEqual("text");
489
489
  }