@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.
- package/CHANGELOG.md +14 -0
- package/dist/es/index.js +420 -240
- 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 +3 -3
- 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.tsbuildinfo → tsconfig-build.tsbuildinfo} +1 -1
- 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/dist/index.js
CHANGED
|
@@ -600,7 +600,7 @@ class Rule {
|
|
|
600
600
|
const lastSlash = pattern.lastIndexOf("/");
|
|
601
601
|
const expression = pattern.substring(1, lastSlash);
|
|
602
602
|
const flags = pattern.substring(lastSlash + 1);
|
|
603
|
-
// @ts-expect-error
|
|
603
|
+
// @ts-expect-error - TS2713 - Cannot access 'RegExp.flags' because 'RegExp' is a type, but not a namespace. Did you mean to retrieve the type of the property 'flags' in 'RegExp' with 'RegExp["flags"]'?
|
|
604
604
|
return new RegExp(expression, flags);
|
|
605
605
|
}
|
|
606
606
|
return new RegExp(pattern);
|
|
@@ -1124,11 +1124,9 @@ class TreeTransformer {
|
|
|
1124
1124
|
// Record the node's text content if it has any.
|
|
1125
1125
|
// Usually this is for nodes with a type property of "text",
|
|
1126
1126
|
// but other nodes types like "math" may also have content.
|
|
1127
|
-
//
|
|
1128
|
-
// "node.content (property `content` is missing in `TreeNode` [1].)"
|
|
1129
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'content' does not exist on type 'TreeNode'.
|
|
1127
|
+
// @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
|
|
1130
1128
|
if (typeof node.content === "string") {
|
|
1131
|
-
// @ts-expect-error
|
|
1129
|
+
// @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
|
|
1132
1130
|
content = node.content;
|
|
1133
1131
|
}
|
|
1134
1132
|
|
|
@@ -1193,7 +1191,7 @@ class TreeTransformer {
|
|
|
1193
1191
|
while (index < nodes.length) {
|
|
1194
1192
|
state._indexes.push(index);
|
|
1195
1193
|
content += this._traverse(nodes[index], state, f);
|
|
1196
|
-
// Casting to convince
|
|
1194
|
+
// Casting to convince TypeScript that this is a number
|
|
1197
1195
|
index = state._indexes.pop() + 1;
|
|
1198
1196
|
}
|
|
1199
1197
|
|
|
@@ -1220,7 +1218,7 @@ class TreeTransformer {
|
|
|
1220
1218
|
* for that traversal, and the instance is passed to the traversal callback
|
|
1221
1219
|
* function for each node that is traversed. This class is not intended to be
|
|
1222
1220
|
* instantiated directly, but is exported so that its type can be used for
|
|
1223
|
-
*
|
|
1221
|
+
* type annotaions.
|
|
1224
1222
|
**/
|
|
1225
1223
|
class TraversalState {
|
|
1226
1224
|
// The root node of the tree being traversed
|
|
@@ -1229,8 +1227,8 @@ class TraversalState {
|
|
|
1229
1227
|
// below instead of using these properties directly. Note that the
|
|
1230
1228
|
// _containers and _indexes stacks can have two different types of
|
|
1231
1229
|
// elements, depending on whether we just recursed on an array or on a
|
|
1232
|
-
// node. This is hard for
|
|
1233
|
-
//
|
|
1230
|
+
// node. This is hard for TypeScript to deal with, so you'll see a number of
|
|
1231
|
+
// type casts through the any type when working with these two properties.
|
|
1234
1232
|
|
|
1235
1233
|
// The constructor just stores the root node and creates empty stacks.
|
|
1236
1234
|
constructor(root) {
|
|
@@ -1369,7 +1367,7 @@ class TraversalState {
|
|
|
1369
1367
|
|
|
1370
1368
|
// The top of the container stack is either an array or an object
|
|
1371
1369
|
// and the top of the indexes stack is a corresponding array index
|
|
1372
|
-
// or object property. This is hard for
|
|
1370
|
+
// or object property. This is hard for TypeScript, so we have to do some
|
|
1373
1371
|
// unsafe casting and be careful when we use which cast version
|
|
1374
1372
|
for (var _len = arguments.length, replacements = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1375
1373
|
replacements[_key] = arguments[_key];
|
|
@@ -1422,7 +1420,7 @@ class TraversalState {
|
|
|
1422
1420
|
this._currentNode = this.previousSibling();
|
|
1423
1421
|
// Since we know that we have a previous sibling, we know that
|
|
1424
1422
|
// the value on top of the stack is a number, but we have to do
|
|
1425
|
-
// this unsafe cast because
|
|
1423
|
+
// this unsafe cast because TypeScript doesn't know that.
|
|
1426
1424
|
const index = this._indexes.pop();
|
|
1427
1425
|
this._indexes.push(index - 1);
|
|
1428
1426
|
}
|
|
@@ -1455,10 +1453,7 @@ class TraversalState {
|
|
|
1455
1453
|
// and more as needed until we restore the invariant that
|
|
1456
1454
|
// this._containers.top()[this.indexes.top()] === this._currentNode
|
|
1457
1455
|
//
|
|
1458
|
-
while (this._containers.size() &&
|
|
1459
|
-
// This is safe, but easier to just disable flow than do casts
|
|
1460
|
-
// $FlowFixMe[incompatible-use]
|
|
1461
|
-
this._containers.top()[this._indexes.top()] !== this._currentNode) {
|
|
1456
|
+
while (this._containers.size() && this._containers.top()[this._indexes.top()] !== this._currentNode) {
|
|
1462
1457
|
this._containers.pop();
|
|
1463
1458
|
this._indexes.pop();
|
|
1464
1459
|
}
|
|
@@ -1509,7 +1504,7 @@ class Stack {
|
|
|
1509
1504
|
|
|
1510
1505
|
/** Pop a value off of the stack. */
|
|
1511
1506
|
pop() {
|
|
1512
|
-
// @ts-expect-error
|
|
1507
|
+
// @ts-expect-error - TS2322 - Type 'T | undefined' is not assignable to type 'T'.
|
|
1513
1508
|
return this.stack.pop();
|
|
1514
1509
|
}
|
|
1515
1510
|
|
|
@@ -1606,7 +1601,7 @@ function runLinter(tree, context, highlight) {
|
|
|
1606
1601
|
if (TreeTransformer.isTextNode(node)) {
|
|
1607
1602
|
let next = state.nextSibling();
|
|
1608
1603
|
while (TreeTransformer.isTextNode(next)) {
|
|
1609
|
-
// @ts-expect-error
|
|
1604
|
+
// @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'.
|
|
1610
1605
|
node.content += next.content;
|
|
1611
1606
|
state.removeNextSibling();
|
|
1612
1607
|
next = state.nextSibling();
|
|
@@ -1708,7 +1703,7 @@ function runLinter(tree, context, highlight) {
|
|
|
1708
1703
|
// this node, then we need to save the warnings for display
|
|
1709
1704
|
// on the table itself
|
|
1710
1705
|
if (insideTable && nodeWarnings.length) {
|
|
1711
|
-
// @ts-expect-error
|
|
1706
|
+
// @ts-expect-error - TS2345 - Argument of type 'any' is not assignable to parameter of type 'never'.
|
|
1712
1707
|
tableWarnings.push(...nodeWarnings);
|
|
1713
1708
|
}
|
|
1714
1709
|
|
|
@@ -1735,7 +1730,7 @@ function runLinter(tree, context, highlight) {
|
|
|
1735
1730
|
// node under a new lint node and put the warnings there.
|
|
1736
1731
|
state.replace({
|
|
1737
1732
|
type: "lint",
|
|
1738
|
-
// @ts-expect-error
|
|
1733
|
+
// @ts-expect-error - TS2345 - Argument of type '{ type: string; content: TreeNode; message: string; ruleName: any; blockHighlight: any; insideTable: boolean; severity: any; }' is not assignable to parameter of type 'TreeNode'.
|
|
1739
1734
|
content: node,
|
|
1740
1735
|
message: nodeWarnings.map(w => w.message).join("\n\n"),
|
|
1741
1736
|
ruleName: nodeWarnings[0].rule,
|
|
@@ -1769,7 +1764,7 @@ function runLinter(tree, context, highlight) {
|
|
|
1769
1764
|
// single line, so keeping them combined in that case might
|
|
1770
1765
|
// be the best thing, anyway.
|
|
1771
1766
|
//
|
|
1772
|
-
// @ts-expect-error
|
|
1767
|
+
// @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
|
|
1773
1768
|
const content = node.content; // Text nodes have content
|
|
1774
1769
|
const warning = nodeWarnings[0]; // There is only one warning.
|
|
1775
1770
|
// These are the lint boundaries within the content
|