@khanacademy/perseus-linter 0.3.1 → 0.3.3
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/CHANGELOG.md +13 -0
- package/dist/es/index.js +15 -20
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +15 -20
- package/dist/index.js.map +1 -1
- package/dist/tree-transformer.d.ts +1 -1
- package/package.json +5 -4
- package/src/__tests__/matcher.test.ts +57 -57
- package/src/__tests__/rules.test.ts +62 -62
- package/src/__tests__/tree-transformer.test.ts +5 -5
- package/src/index.ts +4 -4
- package/src/rule.ts +2 -2
- package/src/tree-transformer.ts +9 -13
- package/tsconfig-build.json +11 -0
- package/tsconfig-build.tsbuildinfo +1 -0
- package/dist/index.js.flow +0 -18
- package/dist/proptypes.js.flow +0 -17
- package/dist/rule.js.flow +0 -86
- package/dist/rules/absolute-url.js.flow +0 -9
- package/dist/rules/all-rules.js.flow +0 -9
- package/dist/rules/blockquoted-math.js.flow +0 -9
- package/dist/rules/blockquoted-widget.js.flow +0 -9
- package/dist/rules/double-spacing-after-terminal.js.flow +0 -9
- package/dist/rules/extra-content-spacing.js.flow +0 -9
- package/dist/rules/heading-level-1.js.flow +0 -9
- package/dist/rules/heading-level-skip.js.flow +0 -9
- package/dist/rules/heading-sentence-case.js.flow +0 -9
- package/dist/rules/heading-title-case.js.flow +0 -9
- package/dist/rules/image-alt-text.js.flow +0 -9
- package/dist/rules/image-in-table.js.flow +0 -9
- package/dist/rules/image-spaces-around-urls.js.flow +0 -9
- package/dist/rules/image-widget.js.flow +0 -9
- package/dist/rules/link-click-here.js.flow +0 -9
- package/dist/rules/lint-utils.js.flow +0 -8
- package/dist/rules/long-paragraph.js.flow +0 -9
- package/dist/rules/math-adjacent.js.flow +0 -9
- package/dist/rules/math-align-extra-break.js.flow +0 -9
- package/dist/rules/math-align-linebreaks.js.flow +0 -9
- package/dist/rules/math-empty.js.flow +0 -9
- package/dist/rules/math-font-size.js.flow +0 -9
- package/dist/rules/math-frac.js.flow +0 -9
- package/dist/rules/math-nested.js.flow +0 -9
- package/dist/rules/math-starts-with-space.js.flow +0 -9
- package/dist/rules/math-text-empty.js.flow +0 -9
- package/dist/rules/math-without-dollars.js.flow +0 -9
- package/dist/rules/nested-lists.js.flow +0 -9
- package/dist/rules/profanity.js.flow +0 -9
- package/dist/rules/table-missing-cells.js.flow +0 -9
- package/dist/rules/unbalanced-code-delimiters.js.flow +0 -9
- package/dist/rules/unescaped-dollar.js.flow +0 -9
- package/dist/rules/widget-in-table.js.flow +0 -9
- package/dist/selector.js.flow +0 -31
- package/dist/tree-transformer.js.flow +0 -253
- package/dist/types.js.flow +0 -12
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -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
|
-
*
|
|
76
|
+
* type annotaions.
|
|
77
77
|
**/
|
|
78
78
|
export declare class TraversalState {
|
|
79
79
|
root: TreeNode;
|
package/package.json
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
"description": "Linter engine for Perseus",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.3",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/Khan/perseus.git"
|
|
12
|
+
"url": "https://github.com/Khan/perseus.git",
|
|
13
|
+
"directory": "packages/perseus-linter"
|
|
13
14
|
},
|
|
14
15
|
"bugs": {
|
|
15
16
|
"url": "https://github.com/Khan/perseus/issues"
|
|
@@ -21,10 +22,10 @@
|
|
|
21
22
|
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@khanacademy/perseus-error": "^0.2.
|
|
25
|
+
"@khanacademy/perseus-error": "^0.2.2"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@khanacademy/pure-markdown": "^0.2.
|
|
28
|
+
"@khanacademy/pure-markdown": "^0.2.5",
|
|
28
29
|
"prop-types": "^15.6.1"
|
|
29
30
|
},
|
|
30
31
|
"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
|
|
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
|
|
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
|
|
89
|
+
// @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
|
|
90
90
|
expect(match[0]).toEqual(parent);
|
|
91
|
-
// @ts-expect-error
|
|
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
|
|
119
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
120
120
|
parent.type === "em" &&
|
|
121
|
-
// @ts-expect-error
|
|
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
|
|
126
|
+
// @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
|
|
127
127
|
expect(match[0]).toEqual(grandparent);
|
|
128
|
-
// @ts-expect-error
|
|
128
|
+
// @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'.
|
|
129
129
|
expect(match[1]).toEqual(parent);
|
|
130
|
-
// @ts-expect-error
|
|
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
|
|
155
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
156
156
|
expect(match[0].type).toEqual("paragraph");
|
|
157
|
-
// @ts-expect-error
|
|
157
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
158
158
|
expect(match[1].type).toEqual("text");
|
|
159
|
-
// @ts-expect-error
|
|
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
|
|
182
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
183
183
|
expect(match[0].type).toEqual("paragraph");
|
|
184
|
-
// @ts-expect-error
|
|
184
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
185
185
|
expect(match[1].type).toEqual("em");
|
|
186
|
-
// @ts-expect-error
|
|
186
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
187
187
|
expect(match[2].type).toEqual("text");
|
|
188
|
-
// @ts-expect-error
|
|
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
|
|
211
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
212
212
|
expect(match[0].type).toEqual("heading");
|
|
213
|
-
// @ts-expect-error
|
|
213
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
214
214
|
expect(match[0]).toEqual(state.previousSibling());
|
|
215
|
-
// @ts-expect-error
|
|
215
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
216
216
|
expect(match[1].type).toEqual("paragraph");
|
|
217
|
-
// @ts-expect-error
|
|
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
|
|
240
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
241
241
|
expect(match[0].type).toEqual("heading");
|
|
242
|
-
// @ts-expect-error
|
|
242
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
243
243
|
expect(match[1].type).toEqual("paragraph");
|
|
244
|
-
// @ts-expect-error
|
|
244
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
245
245
|
expect(match[1]).toEqual(state.previousSibling());
|
|
246
|
-
// @ts-expect-error
|
|
246
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
247
247
|
expect(match[2].type).toEqual("paragraph");
|
|
248
|
-
// @ts-expect-error
|
|
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
|
|
271
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
272
272
|
expect(match[0].type).toEqual("heading");
|
|
273
|
-
// @ts-expect-error
|
|
273
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
274
274
|
expect(match[1].type).toEqual("paragraph");
|
|
275
|
-
// @ts-expect-error
|
|
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
|
|
298
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
299
299
|
expect(match[0].type).toEqual("heading");
|
|
300
|
-
// @ts-expect-error
|
|
300
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
301
301
|
expect(match[1].type).toEqual("paragraph");
|
|
302
|
-
// @ts-expect-error
|
|
302
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
303
303
|
expect(match[2].type).toEqual("paragraph");
|
|
304
|
-
// @ts-expect-error
|
|
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
|
|
327
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
328
328
|
expect(match[0].type).toEqual("list");
|
|
329
|
-
// @ts-expect-error
|
|
329
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
330
330
|
expect(match[1].type).toEqual("paragraph");
|
|
331
|
-
// @ts-expect-error
|
|
331
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
332
332
|
expect(match[1]).toEqual(state.parent());
|
|
333
|
-
// @ts-expect-error
|
|
333
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
334
334
|
expect(match[2].type).toEqual("em");
|
|
335
|
-
// @ts-expect-error
|
|
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
|
|
358
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
359
359
|
expect(match[0].type).toEqual("list");
|
|
360
|
-
// @ts-expect-error
|
|
360
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
361
361
|
expect(match[1].type).toEqual("paragraph");
|
|
362
|
-
// @ts-expect-error
|
|
362
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
363
363
|
expect(match[1]).toEqual(state.parent());
|
|
364
|
-
// @ts-expect-error
|
|
364
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
365
365
|
expect(match[2].type).toEqual("em");
|
|
366
|
-
// @ts-expect-error
|
|
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
|
|
389
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
390
390
|
expect(match[0].type).toEqual("paragraph");
|
|
391
|
-
// @ts-expect-error
|
|
391
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
392
392
|
expect(match[0]).toEqual(state.parent());
|
|
393
|
-
// @ts-expect-error
|
|
393
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
394
394
|
expect(match[1].type).toEqual("em");
|
|
395
|
-
// @ts-expect-error
|
|
395
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
396
396
|
expect(match[1]).toEqual(state.previousSibling());
|
|
397
|
-
// @ts-expect-error
|
|
397
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
398
398
|
expect(match[2].type).toEqual("text");
|
|
399
|
-
// @ts-expect-error
|
|
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
|
|
422
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
423
423
|
expect(match[0].type).toEqual("paragraph");
|
|
424
|
-
// @ts-expect-error
|
|
424
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
425
425
|
expect(match[0]).toEqual(state.parent());
|
|
426
|
-
// @ts-expect-error
|
|
426
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
427
427
|
expect(match[1].type).toEqual("em");
|
|
428
|
-
// @ts-expect-error
|
|
428
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
429
429
|
expect(match[1]).toEqual(state.previousSibling());
|
|
430
|
-
// @ts-expect-error
|
|
430
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
431
431
|
expect(match[2].type).toEqual("text");
|
|
432
|
-
// @ts-expect-error
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|