@khanacademy/perseus-linter 0.3.8 → 0.3.10
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 +18 -0
- package/dist/es/index.js +41 -25
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +284 -90
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @khanacademy/perseus-linter
|
|
2
2
|
|
|
3
|
+
## 0.3.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`1f4e17ba`](https://github.com/Khan/perseus/commit/1f4e17ba77e1491523813655af18a70285a25989), [`8857950b`](https://github.com/Khan/perseus/commit/8857950bdeeb6e13bc3766b1c6545289b21cbe2a)]:
|
|
8
|
+
- @khanacademy/perseus-core@1.4.1
|
|
9
|
+
- @khanacademy/perseus-error@0.2.9
|
|
10
|
+
|
|
11
|
+
## 0.3.9
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#814](https://github.com/Khan/perseus/pull/814) [`105d2060`](https://github.com/Khan/perseus/commit/105d20603d935d35cff237b17f0bfb57ca751e4c) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Minor build change to how we provide Typescript type definitions (should be no change to build output).
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`a91c84fe`](https://github.com/Khan/perseus/commit/a91c84fe53827ff4333220777a9918882b7fe9f0), [`105d2060`](https://github.com/Khan/perseus/commit/105d20603d935d35cff237b17f0bfb57ca751e4c)]:
|
|
18
|
+
- @khanacademy/perseus-core@1.4.0
|
|
19
|
+
- @khanacademy/perseus-error@0.2.8
|
|
20
|
+
|
|
3
21
|
## 0.3.8
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -3,20 +3,17 @@ import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-core';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
|
|
5
5
|
function _extends() {
|
|
6
|
-
_extends = Object.assign
|
|
6
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
7
7
|
for (var i = 1; i < arguments.length; i++) {
|
|
8
8
|
var source = arguments[i];
|
|
9
|
-
|
|
10
9
|
for (var key in source) {
|
|
11
10
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
12
11
|
target[key] = source[key];
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
return target;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
return _extends.apply(this, arguments);
|
|
21
18
|
}
|
|
22
19
|
|
|
@@ -61,12 +58,12 @@ class Selector {
|
|
|
61
58
|
* Instead call the static Selector.parse() method.
|
|
62
59
|
*/
|
|
63
60
|
class Parser {
|
|
64
|
-
// We do lexing with a simple regular expression
|
|
65
|
-
// The array of tokens
|
|
66
61
|
// Which token in the array we're looking at now
|
|
67
62
|
|
|
68
63
|
constructor(s) {
|
|
64
|
+
// We do lexing with a simple regular expression
|
|
69
65
|
this.tokens = void 0;
|
|
66
|
+
// The array of tokens
|
|
70
67
|
this.tokenIndex = void 0;
|
|
71
68
|
// Normalize whitespace:
|
|
72
69
|
// - remove leading and trailing whitespace
|
|
@@ -535,28 +532,46 @@ class SiblingCombinator extends SelectorCombinator {
|
|
|
535
532
|
* object associated with that content string in the JSON object that defines
|
|
536
533
|
* the Perseus article or exercise that is being linted.
|
|
537
534
|
*/
|
|
535
|
+
|
|
536
|
+
// This represents the type returned by String.match(). It is an
|
|
537
|
+
// array of strings, but also has index:number and input:string properties.
|
|
538
|
+
// TypeScript doesn't handle it well, so we punt and just use any.
|
|
539
|
+
// This is the return type of the check() method of a Rule object
|
|
540
|
+
// This is the return type of the lint detection function passed as the 4th
|
|
541
|
+
// argument to the Rule() constructor. It can return null or a string or an
|
|
542
|
+
// object containing a string and two numbers.
|
|
543
|
+
// prettier-ignore
|
|
544
|
+
// (prettier formats this in a way that ka-lint does not like)
|
|
545
|
+
// This is the type of the lint detection function that the Rule() constructor
|
|
546
|
+
// expects as its fourth argument. It is passed the TraversalState object and
|
|
547
|
+
// content string that were passed to check(), and is also passed the array of
|
|
548
|
+
// nodes returned by the selector match and the array of strings returned by
|
|
549
|
+
// the pattern match. It should return null if no lint is detected or an
|
|
550
|
+
// error message or an object contining an error message.
|
|
551
|
+
// An optional check to verify whether or not a particular rule should
|
|
552
|
+
// be checked by context. For example, some rules only apply in exercises,
|
|
553
|
+
// and should never be applied to articles. Defaults to true, so if we
|
|
554
|
+
// omit the applies function in a rule, it'll be tested everywhere.
|
|
538
555
|
/**
|
|
539
556
|
* A Rule object describes a Perseus lint rule. See the comment at the top of
|
|
540
557
|
* this file for detailed description.
|
|
541
558
|
*/
|
|
542
559
|
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
560
|
// The comment at the top of this file has detailed docs for
|
|
552
561
|
// this constructor and its arguments
|
|
553
562
|
constructor(name, severity, selector, pattern, lint, applies) {
|
|
554
563
|
this.name = void 0;
|
|
564
|
+
// The name of the rule
|
|
555
565
|
this.severity = void 0;
|
|
566
|
+
// The severity of the rule
|
|
556
567
|
this.selector = void 0;
|
|
568
|
+
// The specified selector or the DEFAULT_SELECTOR
|
|
557
569
|
this.pattern = void 0;
|
|
570
|
+
// A regular expression if one was specified
|
|
558
571
|
this.lint = void 0;
|
|
572
|
+
// The lint-testing function or a default
|
|
559
573
|
this.applies = void 0;
|
|
574
|
+
// Checks to see if we should apply a rule or not
|
|
560
575
|
this.message = void 0;
|
|
561
576
|
if (!selector && !pattern) {
|
|
562
577
|
throw new PerseusError("Lint rules must have a selector or pattern", Errors.InvalidInput, {
|
|
@@ -721,6 +736,7 @@ ${e.stack}`,
|
|
|
721
736
|
return result;
|
|
722
737
|
}
|
|
723
738
|
}
|
|
739
|
+
// The error message for use with the default function
|
|
724
740
|
Rule.DEFAULT_SELECTOR = void 0;
|
|
725
741
|
Rule.Severity = {
|
|
726
742
|
ERROR: 1,
|
|
@@ -1273,7 +1289,9 @@ var AllRules = [AbsoluteUrl, BlockquotedMath, BlockquotedWidget, DoubleSpacingAf
|
|
|
1273
1289
|
|
|
1274
1290
|
// TreeNode is the type of a node in a parse tree. The only real requirement is
|
|
1275
1291
|
// that every node has a string-valued `type` property
|
|
1276
|
-
|
|
1292
|
+
// TraversalCallback is the type of the callback function passed to the
|
|
1293
|
+
// traverse() method. It is invoked with node, state, and content arguments
|
|
1294
|
+
// and is expected to return nothing.
|
|
1277
1295
|
// This is the TreeTransformer class described in detail at the
|
|
1278
1296
|
// top of this file.
|
|
1279
1297
|
class TreeTransformer {
|
|
@@ -1424,18 +1442,16 @@ class TreeTransformer {
|
|
|
1424
1442
|
* type annotaions.
|
|
1425
1443
|
**/
|
|
1426
1444
|
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
1445
|
// The constructor just stores the root node and creates empty stacks.
|
|
1437
1446
|
constructor(root) {
|
|
1447
|
+
// The root node of the tree being traversed
|
|
1438
1448
|
this.root = void 0;
|
|
1449
|
+
// These are internal state properties. Use the accessor methods defined
|
|
1450
|
+
// below instead of using these properties directly. Note that the
|
|
1451
|
+
// _containers and _indexes stacks can have two different types of
|
|
1452
|
+
// elements, depending on whether we just recursed on an array or on a
|
|
1453
|
+
// node. This is hard for TypeScript to deal with, so you'll see a number of
|
|
1454
|
+
// type casts through the any type when working with these two properties.
|
|
1439
1455
|
this._currentNode = void 0;
|
|
1440
1456
|
this._containers = void 0;
|
|
1441
1457
|
this._indexes = void 0;
|
|
@@ -1752,7 +1768,7 @@ class Stack {
|
|
|
1752
1768
|
|
|
1753
1769
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
1754
1770
|
const libName = "@khanacademy/perseus-linter";
|
|
1755
|
-
const libVersion = "0.3.
|
|
1771
|
+
const libVersion = "0.3.10";
|
|
1756
1772
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
1757
1773
|
|
|
1758
1774
|
// Define the shape of the linter context object that is passed through the
|