@khanacademy/perseus-linter 0.2.5 → 0.3.1
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +19 -0
- package/dist/es/index.js +643 -588
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +281 -398
- package/dist/index.js.flow +18 -2
- package/dist/index.js.map +1 -1
- package/dist/proptypes.d.ts +9 -0
- package/dist/proptypes.js.flow +17 -0
- package/dist/rule.d.ts +170 -0
- package/dist/rule.js.flow +86 -0
- package/dist/rules/absolute-url.d.ts +3 -0
- package/dist/rules/absolute-url.js.flow +9 -0
- package/dist/rules/all-rules.d.ts +2 -0
- package/dist/rules/all-rules.js.flow +9 -0
- package/dist/rules/blockquoted-math.d.ts +3 -0
- package/dist/rules/blockquoted-math.js.flow +9 -0
- package/dist/rules/blockquoted-widget.d.ts +3 -0
- package/dist/rules/blockquoted-widget.js.flow +9 -0
- package/dist/rules/double-spacing-after-terminal.d.ts +3 -0
- package/dist/rules/double-spacing-after-terminal.js.flow +9 -0
- package/dist/rules/extra-content-spacing.d.ts +3 -0
- package/dist/rules/extra-content-spacing.js.flow +9 -0
- package/dist/rules/heading-level-1.d.ts +3 -0
- package/dist/rules/heading-level-1.js.flow +9 -0
- package/dist/rules/heading-level-skip.d.ts +3 -0
- package/dist/rules/heading-level-skip.js.flow +9 -0
- package/dist/rules/heading-sentence-case.d.ts +3 -0
- package/dist/rules/heading-sentence-case.js.flow +9 -0
- package/dist/rules/heading-title-case.d.ts +3 -0
- package/dist/rules/heading-title-case.js.flow +9 -0
- package/dist/rules/image-alt-text.d.ts +3 -0
- package/dist/rules/image-alt-text.js.flow +9 -0
- package/dist/rules/image-in-table.d.ts +3 -0
- package/dist/rules/image-in-table.js.flow +9 -0
- package/dist/rules/image-spaces-around-urls.d.ts +3 -0
- package/dist/rules/image-spaces-around-urls.js.flow +9 -0
- package/dist/rules/image-widget.d.ts +3 -0
- package/dist/rules/image-widget.js.flow +9 -0
- package/dist/rules/link-click-here.d.ts +3 -0
- package/dist/rules/link-click-here.js.flow +9 -0
- package/dist/rules/lint-utils.d.ts +2 -0
- package/dist/rules/lint-utils.js.flow +8 -0
- package/dist/rules/long-paragraph.d.ts +3 -0
- package/dist/rules/long-paragraph.js.flow +9 -0
- package/dist/rules/math-adjacent.d.ts +3 -0
- package/dist/rules/math-adjacent.js.flow +9 -0
- package/dist/rules/math-align-extra-break.d.ts +3 -0
- package/dist/rules/math-align-extra-break.js.flow +9 -0
- package/dist/rules/math-align-linebreaks.d.ts +3 -0
- package/dist/rules/math-align-linebreaks.js.flow +9 -0
- package/dist/rules/math-empty.d.ts +3 -0
- package/dist/rules/math-empty.js.flow +9 -0
- package/dist/rules/math-font-size.d.ts +3 -0
- package/dist/rules/math-font-size.js.flow +9 -0
- package/dist/rules/math-frac.d.ts +3 -0
- package/dist/rules/math-frac.js.flow +9 -0
- package/dist/rules/math-nested.d.ts +3 -0
- package/dist/rules/math-nested.js.flow +9 -0
- package/dist/rules/math-starts-with-space.d.ts +3 -0
- package/dist/rules/math-starts-with-space.js.flow +9 -0
- package/dist/rules/math-text-empty.d.ts +3 -0
- package/dist/rules/math-text-empty.js.flow +9 -0
- package/dist/rules/math-without-dollars.d.ts +3 -0
- package/dist/rules/math-without-dollars.js.flow +9 -0
- package/dist/rules/nested-lists.d.ts +3 -0
- package/dist/rules/nested-lists.js.flow +9 -0
- package/dist/rules/profanity.d.ts +3 -0
- package/dist/rules/profanity.js.flow +9 -0
- package/dist/rules/table-missing-cells.d.ts +3 -0
- package/dist/rules/table-missing-cells.js.flow +9 -0
- package/dist/rules/unbalanced-code-delimiters.d.ts +3 -0
- package/dist/rules/unbalanced-code-delimiters.js.flow +9 -0
- package/dist/rules/unescaped-dollar.d.ts +3 -0
- package/dist/rules/unescaped-dollar.js.flow +9 -0
- package/dist/rules/widget-in-table.d.ts +3 -0
- package/dist/rules/widget-in-table.js.flow +9 -0
- package/dist/selector.d.ts +108 -0
- package/dist/selector.js.flow +31 -0
- package/dist/tree-transformer.d.ts +205 -0
- package/dist/tree-transformer.js.flow +253 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js.flow +12 -0
- package/package.json +4 -4
- package/src/__tests__/{matcher_test.js → matcher.test.ts} +60 -60
- package/src/__tests__/{rule_test.js → rule.test.ts} +13 -5
- package/src/__tests__/{rules_test.js → rules.test.ts} +99 -39
- package/src/__tests__/{selector-parser_test.js → selector-parser.test.ts} +1 -2
- package/src/__tests__/{tree-transformer_test.js → tree-transformer.test.ts} +39 -41
- package/src/{index.js → index.ts} +21 -23
- package/src/{proptypes.js → proptypes.ts} +4 -14
- package/src/{rule.js → rule.ts} +45 -38
- package/src/rules/{absolute-url.js → absolute-url.ts} +4 -5
- package/src/rules/all-rules.ts +71 -0
- package/src/rules/{blockquoted-math.js → blockquoted-math.ts} +3 -4
- package/src/rules/{blockquoted-widget.js → blockquoted-widget.ts} +3 -4
- package/src/rules/{double-spacing-after-terminal.js → double-spacing-after-terminal.ts} +3 -4
- package/src/rules/{extra-content-spacing.js → extra-content-spacing.ts} +3 -4
- package/src/rules/{heading-level-1.js → heading-level-1.ts} +3 -4
- package/src/rules/{heading-level-skip.js → heading-level-skip.ts} +3 -4
- package/src/rules/{heading-sentence-case.js → heading-sentence-case.ts} +3 -4
- package/src/rules/{heading-title-case.js → heading-title-case.ts} +11 -6
- package/src/rules/{image-alt-text.js → image-alt-text.ts} +3 -4
- package/src/rules/{image-in-table.js → image-in-table.ts} +3 -4
- package/src/rules/{image-spaces-around-urls.js → image-spaces-around-urls.ts} +3 -4
- package/src/rules/{image-widget.js → image-widget.ts} +3 -4
- package/src/rules/{link-click-here.js → link-click-here.ts} +3 -4
- package/src/rules/{lint-utils.js → lint-utils.ts} +1 -2
- package/src/rules/{long-paragraph.js → long-paragraph.ts} +3 -4
- package/src/rules/{math-adjacent.js → math-adjacent.ts} +3 -4
- package/src/rules/{math-align-extra-break.js → math-align-extra-break.ts} +3 -4
- package/src/rules/{math-align-linebreaks.js → math-align-linebreaks.ts} +3 -4
- package/src/rules/{math-empty.js → math-empty.ts} +3 -4
- package/src/rules/{math-font-size.js → math-font-size.ts} +3 -4
- package/src/rules/{math-frac.js → math-frac.ts} +3 -4
- package/src/rules/{math-nested.js → math-nested.ts} +3 -4
- package/src/rules/{math-starts-with-space.js → math-starts-with-space.ts} +3 -4
- package/src/rules/{math-text-empty.js → math-text-empty.ts} +3 -4
- package/src/rules/{math-without-dollars.js → math-without-dollars.ts} +3 -4
- package/src/rules/{nested-lists.js → nested-lists.ts} +3 -4
- package/src/rules/{profanity.js → profanity.ts} +3 -4
- package/src/rules/{table-missing-cells.js → table-missing-cells.ts} +3 -4
- package/src/rules/{unbalanced-code-delimiters.js → unbalanced-code-delimiters.ts} +3 -4
- package/src/rules/{unescaped-dollar.js → unescaped-dollar.ts} +3 -4
- package/src/rules/{widget-in-table.js → widget-in-table.ts} +3 -4
- package/src/{selector.js → selector.ts} +12 -13
- package/src/{tree-transformer.js → tree-transformer.ts} +24 -24
- package/src/types.ts +7 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/rules/all-rules.js +0 -72
- package/src/types.js +0 -10
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as PureMarkdown from "@khanacademy/pure-markdown";
|
|
3
2
|
|
|
4
|
-
import absoluteUrlRule from "../rules/absolute-url
|
|
5
|
-
import blockquotedMathRule from "../rules/blockquoted-math
|
|
6
|
-
import blockquotedWidgetRule from "../rules/blockquoted-widget
|
|
7
|
-
import doubleSpacingAfterTerminalRule from "../rules/double-spacing-after-terminal
|
|
8
|
-
import extraContentSpacingRule from "../rules/extra-content-spacing
|
|
9
|
-
import headingLevel1Rule from "../rules/heading-level-1
|
|
10
|
-
import headingLevelSkipRule from "../rules/heading-level-skip
|
|
11
|
-
import headingSentenceCaseRule from "../rules/heading-sentence-case
|
|
12
|
-
import headingTitleCaseRule from "../rules/heading-title-case
|
|
13
|
-
import imageAltTextRule from "../rules/image-alt-text
|
|
14
|
-
import imageInTableRule from "../rules/image-in-table
|
|
15
|
-
import imageSpacesAroundUrlsRule from "../rules/image-spaces-around-urls
|
|
16
|
-
import imageWidgetRule from "../rules/image-widget
|
|
17
|
-
import linkClickHereRule from "../rules/link-click-here
|
|
18
|
-
import longParagraphRule from "../rules/long-paragraph
|
|
19
|
-
import mathAdjacentRule from "../rules/math-adjacent
|
|
20
|
-
import mathAlignExtraBreakRule from "../rules/math-align-extra-break
|
|
21
|
-
import mathAlignLinebreaksRule from "../rules/math-align-linebreaks
|
|
22
|
-
import mathEmptyRule from "../rules/math-empty
|
|
23
|
-
import mathFontSizeRule from "../rules/math-font-size
|
|
24
|
-
import mathFracRule from "../rules/math-frac
|
|
25
|
-
import mathNestedRule from "../rules/math-nested
|
|
26
|
-
import mathStartsWithSpaceRule from "../rules/math-starts-with-space
|
|
27
|
-
import mathTextEmptyRule from "../rules/math-text-empty
|
|
28
|
-
import mathWithoutDollarsRule from "../rules/math-without-dollars
|
|
29
|
-
import nestedListsRule from "../rules/nested-lists
|
|
30
|
-
import profanityRule from "../rules/profanity
|
|
31
|
-
import tableMissingCellsRule from "../rules/table-missing-cells
|
|
32
|
-
import unbalancedCodeDelimitersRule from "../rules/unbalanced-code-delimiters
|
|
33
|
-
import unescapedDollarRule from "../rules/unescaped-dollar
|
|
34
|
-
import widgetInTableRule from "../rules/widget-in-table
|
|
35
|
-
import TreeTransformer from "../tree-transformer
|
|
3
|
+
import absoluteUrlRule from "../rules/absolute-url";
|
|
4
|
+
import blockquotedMathRule from "../rules/blockquoted-math";
|
|
5
|
+
import blockquotedWidgetRule from "../rules/blockquoted-widget";
|
|
6
|
+
import doubleSpacingAfterTerminalRule from "../rules/double-spacing-after-terminal";
|
|
7
|
+
import extraContentSpacingRule from "../rules/extra-content-spacing";
|
|
8
|
+
import headingLevel1Rule from "../rules/heading-level-1";
|
|
9
|
+
import headingLevelSkipRule from "../rules/heading-level-skip";
|
|
10
|
+
import headingSentenceCaseRule from "../rules/heading-sentence-case";
|
|
11
|
+
import headingTitleCaseRule from "../rules/heading-title-case";
|
|
12
|
+
import imageAltTextRule from "../rules/image-alt-text";
|
|
13
|
+
import imageInTableRule from "../rules/image-in-table";
|
|
14
|
+
import imageSpacesAroundUrlsRule from "../rules/image-spaces-around-urls";
|
|
15
|
+
import imageWidgetRule from "../rules/image-widget";
|
|
16
|
+
import linkClickHereRule from "../rules/link-click-here";
|
|
17
|
+
import longParagraphRule from "../rules/long-paragraph";
|
|
18
|
+
import mathAdjacentRule from "../rules/math-adjacent";
|
|
19
|
+
import mathAlignExtraBreakRule from "../rules/math-align-extra-break";
|
|
20
|
+
import mathAlignLinebreaksRule from "../rules/math-align-linebreaks";
|
|
21
|
+
import mathEmptyRule from "../rules/math-empty";
|
|
22
|
+
import mathFontSizeRule from "../rules/math-font-size";
|
|
23
|
+
import mathFracRule from "../rules/math-frac";
|
|
24
|
+
import mathNestedRule from "../rules/math-nested";
|
|
25
|
+
import mathStartsWithSpaceRule from "../rules/math-starts-with-space";
|
|
26
|
+
import mathTextEmptyRule from "../rules/math-text-empty";
|
|
27
|
+
import mathWithoutDollarsRule from "../rules/math-without-dollars";
|
|
28
|
+
import nestedListsRule from "../rules/nested-lists";
|
|
29
|
+
import profanityRule from "../rules/profanity";
|
|
30
|
+
import tableMissingCellsRule from "../rules/table-missing-cells";
|
|
31
|
+
import unbalancedCodeDelimitersRule from "../rules/unbalanced-code-delimiters";
|
|
32
|
+
import unescapedDollarRule from "../rules/unescaped-dollar";
|
|
33
|
+
import widgetInTableRule from "../rules/widget-in-table";
|
|
34
|
+
import TreeTransformer from "../tree-transformer";
|
|
35
|
+
|
|
36
|
+
type Rule = any;
|
|
36
37
|
|
|
37
38
|
describe("Individual lint rules tests", () => {
|
|
38
|
-
function testRule(rule, markdown, context) {
|
|
39
|
+
function testRule(rule: Rule, markdown: string, context) {
|
|
39
40
|
const tree = PureMarkdown.parse(markdown);
|
|
40
41
|
const tt = new TreeTransformer(tree);
|
|
41
42
|
const warnings = [];
|
|
@@ -46,8 +47,7 @@ describe("Individual lint rules tests", () => {
|
|
|
46
47
|
if (TreeTransformer.isTextNode(node)) {
|
|
47
48
|
let next = state.nextSibling();
|
|
48
49
|
while (TreeTransformer.isTextNode(next)) {
|
|
49
|
-
//
|
|
50
|
-
// $FlowFixMe[incompatible-use]
|
|
50
|
+
// @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'.
|
|
51
51
|
node.content += next.content;
|
|
52
52
|
state.removeNextSibling();
|
|
53
53
|
next = state.nextSibling();
|
|
@@ -56,7 +56,6 @@ describe("Individual lint rules tests", () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
if (context) {
|
|
59
|
-
// $FlowFixMe[prop-missing]
|
|
60
59
|
context.content = markdown;
|
|
61
60
|
} else {
|
|
62
61
|
context = {
|
|
@@ -67,6 +66,7 @@ describe("Individual lint rules tests", () => {
|
|
|
67
66
|
tt.traverse((node, state, content) => {
|
|
68
67
|
const check = rule.check(node, state, content, context);
|
|
69
68
|
if (check) {
|
|
69
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'any' is not assignable to parameter of type 'never'.
|
|
70
70
|
warnings.push(check);
|
|
71
71
|
}
|
|
72
72
|
});
|
|
@@ -74,7 +74,7 @@ describe("Individual lint rules tests", () => {
|
|
|
74
74
|
return warnings.length === 0 ? null : warnings;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function expectWarning(rule, strings
|
|
77
|
+
function expectWarning(rule, strings: string | Array<string>, context) {
|
|
78
78
|
if (typeof strings === "string") {
|
|
79
79
|
strings = [strings];
|
|
80
80
|
}
|
|
@@ -86,7 +86,7 @@ describe("Individual lint rules tests", () => {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function expectPass(rule, strings
|
|
89
|
+
function expectPass(rule, strings: string | Array<string>, context) {
|
|
90
90
|
if (typeof strings === "string") {
|
|
91
91
|
strings = [strings];
|
|
92
92
|
}
|
|
@@ -102,49 +102,62 @@ describe("Individual lint rules tests", () => {
|
|
|
102
102
|
const sentence = new Array(25).fill("lorem ipsum").join(" ");
|
|
103
103
|
|
|
104
104
|
// long-paragraph rule warns about paragraphs over 500 characters
|
|
105
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
105
106
|
expectWarning(longParagraphRule, sentence + sentence);
|
|
107
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
106
108
|
expectPass(longParagraphRule, [sentence, sentence + "\n\n" + sentence]);
|
|
107
109
|
|
|
110
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
108
111
|
expectWarning(headingLevel1Rule, "# Level 1 heading");
|
|
112
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
109
113
|
expectPass(headingLevel1Rule, "## Level 1 heading\n\n### Level 3 heading");
|
|
110
114
|
|
|
115
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
111
116
|
expectWarning(headingLevelSkipRule, "## heading 1\n\n#### heading 2");
|
|
117
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
112
118
|
expectPass(headingLevelSkipRule, [
|
|
113
119
|
"## heading 1\n\n### heading 2\n\n#### heading 3\n\n### heading 4",
|
|
114
120
|
"## heading 1\n\n##heading 2\n\n##heading3",
|
|
115
121
|
]);
|
|
116
122
|
|
|
123
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
117
124
|
expectWarning(
|
|
118
125
|
headingTitleCaseRule,
|
|
119
126
|
"## This Heading is in Title Case and the but nor for Too",
|
|
120
127
|
);
|
|
128
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
121
129
|
expectPass(headingTitleCaseRule, [
|
|
122
130
|
"## This heading is in sentence case",
|
|
123
131
|
"## Acronyms: The CIA, NSA, DNI, and FBI",
|
|
124
132
|
"## The Great War",
|
|
125
133
|
]);
|
|
126
134
|
|
|
135
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
127
136
|
expectWarning(headingSentenceCaseRule, [
|
|
128
137
|
"## this heading is uncapitalized",
|
|
129
138
|
"## 'this' heading is uncapitalized",
|
|
130
139
|
"## this heading is uncapitalized",
|
|
131
140
|
]);
|
|
141
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
132
142
|
expectPass(headingSentenceCaseRule, [
|
|
133
143
|
"## This heading is in sentence case",
|
|
134
144
|
"## 'This heading too'",
|
|
135
145
|
"## 2 + 2 = 4",
|
|
136
146
|
]);
|
|
137
147
|
|
|
148
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
138
149
|
expectWarning(nestedListsRule, [
|
|
139
150
|
"1. outer\n * nested\n *nested",
|
|
140
151
|
" + outer\n\n 1. nested",
|
|
141
152
|
]);
|
|
153
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
142
154
|
expectPass(nestedListsRule, [
|
|
143
155
|
"-one\n-two\n-three",
|
|
144
156
|
"1. one\n 2. two\n3. three",
|
|
145
157
|
" * one\n\n * two\n\n * three",
|
|
146
158
|
]);
|
|
147
159
|
|
|
160
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
148
161
|
expectWarning(imageAltTextRule, [
|
|
149
162
|
"",
|
|
150
163
|
'',
|
|
@@ -154,34 +167,42 @@ describe("Individual lint rules tests", () => {
|
|
|
154
167
|
"", // too short to be meaningful
|
|
155
168
|
]);
|
|
156
169
|
|
|
170
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
157
171
|
expectPass(imageAltTextRule, [
|
|
158
172
|
"",
|
|
159
173
|
'',
|
|
160
174
|
"![alt alt alt][url-ref]",
|
|
161
175
|
]);
|
|
162
176
|
|
|
177
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
163
178
|
expectWarning(blockquotedMathRule, ["> $1$", "Quote:\n\n> $x$\n\n"]);
|
|
179
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
164
180
|
expectPass(blockquotedMathRule, [
|
|
165
181
|
"$x$",
|
|
166
182
|
"\n$x$\n $y$\n",
|
|
167
183
|
"> bq #1\n\n$x+y=1$\n\n> bq #2",
|
|
168
184
|
]);
|
|
169
185
|
|
|
186
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
170
187
|
expectWarning(blockquotedWidgetRule, ["> [[☃ passage 1]]"]);
|
|
188
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
171
189
|
expectPass(blockquotedWidgetRule, [
|
|
172
190
|
"[[☃ passage 1]]",
|
|
173
191
|
"> bq #1\n\nTesting [[☃ passage 1]] testing\n\n> bq #2",
|
|
174
192
|
]);
|
|
175
193
|
|
|
194
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
176
195
|
expectWarning(linkClickHereRule, [
|
|
177
196
|
"[click here](http://google.com)",
|
|
178
197
|
"[Click here, please](http://google.com)",
|
|
179
198
|
"[For a good time, Click Here](http://google.com)",
|
|
180
199
|
]);
|
|
200
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
181
201
|
expectPass(linkClickHereRule, [
|
|
182
202
|
"[click to activate this link here](http://google.com)",
|
|
183
203
|
]);
|
|
184
204
|
|
|
205
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
185
206
|
expectWarning(absoluteUrlRule, [
|
|
186
207
|
// Warn about absolute khanacademy.org urls
|
|
187
208
|
"[target](http://khanacademy.org/about)",
|
|
@@ -198,6 +219,7 @@ describe("Individual lint rules tests", () => {
|
|
|
198
219
|
"",
|
|
199
220
|
"",
|
|
200
221
|
]);
|
|
222
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
201
223
|
expectPass(absoluteUrlRule, [
|
|
202
224
|
"[target](/about)", // relative URLs okay
|
|
203
225
|
"[target](https://kasandbox.org/path)",
|
|
@@ -212,20 +234,25 @@ describe("Individual lint rules tests", () => {
|
|
|
212
234
|
"",
|
|
213
235
|
]);
|
|
214
236
|
|
|
237
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
215
238
|
expectWarning(imageInTableRule, [
|
|
216
239
|
"|col1|col2|\n|----|----|\n||cell2|",
|
|
217
240
|
]);
|
|
241
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
218
242
|
expectPass(imageInTableRule, [
|
|
219
243
|
"\n|col1|col2|\n|----|----|\n|cell1|cell2|",
|
|
220
244
|
]);
|
|
221
245
|
|
|
246
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
222
247
|
expectWarning(widgetInTableRule, [
|
|
223
248
|
"|col1|col2|\n|----|----|\n|[[☃ passage 1]]|cell2|",
|
|
224
249
|
]);
|
|
250
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
225
251
|
expectPass(widgetInTableRule, [
|
|
226
252
|
"[[☃ passage 1]]\n|col1|col2|\n|----|----|\n|cell1|cell2|",
|
|
227
253
|
]);
|
|
228
254
|
|
|
255
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
229
256
|
expectWarning(tableMissingCellsRule, [
|
|
230
257
|
"|col1|col2|col3|\n|----|----|----|\n|col1|col2|col3|\n|cell1|cell2|",
|
|
231
258
|
"|col1|col2|col3|\n|----|----|----|\n|col1|col2|\n|cell1|cell2|",
|
|
@@ -233,15 +260,19 @@ describe("Individual lint rules tests", () => {
|
|
|
233
260
|
"|col1|\n|----|----|\n|col1|\n|cell1|cell2|",
|
|
234
261
|
"|col1|col2|\n|----|----|\n|col1|\n|cell1|cell2|",
|
|
235
262
|
]);
|
|
263
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
236
264
|
expectPass(tableMissingCellsRule, [
|
|
237
265
|
"|col1|col2|\n|----|----|\n|cell1|cell2|\n|cell1|cell2|",
|
|
238
266
|
"|cell1|\n|----|\n|cell2|\n|cell3|",
|
|
239
267
|
]);
|
|
240
268
|
|
|
269
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
241
270
|
expectWarning(unescapedDollarRule, ["It costs $10", "It costs $$10$"]);
|
|
242
271
|
|
|
272
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
243
273
|
expectPass(unescapedDollarRule, ["It costs \\$10", "It costs $10x$"]);
|
|
244
274
|
|
|
275
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
245
276
|
expectWarning(mathStartsWithSpaceRule, [
|
|
246
277
|
"foo$~ x$bar",
|
|
247
278
|
"$\\qquad x$",
|
|
@@ -254,6 +285,7 @@ describe("Individual lint rules tests", () => {
|
|
|
254
285
|
"$\\enspace x$",
|
|
255
286
|
"$\\phantom{xyz} x$",
|
|
256
287
|
]);
|
|
288
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
257
289
|
expectPass(mathStartsWithSpaceRule, [
|
|
258
290
|
"$a~ x$",
|
|
259
291
|
"$a\\qquad x$",
|
|
@@ -267,41 +299,51 @@ describe("Individual lint rules tests", () => {
|
|
|
267
299
|
"$a\\phantom{xyz} x$",
|
|
268
300
|
]);
|
|
269
301
|
|
|
302
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
270
303
|
expectWarning(mathEmptyRule, [
|
|
271
304
|
"foo $$ bar",
|
|
272
305
|
"foo\n\n$$\n\nbar",
|
|
273
306
|
"$$ | $$ | $$\n- | - | -\ndata 1 | data 2 | data 3",
|
|
274
307
|
]);
|
|
308
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
275
309
|
expectPass(mathEmptyRule, [
|
|
276
310
|
"foo $x$ bar",
|
|
277
311
|
"foo\n\n$x$\n\nbar",
|
|
278
312
|
"$x$ | $y$ | $z$\n- | - | -\ndata 1 | data 2 | data 3",
|
|
279
313
|
]);
|
|
280
314
|
|
|
315
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
281
316
|
expectWarning(mathFracRule, ["$\\frac 12$", "$\\frac{1}{2}$"]);
|
|
317
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
282
318
|
expectPass(mathFracRule, [
|
|
283
319
|
"$\\dfrac 12$",
|
|
284
320
|
"$\\dfrac{1}{2}$",
|
|
285
321
|
"$\\fraction 12$",
|
|
286
322
|
]);
|
|
287
323
|
|
|
324
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
288
325
|
expectWarning(mathTextEmptyRule, [
|
|
289
326
|
"$x\\text{}y$",
|
|
290
327
|
"$x\\text{ }y$",
|
|
291
328
|
"$x\\text{\n}y$",
|
|
292
329
|
"$x\\text{\t}y$",
|
|
293
330
|
]);
|
|
331
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
294
332
|
expectPass(mathTextEmptyRule, ["$x\\text{z}y$"]);
|
|
295
333
|
|
|
334
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
296
335
|
expectWarning(mathAdjacentRule, ["$x=b+c$\n\n$x-b=c$"]);
|
|
336
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
297
337
|
expectPass(mathAdjacentRule, ["$x=b+c$\n\nnew paragraph\n\n$x-b=c$"]);
|
|
298
338
|
|
|
339
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
299
340
|
expectWarning(mathAlignLinebreaksRule, [
|
|
300
341
|
"$\\begin{align}x\\\\y\\end{align}$",
|
|
301
342
|
"$\\begin{align} x \\\\ y \\end{align}$",
|
|
302
343
|
"$\\begin{align}x\\\\\\\\\\\\y\\end{align}$",
|
|
303
344
|
"$\\begin{align}\nx\\\\\n\\\\\\\\\ny\n\\end{align}$",
|
|
304
345
|
]);
|
|
346
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
305
347
|
expectPass(mathAlignLinebreaksRule, [
|
|
306
348
|
"$\\begin{align}x\\sqrty\\end{align}$",
|
|
307
349
|
"$\\begin{align}x\\\\\\\\y\\end{align}$",
|
|
@@ -309,21 +351,26 @@ describe("Individual lint rules tests", () => {
|
|
|
309
351
|
"$\\begin{align}x \\\\ \\\\ y\\end{align}$",
|
|
310
352
|
]);
|
|
311
353
|
|
|
354
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
312
355
|
expectWarning(mathAlignExtraBreakRule, [
|
|
313
356
|
"$\\begin{align}x \\\\\\\\ y \\\\ \\end{align}$",
|
|
314
357
|
"$\\begin{align}x \\\\\\\\ y \\\\\\\\ \\end{align}$",
|
|
315
358
|
]);
|
|
359
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
316
360
|
expectPass(mathAlignExtraBreakRule, [
|
|
317
361
|
"$\\begin{align} x \\\\\\\\ y \\end{align}$",
|
|
318
362
|
]);
|
|
319
363
|
|
|
364
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
320
365
|
expectWarning(mathNestedRule, [
|
|
321
366
|
"$\\text{4$x$}$",
|
|
322
367
|
"inline $\\text{4$x$}$ math",
|
|
323
368
|
"$\\text{$$}$",
|
|
324
369
|
]);
|
|
370
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
325
371
|
expectPass(mathNestedRule, ["$\\text{4}x$", "inline $\\text{4}x$ math"]);
|
|
326
372
|
|
|
373
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
327
374
|
expectWarning(mathFontSizeRule, [
|
|
328
375
|
"$\\tiny{x}$",
|
|
329
376
|
"inline $\\Tiny{x}$ math",
|
|
@@ -336,8 +383,10 @@ describe("Individual lint rules tests", () => {
|
|
|
336
383
|
"$\\normalsize{x}$",
|
|
337
384
|
"$\\scriptsize{x}$",
|
|
338
385
|
]);
|
|
386
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
339
387
|
expectPass(mathFontSizeRule, ["$\\sqrt{x}$", "inline $\\sqrt{x}$ math"]);
|
|
340
388
|
|
|
389
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
341
390
|
expectWarning(profanityRule, [
|
|
342
391
|
"Shit",
|
|
343
392
|
"taking a piss",
|
|
@@ -346,14 +395,17 @@ describe("Individual lint rules tests", () => {
|
|
|
346
395
|
"cocksucker",
|
|
347
396
|
"motherfucker",
|
|
348
397
|
]);
|
|
398
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
349
399
|
expectPass(profanityRule, ["spit", "miss", "duck"]);
|
|
350
400
|
|
|
401
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
351
402
|
expectWarning(mathWithoutDollarsRule, [
|
|
352
403
|
"One half: \\frac{1}{2}!",
|
|
353
404
|
"\\Large{BIG}!",
|
|
354
405
|
"This looks like someone's ear: {",
|
|
355
406
|
"Here's the other ear: }. Weird!",
|
|
356
407
|
]);
|
|
408
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
357
409
|
expectPass(mathWithoutDollarsRule, [
|
|
358
410
|
"One half: $\\frac{1}{2}$",
|
|
359
411
|
"$\\Large{BIG}$!",
|
|
@@ -365,12 +417,14 @@ describe("Individual lint rules tests", () => {
|
|
|
365
417
|
"\n \\frac{1}{2}\n {\n }\n",
|
|
366
418
|
]);
|
|
367
419
|
|
|
420
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
368
421
|
expectWarning(unbalancedCodeDelimitersRule, [
|
|
369
422
|
"`code``",
|
|
370
423
|
"``code```",
|
|
371
424
|
"```code\n",
|
|
372
425
|
"~~~\ncode\n~~",
|
|
373
426
|
]);
|
|
427
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
374
428
|
expectPass(unbalancedCodeDelimitersRule, [
|
|
375
429
|
"`code`",
|
|
376
430
|
"``code``",
|
|
@@ -382,6 +436,7 @@ describe("Individual lint rules tests", () => {
|
|
|
382
436
|
"$`~$",
|
|
383
437
|
]);
|
|
384
438
|
|
|
439
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
385
440
|
expectWarning(imageSpacesAroundUrlsRule, [
|
|
386
441
|
"",
|
|
387
442
|
"",
|
|
@@ -391,6 +446,7 @@ describe("Individual lint rules tests", () => {
|
|
|
391
446
|
"",
|
|
392
447
|
"",
|
|
393
448
|
]);
|
|
449
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
394
450
|
expectPass(imageSpacesAroundUrlsRule, [
|
|
395
451
|
"",
|
|
396
452
|
"",
|
|
@@ -464,22 +520,26 @@ describe("Individual lint rules tests", () => {
|
|
|
464
520
|
},
|
|
465
521
|
});
|
|
466
522
|
|
|
523
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
467
524
|
expectWarning(doubleSpacingAfterTerminalRule, [
|
|
468
525
|
"Good times. Great oldies.",
|
|
469
526
|
"End of the line! ",
|
|
470
527
|
"You? Me!",
|
|
471
528
|
]);
|
|
529
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
472
530
|
expectPass(doubleSpacingAfterTerminalRule, [
|
|
473
531
|
"This is okay.",
|
|
474
532
|
"This is definitely okay. Yeah.",
|
|
475
533
|
"$a == 3. 125$",
|
|
476
534
|
]);
|
|
477
535
|
|
|
536
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
478
537
|
expectWarning(extraContentSpacingRule, [
|
|
479
538
|
"There's extra spaces here. ",
|
|
480
539
|
"There's extra spaces here ",
|
|
481
540
|
" ",
|
|
482
541
|
]);
|
|
542
|
+
// @ts-expect-error [FEI-5003] - TS2554 - Expected 3 arguments, but got 2.
|
|
483
543
|
expectPass(extraContentSpacingRule, [
|
|
484
544
|
"This is okay.",
|
|
485
545
|
"This is definitely okay. Yeah.",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import TreeTransformer from "../tree-transformer";
|
|
2
|
+
|
|
3
|
+
import type {TraversalState} from "../tree-transformer";
|
|
3
4
|
|
|
4
5
|
describe("PerseusLinter tree transformer", () => {
|
|
5
6
|
function clone(o) {
|
|
@@ -30,7 +31,7 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
30
31
|
],
|
|
31
32
|
},
|
|
32
33
|
],
|
|
33
|
-
};
|
|
34
|
+
} as const;
|
|
34
35
|
|
|
35
36
|
// These are three variants on the same tree where we use arrays
|
|
36
37
|
// instead of single nodes. The tests below will be run over all
|
|
@@ -50,25 +51,25 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
50
51
|
|
|
51
52
|
// The first test will fill in this array mapping numbers to nodes
|
|
52
53
|
// Then subsequent tests can use it
|
|
53
|
-
const nodes = [];
|
|
54
|
+
const nodes: Array<any> = [];
|
|
54
55
|
|
|
55
|
-
function getTraversalOrder(tree) {
|
|
56
|
-
const order = [];
|
|
56
|
+
function getTraversalOrder(tree: any) {
|
|
57
|
+
const order: Array<any> = [];
|
|
57
58
|
new TreeTransformer(tree).traverse((n, state) => {
|
|
58
|
-
//
|
|
59
|
+
// @ts-expect-error [FEI-5003] - TS2339 - Property 'id' does not exist on type 'TreeNode'.
|
|
59
60
|
order.push(n.id);
|
|
60
61
|
});
|
|
61
62
|
return order;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
trees.forEach((tree:
|
|
65
|
+
trees.forEach((tree: any, treenum: number) => {
|
|
65
66
|
it(
|
|
66
67
|
"does post-order traversal of each node in the tree " + treenum,
|
|
67
68
|
() => {
|
|
68
69
|
const tt = new TreeTransformer(tree);
|
|
69
|
-
const ids = [];
|
|
70
|
+
const ids: Array<any> = [];
|
|
70
71
|
|
|
71
|
-
tt.traverse((n:
|
|
72
|
+
tt.traverse((n: any) => {
|
|
72
73
|
nodes[n.id] = n; // Remember the nodes by id for later tests
|
|
73
74
|
ids.push(n.id);
|
|
74
75
|
});
|
|
@@ -86,7 +87,7 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
it("correctly gets the siblings for each node " + treenum, () => {
|
|
89
|
-
new TreeTransformer(tree).traverse((n:
|
|
90
|
+
new TreeTransformer(tree).traverse((n: any, state) => {
|
|
90
91
|
const previd = previousNodeIds[n.id];
|
|
91
92
|
expect(state.hasPreviousSibling()).toEqual(previd >= 0);
|
|
92
93
|
expect(state.previousSibling()).toEqual(
|
|
@@ -122,7 +123,7 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
122
123
|
["root", "list"],
|
|
123
124
|
];
|
|
124
125
|
|
|
125
|
-
new TreeTransformer(tree).traverse((n:
|
|
126
|
+
new TreeTransformer(tree).traverse((n: any, state) => {
|
|
126
127
|
expect(state.hasParent()).toEqual(
|
|
127
128
|
ancestorsById[n.id].length > 0,
|
|
128
129
|
);
|
|
@@ -151,11 +152,9 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
151
152
|
"C",
|
|
152
153
|
];
|
|
153
154
|
|
|
154
|
-
new TreeTransformer(tree).traverse(
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
},
|
|
158
|
-
);
|
|
155
|
+
new TreeTransformer(tree).traverse((n: any, state, content) => {
|
|
156
|
+
expect(content).toEqual(textContentForNode[n.id]);
|
|
157
|
+
});
|
|
159
158
|
});
|
|
160
159
|
|
|
161
160
|
it("can remove the next sibling " + treenum, () => {
|
|
@@ -177,16 +176,14 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
177
176
|
const copy = clone(tree);
|
|
178
177
|
|
|
179
178
|
// Remove the next sibling of the node with this id
|
|
180
|
-
new TreeTransformer(copy).traverse(
|
|
181
|
-
(n
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
},
|
|
189
|
-
);
|
|
179
|
+
new TreeTransformer(copy).traverse((n: any, state: any) => {
|
|
180
|
+
if (n.id === id) {
|
|
181
|
+
state.removeNextSibling();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Ensure that we don't iterate the removed sibling
|
|
185
|
+
expect(n.id).not.toEqual(nextNodeIds[id]);
|
|
186
|
+
});
|
|
190
187
|
|
|
191
188
|
// And then get the traversal order of the resulting tree
|
|
192
189
|
const traversal = getTraversalOrder(copy);
|
|
@@ -222,13 +219,11 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
222
219
|
// Make a copy of the tree
|
|
223
220
|
const copy = clone(tree);
|
|
224
221
|
// Remove this node from it
|
|
225
|
-
new TreeTransformer(copy).traverse(
|
|
226
|
-
(n
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
);
|
|
222
|
+
new TreeTransformer(copy).traverse((n: any, state: any) => {
|
|
223
|
+
if (n.id === id) {
|
|
224
|
+
state.replace();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
232
227
|
|
|
233
228
|
// Traverse what remains and see if we get what is expected
|
|
234
229
|
expect(getTraversalOrder(copy)).toEqual(expectedTraversals[id]);
|
|
@@ -252,9 +247,10 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
252
247
|
// Make a copy of the tree
|
|
253
248
|
const copy = clone(tree);
|
|
254
249
|
// Replace the node with a different one
|
|
255
|
-
new TreeTransformer(copy).traverse((n:
|
|
250
|
+
new TreeTransformer(copy).traverse((n: any, state) => {
|
|
256
251
|
if (n.id === id) {
|
|
257
252
|
state.replace({
|
|
253
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type '{ id: number; type: string; }' is not assignable to parameter of type 'TreeNode'.
|
|
258
254
|
id: 99,
|
|
259
255
|
type: "replacement",
|
|
260
256
|
});
|
|
@@ -287,11 +283,12 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
287
283
|
const copy = clone(tree);
|
|
288
284
|
let count = 0;
|
|
289
285
|
// Replace the node with a different one
|
|
290
|
-
new TreeTransformer(copy).traverse((n:
|
|
286
|
+
new TreeTransformer(copy).traverse((n: any, state) => {
|
|
291
287
|
if (n.id === id) {
|
|
292
288
|
// Ensure that we don't traverse the node more than once
|
|
293
289
|
expect(++count).toEqual(1);
|
|
294
290
|
state.replace({
|
|
291
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type '{ id: number; type: string; content: any; }' is not assignable to parameter of type 'TreeNode'.
|
|
295
292
|
id: 99,
|
|
296
293
|
type: "reparent",
|
|
297
294
|
content: n,
|
|
@@ -324,9 +321,9 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
324
321
|
// Make a copy of the tree
|
|
325
322
|
const copy = clone(tree);
|
|
326
323
|
// Replace the node with two new ones
|
|
327
|
-
new TreeTransformer(copy).traverse((n:
|
|
324
|
+
new TreeTransformer(copy).traverse((n: any, state) => {
|
|
328
325
|
if (n.id === id) {
|
|
329
|
-
//
|
|
326
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type '({ id: number; type: string; } | { id: number; type: string; content: { id: number; type: string; }; })[]' is not assignable to parameter of type 'TreeNode'.
|
|
330
327
|
state.replace([
|
|
331
328
|
{
|
|
332
329
|
id: 99,
|
|
@@ -371,10 +368,11 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
371
368
|
// Make a copy of the tree
|
|
372
369
|
const copy = clone(tree);
|
|
373
370
|
// Replace the node with two new ones
|
|
374
|
-
new TreeTransformer(copy).traverse((n:
|
|
371
|
+
new TreeTransformer(copy).traverse((n: any, state) => {
|
|
375
372
|
if (n.id === id) {
|
|
376
373
|
state.replace(
|
|
377
374
|
{
|
|
375
|
+
// @ts-expect-error [FEI-5003] - TS2345 - Argument of type '{ id: number; type: string; }' is not assignable to parameter of type 'TreeNode'.
|
|
378
376
|
id: 99,
|
|
379
377
|
type: "replacement",
|
|
380
378
|
},
|
|
@@ -405,10 +403,10 @@ describe("PerseusLinter tree transformer", () => {
|
|
|
405
403
|
// for each node. Then check that goToParent() and
|
|
406
404
|
// goToPreviousSibling() on each saved state object
|
|
407
405
|
// modify the states in apprpriate ways.
|
|
408
|
-
const states = [];
|
|
406
|
+
const states: Array<TraversalState> = [];
|
|
409
407
|
|
|
410
408
|
const tt = new TreeTransformer(tree);
|
|
411
|
-
tt.traverse((n:
|
|
409
|
+
tt.traverse((n: any, state, content) => {
|
|
412
410
|
states[n.id] = state.clone();
|
|
413
411
|
// Verify that a clone() and equal() work as expected
|
|
414
412
|
expect(state.equals(states[n.id])).toBeTruthy();
|