@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/es/index.js +15 -20
  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 +5 -4
  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-build.tsbuildinfo +1 -0
  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
  56. package/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @khanacademy/perseus-linter
2
2
 
3
+ ## 0.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a383823d]
8
+ - @khanacademy/perseus-error@0.2.2
9
+
10
+ ## 0.3.2
11
+
12
+ ### Patch Changes
13
+
14
+ - ce5e6297: Upgrade wonder-blocks deps to package versions without Flow types
15
+
3
16
  ## 0.3.1
4
17
 
5
18
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -703,7 +703,7 @@ ${e.stack}`,
703
703
  const lastSlash = pattern.lastIndexOf("/");
704
704
  const expression = pattern.substring(1, lastSlash);
705
705
  const flags = pattern.substring(lastSlash + 1);
706
- // @ts-expect-error [FEI-5003] - 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"]'?
706
+ // @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"]'?
707
707
  return new RegExp(expression, flags);
708
708
  }
709
709
  return new RegExp(pattern);
@@ -1326,11 +1326,9 @@ class TreeTransformer {
1326
1326
  // Record the node's text content if it has any.
1327
1327
  // Usually this is for nodes with a type property of "text",
1328
1328
  // but other nodes types like "math" may also have content.
1329
- // TODO(mdr): We found a new Flow error when upgrading:
1330
- // "node.content (property `content` is missing in `TreeNode` [1].)"
1331
- // @ts-expect-error [FEI-5003] - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1329
+ // @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1332
1330
  if (typeof node.content === "string") {
1333
- // @ts-expect-error [FEI-5003] - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1331
+ // @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1334
1332
  content = node.content;
1335
1333
  }
1336
1334
 
@@ -1395,7 +1393,7 @@ class TreeTransformer {
1395
1393
  while (index < nodes.length) {
1396
1394
  state._indexes.push(index);
1397
1395
  content += this._traverse(nodes[index], state, f);
1398
- // Casting to convince Flow that this is a number
1396
+ // Casting to convince TypeScript that this is a number
1399
1397
  index = state._indexes.pop() + 1;
1400
1398
  }
1401
1399
 
@@ -1422,7 +1420,7 @@ class TreeTransformer {
1422
1420
  * for that traversal, and the instance is passed to the traversal callback
1423
1421
  * function for each node that is traversed. This class is not intended to be
1424
1422
  * instantiated directly, but is exported so that its type can be used for
1425
- * Flow annotaions.
1423
+ * type annotaions.
1426
1424
  **/
1427
1425
  class TraversalState {
1428
1426
  // The root node of the tree being traversed
@@ -1431,8 +1429,8 @@ class TraversalState {
1431
1429
  // below instead of using these properties directly. Note that the
1432
1430
  // _containers and _indexes stacks can have two different types of
1433
1431
  // elements, depending on whether we just recursed on an array or on a
1434
- // node. This is hard for Flow to deal with, so you'll see a number of
1435
- // Flow casts through the any type when working with these two properties.
1432
+ // node. This is hard for TypeScript to deal with, so you'll see a number of
1433
+ // type casts through the any type when working with these two properties.
1436
1434
 
1437
1435
  // The constructor just stores the root node and creates empty stacks.
1438
1436
  constructor(root) {
@@ -1571,7 +1569,7 @@ class TraversalState {
1571
1569
 
1572
1570
  // The top of the container stack is either an array or an object
1573
1571
  // and the top of the indexes stack is a corresponding array index
1574
- // or object property. This is hard for Flow, so we have to do some
1572
+ // or object property. This is hard for TypeScript, so we have to do some
1575
1573
  // unsafe casting and be careful when we use which cast version
1576
1574
  if (Array.isArray(parent)) {
1577
1575
  const index = this._indexes.top();
@@ -1621,7 +1619,7 @@ class TraversalState {
1621
1619
  this._currentNode = this.previousSibling();
1622
1620
  // Since we know that we have a previous sibling, we know that
1623
1621
  // the value on top of the stack is a number, but we have to do
1624
- // this unsafe cast because Flow doesn't know that.
1622
+ // this unsafe cast because TypeScript doesn't know that.
1625
1623
  const index = this._indexes.pop();
1626
1624
  this._indexes.push(index - 1);
1627
1625
  }
@@ -1654,10 +1652,7 @@ class TraversalState {
1654
1652
  // and more as needed until we restore the invariant that
1655
1653
  // this._containers.top()[this.indexes.top()] === this._currentNode
1656
1654
  //
1657
- while (this._containers.size() &&
1658
- // This is safe, but easier to just disable flow than do casts
1659
- // $FlowFixMe[incompatible-use]
1660
- this._containers.top()[this._indexes.top()] !== this._currentNode) {
1655
+ while (this._containers.size() && this._containers.top()[this._indexes.top()] !== this._currentNode) {
1661
1656
  this._containers.pop();
1662
1657
  this._indexes.pop();
1663
1658
  }
@@ -1708,7 +1703,7 @@ class Stack {
1708
1703
 
1709
1704
  /** Pop a value off of the stack. */
1710
1705
  pop() {
1711
- // @ts-expect-error [FEI-5003] - TS2322 - Type 'T | undefined' is not assignable to type 'T'.
1706
+ // @ts-expect-error - TS2322 - Type 'T | undefined' is not assignable to type 'T'.
1712
1707
  return this.stack.pop();
1713
1708
  }
1714
1709
 
@@ -1804,7 +1799,7 @@ function runLinter(tree, context, highlight, rules = allLintRules) {
1804
1799
  if (TreeTransformer.isTextNode(node)) {
1805
1800
  let next = state.nextSibling();
1806
1801
  while (TreeTransformer.isTextNode(next)) {
1807
- // @ts-expect-error [FEI-5003] - 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'.
1802
+ // @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'.
1808
1803
  node.content += next.content;
1809
1804
  state.removeNextSibling();
1810
1805
  next = state.nextSibling();
@@ -1905,7 +1900,7 @@ function runLinter(tree, context, highlight, rules = allLintRules) {
1905
1900
  // this node, then we need to save the warnings for display
1906
1901
  // on the table itself
1907
1902
  if (insideTable && nodeWarnings.length) {
1908
- // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'any' is not assignable to parameter of type 'never'.
1903
+ // @ts-expect-error - TS2345 - Argument of type 'any' is not assignable to parameter of type 'never'.
1909
1904
  tableWarnings.push(...nodeWarnings);
1910
1905
  }
1911
1906
 
@@ -1932,7 +1927,7 @@ function runLinter(tree, context, highlight, rules = allLintRules) {
1932
1927
  // node under a new lint node and put the warnings there.
1933
1928
  state.replace({
1934
1929
  type: "lint",
1935
- // @ts-expect-error [FEI-5003] - 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'.
1930
+ // @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'.
1936
1931
  content: node,
1937
1932
  message: nodeWarnings.map(w => w.message).join("\n\n"),
1938
1933
  ruleName: nodeWarnings[0].rule,
@@ -1966,7 +1961,7 @@ function runLinter(tree, context, highlight, rules = allLintRules) {
1966
1961
  // single line, so keeping them combined in that case might
1967
1962
  // be the best thing, anyway.
1968
1963
  //
1969
- // @ts-expect-error [FEI-5003] - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1964
+ // @ts-expect-error - TS2339 - Property 'content' does not exist on type 'TreeNode'.
1970
1965
  const _content = node.content; // Text nodes have content
1971
1966
  const warning = nodeWarnings[0]; // There is only one warning.
1972
1967
  // These are the lint boundaries within the content