@khanacademy/perseus-linter 0.0.0-PR789-20231101163312 → 0.0.0-PR790-20231103191602
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 +3 -3
- package/dist/es/index.js +39 -20
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +283 -89
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @khanacademy/perseus-linter
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-PR790-20231103191602
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Updated dependencies [[`79403e06`](https://github.com/Khan/perseus/commit/79403e06eedb597d7818d6c858bbba6f51ff3fe1)]:
|
|
8
|
-
- @khanacademy/perseus-core@0.0.0-
|
|
9
|
-
- @khanacademy/perseus-error@0.0.0-
|
|
8
|
+
- @khanacademy/perseus-core@0.0.0-PR790-20231103191602
|
|
9
|
+
- @khanacademy/perseus-error@0.0.0-PR790-20231103191602
|
|
10
10
|
|
|
11
11
|
## 0.3.7
|
|
12
12
|
|
package/dist/es/index.js
CHANGED
|
@@ -61,12 +61,12 @@ class Selector {
|
|
|
61
61
|
* Instead call the static Selector.parse() method.
|
|
62
62
|
*/
|
|
63
63
|
class Parser {
|
|
64
|
-
// We do lexing with a simple regular expression
|
|
65
|
-
// The array of tokens
|
|
66
64
|
// Which token in the array we're looking at now
|
|
67
65
|
|
|
68
66
|
constructor(s) {
|
|
67
|
+
// We do lexing with a simple regular expression
|
|
69
68
|
this.tokens = void 0;
|
|
69
|
+
// The array of tokens
|
|
70
70
|
this.tokenIndex = void 0;
|
|
71
71
|
// Normalize whitespace:
|
|
72
72
|
// - remove leading and trailing whitespace
|
|
@@ -535,28 +535,46 @@ class SiblingCombinator extends SelectorCombinator {
|
|
|
535
535
|
* object associated with that content string in the JSON object that defines
|
|
536
536
|
* the Perseus article or exercise that is being linted.
|
|
537
537
|
*/
|
|
538
|
+
|
|
539
|
+
// This represents the type returned by String.match(). It is an
|
|
540
|
+
// array of strings, but also has index:number and input:string properties.
|
|
541
|
+
// TypeScript doesn't handle it well, so we punt and just use any.
|
|
542
|
+
// This is the return type of the check() method of a Rule object
|
|
543
|
+
// This is the return type of the lint detection function passed as the 4th
|
|
544
|
+
// argument to the Rule() constructor. It can return null or a string or an
|
|
545
|
+
// object containing a string and two numbers.
|
|
546
|
+
// prettier-ignore
|
|
547
|
+
// (prettier formats this in a way that ka-lint does not like)
|
|
548
|
+
// This is the type of the lint detection function that the Rule() constructor
|
|
549
|
+
// expects as its fourth argument. It is passed the TraversalState object and
|
|
550
|
+
// content string that were passed to check(), and is also passed the array of
|
|
551
|
+
// nodes returned by the selector match and the array of strings returned by
|
|
552
|
+
// the pattern match. It should return null if no lint is detected or an
|
|
553
|
+
// error message or an object contining an error message.
|
|
554
|
+
// An optional check to verify whether or not a particular rule should
|
|
555
|
+
// be checked by context. For example, some rules only apply in exercises,
|
|
556
|
+
// and should never be applied to articles. Defaults to true, so if we
|
|
557
|
+
// omit the applies function in a rule, it'll be tested everywhere.
|
|
538
558
|
/**
|
|
539
559
|
* A Rule object describes a Perseus lint rule. See the comment at the top of
|
|
540
560
|
* this file for detailed description.
|
|
541
561
|
*/
|
|
542
562
|
class Rule {
|
|
543
|
-
// The name of the rule
|
|
544
|
-
// The severity of the rule
|
|
545
|
-
// The specified selector or the DEFAULT_SELECTOR
|
|
546
|
-
// A regular expression if one was specified
|
|
547
|
-
// The lint-testing function or a default
|
|
548
|
-
// Checks to see if we should apply a rule or not
|
|
549
|
-
// The error message for use with the default function
|
|
550
|
-
|
|
551
563
|
// The comment at the top of this file has detailed docs for
|
|
552
564
|
// this constructor and its arguments
|
|
553
565
|
constructor(name, severity, selector, pattern, lint, applies) {
|
|
554
566
|
this.name = void 0;
|
|
567
|
+
// The name of the rule
|
|
555
568
|
this.severity = void 0;
|
|
569
|
+
// The severity of the rule
|
|
556
570
|
this.selector = void 0;
|
|
571
|
+
// The specified selector or the DEFAULT_SELECTOR
|
|
557
572
|
this.pattern = void 0;
|
|
573
|
+
// A regular expression if one was specified
|
|
558
574
|
this.lint = void 0;
|
|
575
|
+
// The lint-testing function or a default
|
|
559
576
|
this.applies = void 0;
|
|
577
|
+
// Checks to see if we should apply a rule or not
|
|
560
578
|
this.message = void 0;
|
|
561
579
|
if (!selector && !pattern) {
|
|
562
580
|
throw new PerseusError("Lint rules must have a selector or pattern", Errors.InvalidInput, {
|
|
@@ -721,6 +739,7 @@ ${e.stack}`,
|
|
|
721
739
|
return result;
|
|
722
740
|
}
|
|
723
741
|
}
|
|
742
|
+
// The error message for use with the default function
|
|
724
743
|
Rule.DEFAULT_SELECTOR = void 0;
|
|
725
744
|
Rule.Severity = {
|
|
726
745
|
ERROR: 1,
|
|
@@ -1273,7 +1292,9 @@ var AllRules = [AbsoluteUrl, BlockquotedMath, BlockquotedWidget, DoubleSpacingAf
|
|
|
1273
1292
|
|
|
1274
1293
|
// TreeNode is the type of a node in a parse tree. The only real requirement is
|
|
1275
1294
|
// that every node has a string-valued `type` property
|
|
1276
|
-
|
|
1295
|
+
// TraversalCallback is the type of the callback function passed to the
|
|
1296
|
+
// traverse() method. It is invoked with node, state, and content arguments
|
|
1297
|
+
// and is expected to return nothing.
|
|
1277
1298
|
// This is the TreeTransformer class described in detail at the
|
|
1278
1299
|
// top of this file.
|
|
1279
1300
|
class TreeTransformer {
|
|
@@ -1424,18 +1445,16 @@ class TreeTransformer {
|
|
|
1424
1445
|
* type annotaions.
|
|
1425
1446
|
**/
|
|
1426
1447
|
class TraversalState {
|
|
1427
|
-
// The root node of the tree being traversed
|
|
1428
|
-
|
|
1429
|
-
// These are internal state properties. Use the accessor methods defined
|
|
1430
|
-
// below instead of using these properties directly. Note that the
|
|
1431
|
-
// _containers and _indexes stacks can have two different types of
|
|
1432
|
-
// elements, depending on whether we just recursed on an array or on a
|
|
1433
|
-
// node. This is hard for TypeScript to deal with, so you'll see a number of
|
|
1434
|
-
// type casts through the any type when working with these two properties.
|
|
1435
|
-
|
|
1436
1448
|
// The constructor just stores the root node and creates empty stacks.
|
|
1437
1449
|
constructor(root) {
|
|
1450
|
+
// The root node of the tree being traversed
|
|
1438
1451
|
this.root = void 0;
|
|
1452
|
+
// These are internal state properties. Use the accessor methods defined
|
|
1453
|
+
// below instead of using these properties directly. Note that the
|
|
1454
|
+
// _containers and _indexes stacks can have two different types of
|
|
1455
|
+
// elements, depending on whether we just recursed on an array or on a
|
|
1456
|
+
// node. This is hard for TypeScript to deal with, so you'll see a number of
|
|
1457
|
+
// type casts through the any type when working with these two properties.
|
|
1439
1458
|
this._currentNode = void 0;
|
|
1440
1459
|
this._containers = void 0;
|
|
1441
1460
|
this._indexes = void 0;
|