@khanacademy/perseus-linter 0.3.12 → 1.0.0

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/dist/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var perseusError = require('@khanacademy/perseus-error');
6
5
  var perseusCore = require('@khanacademy/perseus-core');
7
6
  var PropTypes = require('prop-types');
8
7
 
@@ -29,7 +28,7 @@ class Selector {
29
28
  * subclasses must provide an implementation of this method.
30
29
  */
31
30
  match(state) {
32
- throw new perseusError.PerseusError("Selector subclasses must implement match()", perseusError.Errors.NotAllowed);
31
+ throw new perseusCore.PerseusError("Selector subclasses must implement match()", perseusCore.Errors.NotAllowed);
33
32
  }
34
33
 
35
34
  /**
@@ -51,9 +50,9 @@ class Selector {
51
50
  * Instead call the static Selector.parse() method.
52
51
  */
53
52
  class Parser {
54
- // We do lexing with a simple regular expression
55
- // The array of tokens
56
- // Which token in the array we're looking at now
53
+ static TOKENS; // We do lexing with a simple regular expression
54
+ tokens; // The array of tokens
55
+ tokenIndex; // Which token in the array we're looking at now
57
56
 
58
57
  constructor(s) {
59
58
  // Normalize whitespace:
@@ -212,6 +211,7 @@ class ParseError extends Error {
212
211
  * first.
213
212
  */
214
213
  class SelectorList extends Selector {
214
+ selectors;
215
215
  constructor(selectors) {
216
216
  super();
217
217
  this.selectors = selectors;
@@ -254,6 +254,7 @@ class AnyNode extends Selector {
254
254
  * it matches any node whose `type` property is a specified string
255
255
  */
256
256
  class TypeSelector extends Selector {
257
+ type;
257
258
  constructor(type) {
258
259
  super();
259
260
  this.type = type;
@@ -277,6 +278,8 @@ class TypeSelector extends Selector {
277
278
  * method.
278
279
  */
279
280
  class SelectorCombinator extends Selector {
281
+ left;
282
+ right;
280
283
  constructor(left, right) {
281
284
  super();
282
285
  this.left = left;
@@ -543,20 +546,21 @@ class SiblingCombinator extends SelectorCombinator {
543
546
  * this file for detailed description.
544
547
  */
545
548
  class Rule {
546
- // The name of the rule
547
- // The severity of the rule
548
- // The specified selector or the DEFAULT_SELECTOR
549
- // A regular expression if one was specified
550
- // The lint-testing function or a default
551
- // Checks to see if we should apply a rule or not
552
- // The error message for use with the default function
549
+ name; // The name of the rule
550
+ severity; // The severity of the rule
551
+ selector; // The specified selector or the DEFAULT_SELECTOR
552
+ pattern; // A regular expression if one was specified
553
+ lint; // The lint-testing function or a default
554
+ applies; // Checks to see if we should apply a rule or not
555
+ message; // The error message for use with the default function
556
+ static DEFAULT_SELECTOR;
553
557
 
554
558
  // The comment at the top of this file has detailed docs for
555
559
  // this constructor and its arguments
556
560
  constructor(name, severity, selector, pattern, lint, applies) {
557
561
  var _this = this;
558
562
  if (!selector && !pattern) {
559
- throw new perseusError.PerseusError("Lint rules must have a selector or pattern", perseusError.Errors.InvalidInput, {
563
+ throw new perseusCore.PerseusError("Lint rules must have a selector or pattern", perseusCore.Errors.InvalidInput, {
560
564
  metadata: {
561
565
  name
562
566
  }
@@ -1154,14 +1158,6 @@ nested lists are hard to read on mobile devices;
1154
1158
  do not use additional indentation.`
1155
1159
  });
1156
1160
 
1157
- var Profanity = Rule.makeRule({
1158
- name: "profanity",
1159
- // This list could obviously be expanded a lot, but I figured we
1160
- // could start with https://en.wikipedia.org/wiki/Seven_dirty_words
1161
- pattern: /\b(shit|piss|fuck|cunt|cocksucker|motherfucker|tits)\b/i,
1162
- message: "Avoid profanity"
1163
- });
1164
-
1165
1161
  var TableMissingCells = Rule.makeRule({
1166
1162
  name: "table-missing-cells",
1167
1163
  severity: Rule.Severity.WARNING,
@@ -1209,7 +1205,7 @@ do not put widgets inside of tables.`
1209
1205
  });
1210
1206
 
1211
1207
  // TODO(davidflanagan):
1212
- var AllRules = [AbsoluteUrl, BlockquotedMath, BlockquotedWidget, DoubleSpacingAfterTerminal, ExtraContentSpacing, HeadingLevel1, HeadingLevelSkip, HeadingSentenceCase, HeadingTitleCase, ImageAltText, ImageInTable, LinkClickHere, LongParagraph, MathAdjacent, MathAlignExtraBreak, MathAlignLinebreaks, MathEmpty, MathFontSize, MathFrac, MathNested, MathStartsWithSpace, MathTextEmpty, NestedLists, TableMissingCells, UnescapedDollar, WidgetInTable, Profanity, MathWithoutDollars, UnbalancedCodeDelimiters, ImageSpacesAroundUrls, ImageWidget];
1208
+ var AllRules = [AbsoluteUrl, BlockquotedMath, BlockquotedWidget, DoubleSpacingAfterTerminal, ExtraContentSpacing, HeadingLevel1, HeadingLevelSkip, HeadingSentenceCase, HeadingTitleCase, ImageAltText, ImageInTable, LinkClickHere, LongParagraph, MathAdjacent, MathAlignExtraBreak, MathAlignLinebreaks, MathEmpty, MathFontSize, MathFrac, MathNested, MathStartsWithSpace, MathTextEmpty, NestedLists, TableMissingCells, UnescapedDollar, WidgetInTable, MathWithoutDollars, UnbalancedCodeDelimiters, ImageSpacesAroundUrls, ImageWidget];
1213
1209
 
1214
1210
  /**
1215
1211
  * TreeTransformer is a class for traversing and transforming trees. Create a
@@ -1277,6 +1273,8 @@ var AllRules = [AbsoluteUrl, BlockquotedMath, BlockquotedWidget, DoubleSpacingAf
1277
1273
  // This is the TreeTransformer class described in detail at the
1278
1274
  // top of this file.
1279
1275
  class TreeTransformer {
1276
+ root;
1277
+
1280
1278
  // To create a tree transformer, just pass the root node of the tree
1281
1279
  constructor(root) {
1282
1280
  this.root = root;
@@ -1424,6 +1422,7 @@ class TreeTransformer {
1424
1422
  **/
1425
1423
  class TraversalState {
1426
1424
  // The root node of the tree being traversed
1425
+ root;
1427
1426
 
1428
1427
  // These are internal state properties. Use the accessor methods defined
1429
1428
  // below instead of using these properties directly. Note that the
@@ -1431,6 +1430,11 @@ class TraversalState {
1431
1430
  // elements, depending on whether we just recursed on an array or on a
1432
1431
  // node. This is hard for TypeScript to deal with, so you'll see a number of
1433
1432
  // type casts through the any type when working with these two properties.
1433
+ _currentNode;
1434
+ _containers;
1435
+ _indexes;
1436
+ _ancestors;
1437
+
1434
1438
  // The constructor just stores the root node and creates empty stacks.
1435
1439
  constructor(root) {
1436
1440
  this.root = root;
@@ -1558,7 +1562,7 @@ class TraversalState {
1558
1562
  replace() {
1559
1563
  const parent = this._containers.top();
1560
1564
  if (!parent) {
1561
- throw new perseusError.PerseusError("Can't replace the root of the tree", perseusError.Errors.Internal);
1565
+ throw new perseusCore.PerseusError("Can't replace the root of the tree", perseusCore.Errors.Internal);
1562
1566
  }
1563
1567
 
1564
1568
  // The top of the container stack is either an array or an object
@@ -1611,7 +1615,7 @@ class TraversalState {
1611
1615
  */
1612
1616
  goToPreviousSibling() {
1613
1617
  if (!this.hasPreviousSibling()) {
1614
- throw new perseusError.PerseusError("goToPreviousSibling(): node has no previous sibling", perseusError.Errors.Internal);
1618
+ throw new perseusCore.PerseusError("goToPreviousSibling(): node has no previous sibling", perseusCore.Errors.Internal);
1615
1619
  }
1616
1620
  this._currentNode = this.previousSibling();
1617
1621
  // Since we know that we have a previous sibling, we know that
@@ -1641,7 +1645,7 @@ class TraversalState {
1641
1645
  */
1642
1646
  goToParent() {
1643
1647
  if (!this.hasParent()) {
1644
- throw new perseusError.PerseusError("goToParent(): node has no ancestor", perseusError.Errors.NotAllowed);
1648
+ throw new perseusCore.PerseusError("goToParent(): node has no ancestor", perseusCore.Errors.NotAllowed);
1645
1649
  }
1646
1650
  this._currentNode = this._ancestors.pop();
1647
1651
 
@@ -1688,6 +1692,7 @@ class TraversalState {
1688
1692
  * the TraversalState class simpler in a number of places.
1689
1693
  */
1690
1694
  class Stack {
1695
+ stack;
1691
1696
  constructor(array) {
1692
1697
  this.stack = array ? array.slice(0) : [];
1693
1698
  }
@@ -1747,7 +1752,7 @@ class Stack {
1747
1752
 
1748
1753
  // This file is processed by a Rollup plugin (replace) to inject the production
1749
1754
  const libName = "@khanacademy/perseus-linter";
1750
- const libVersion = "0.3.12";
1755
+ const libVersion = "1.0.0";
1751
1756
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
1752
1757
 
1753
1758
  // Define the shape of the linter context object that is passed through the