@khanacademy/perseus-linter 0.4.0 → 1.1.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
|
|
31
|
+
throw new perseusCore.PerseusError("Selector subclasses must implement match()", perseusCore.Errors.NotAllowed);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/**
|
|
@@ -561,7 +560,7 @@ class Rule {
|
|
|
561
560
|
constructor(name, severity, selector, pattern, lint, applies) {
|
|
562
561
|
var _this = this;
|
|
563
562
|
if (!selector && !pattern) {
|
|
564
|
-
throw new
|
|
563
|
+
throw new perseusCore.PerseusError("Lint rules must have a selector or pattern", perseusCore.Errors.InvalidInput, {
|
|
565
564
|
metadata: {
|
|
566
565
|
name
|
|
567
566
|
}
|
|
@@ -1159,12 +1158,25 @@ nested lists are hard to read on mobile devices;
|
|
|
1159
1158
|
do not use additional indentation.`
|
|
1160
1159
|
});
|
|
1161
1160
|
|
|
1162
|
-
var
|
|
1163
|
-
name: "
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1161
|
+
var StaticWidgetInQuestionStem = Rule.makeRule({
|
|
1162
|
+
name: "static-widget-in-question-stem",
|
|
1163
|
+
severity: Rule.Severity.WARNING,
|
|
1164
|
+
selector: "widget",
|
|
1165
|
+
lint: (state, content, nodes, match, context) => {
|
|
1166
|
+
if (context.contentType !== "exercise") {
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (context.stack.includes("hint")) {
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
const widget = context?.widgets?.[state.currentNode().id];
|
|
1173
|
+
if (!widget) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
if (widget.static) {
|
|
1177
|
+
return `Widget in question stem is static (non-interactive).`;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1168
1180
|
});
|
|
1169
1181
|
|
|
1170
1182
|
var TableMissingCells = Rule.makeRule({
|
|
@@ -1214,7 +1226,7 @@ do not put widgets inside of tables.`
|
|
|
1214
1226
|
});
|
|
1215
1227
|
|
|
1216
1228
|
// TODO(davidflanagan):
|
|
1217
|
-
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,
|
|
1229
|
+
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, StaticWidgetInQuestionStem, TableMissingCells, UnescapedDollar, WidgetInTable, MathWithoutDollars, UnbalancedCodeDelimiters, ImageSpacesAroundUrls, ImageWidget];
|
|
1218
1230
|
|
|
1219
1231
|
/**
|
|
1220
1232
|
* TreeTransformer is a class for traversing and transforming trees. Create a
|
|
@@ -1571,7 +1583,7 @@ class TraversalState {
|
|
|
1571
1583
|
replace() {
|
|
1572
1584
|
const parent = this._containers.top();
|
|
1573
1585
|
if (!parent) {
|
|
1574
|
-
throw new
|
|
1586
|
+
throw new perseusCore.PerseusError("Can't replace the root of the tree", perseusCore.Errors.Internal);
|
|
1575
1587
|
}
|
|
1576
1588
|
|
|
1577
1589
|
// The top of the container stack is either an array or an object
|
|
@@ -1624,7 +1636,7 @@ class TraversalState {
|
|
|
1624
1636
|
*/
|
|
1625
1637
|
goToPreviousSibling() {
|
|
1626
1638
|
if (!this.hasPreviousSibling()) {
|
|
1627
|
-
throw new
|
|
1639
|
+
throw new perseusCore.PerseusError("goToPreviousSibling(): node has no previous sibling", perseusCore.Errors.Internal);
|
|
1628
1640
|
}
|
|
1629
1641
|
this._currentNode = this.previousSibling();
|
|
1630
1642
|
// Since we know that we have a previous sibling, we know that
|
|
@@ -1654,7 +1666,7 @@ class TraversalState {
|
|
|
1654
1666
|
*/
|
|
1655
1667
|
goToParent() {
|
|
1656
1668
|
if (!this.hasParent()) {
|
|
1657
|
-
throw new
|
|
1669
|
+
throw new perseusCore.PerseusError("goToParent(): node has no ancestor", perseusCore.Errors.NotAllowed);
|
|
1658
1670
|
}
|
|
1659
1671
|
this._currentNode = this._ancestors.pop();
|
|
1660
1672
|
|
|
@@ -1761,7 +1773,7 @@ class Stack {
|
|
|
1761
1773
|
|
|
1762
1774
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
1763
1775
|
const libName = "@khanacademy/perseus-linter";
|
|
1764
|
-
const libVersion = "
|
|
1776
|
+
const libVersion = "1.1.0";
|
|
1765
1777
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
1766
1778
|
|
|
1767
1779
|
// Define the shape of the linter context object that is passed through the
|