@khanacademy/perseus-linter 0.3.1 → 0.3.2

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/es/index.js +15 -20
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.js +15 -20
  5. package/dist/index.js.map +1 -1
  6. package/dist/tree-transformer.d.ts +1 -1
  7. package/package.json +2 -2
  8. package/src/__tests__/matcher.test.ts +57 -57
  9. package/src/__tests__/rules.test.ts +62 -62
  10. package/src/__tests__/tree-transformer.test.ts +5 -5
  11. package/src/index.ts +4 -4
  12. package/src/rule.ts +2 -2
  13. package/src/tree-transformer.ts +9 -13
  14. package/tsconfig-build.json +11 -0
  15. package/{tsconfig.tsbuildinfo → tsconfig-build.tsbuildinfo} +1 -1
  16. package/dist/index.js.flow +0 -18
  17. package/dist/proptypes.js.flow +0 -17
  18. package/dist/rule.js.flow +0 -86
  19. package/dist/rules/absolute-url.js.flow +0 -9
  20. package/dist/rules/all-rules.js.flow +0 -9
  21. package/dist/rules/blockquoted-math.js.flow +0 -9
  22. package/dist/rules/blockquoted-widget.js.flow +0 -9
  23. package/dist/rules/double-spacing-after-terminal.js.flow +0 -9
  24. package/dist/rules/extra-content-spacing.js.flow +0 -9
  25. package/dist/rules/heading-level-1.js.flow +0 -9
  26. package/dist/rules/heading-level-skip.js.flow +0 -9
  27. package/dist/rules/heading-sentence-case.js.flow +0 -9
  28. package/dist/rules/heading-title-case.js.flow +0 -9
  29. package/dist/rules/image-alt-text.js.flow +0 -9
  30. package/dist/rules/image-in-table.js.flow +0 -9
  31. package/dist/rules/image-spaces-around-urls.js.flow +0 -9
  32. package/dist/rules/image-widget.js.flow +0 -9
  33. package/dist/rules/link-click-here.js.flow +0 -9
  34. package/dist/rules/lint-utils.js.flow +0 -8
  35. package/dist/rules/long-paragraph.js.flow +0 -9
  36. package/dist/rules/math-adjacent.js.flow +0 -9
  37. package/dist/rules/math-align-extra-break.js.flow +0 -9
  38. package/dist/rules/math-align-linebreaks.js.flow +0 -9
  39. package/dist/rules/math-empty.js.flow +0 -9
  40. package/dist/rules/math-font-size.js.flow +0 -9
  41. package/dist/rules/math-frac.js.flow +0 -9
  42. package/dist/rules/math-nested.js.flow +0 -9
  43. package/dist/rules/math-starts-with-space.js.flow +0 -9
  44. package/dist/rules/math-text-empty.js.flow +0 -9
  45. package/dist/rules/math-without-dollars.js.flow +0 -9
  46. package/dist/rules/nested-lists.js.flow +0 -9
  47. package/dist/rules/profanity.js.flow +0 -9
  48. package/dist/rules/table-missing-cells.js.flow +0 -9
  49. package/dist/rules/unbalanced-code-delimiters.js.flow +0 -9
  50. package/dist/rules/unescaped-dollar.js.flow +0 -9
  51. package/dist/rules/widget-in-table.js.flow +0 -9
  52. package/dist/selector.js.flow +0 -31
  53. package/dist/tree-transformer.js.flow +0 -253
  54. package/dist/types.js.flow +0 -12
  55. package/tsconfig.json +0 -12
@@ -1,8 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- declare export function getHostname(url: string): string;
8
- declare export function isInternalURL(url: string): boolean;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import Rule from "../rule";
8
- declare var _default: Rule;
9
- declare export default typeof _default;
@@ -1,31 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- import type { TreeNode, TraversalState } from "./tree-transformer";
8
-
9
- /**
10
- * This is the base class for all Selector types. The key method that all
11
- * selector subclasses must implement is match(). It takes a TraversalState
12
- * object (from a TreeTransformer traversal) and tests whether the selector
13
- * matches at the current node. See the comment at the start of this file for
14
- * more details on the match() method.
15
- */
16
- declare export default class Selector {
17
- static parse(selectorText: string): Selector;
18
-
19
- /**
20
- * Return an array of the nodes that matched or null if no match.
21
- * This is the base class so we just throw an exception. All Selector
22
- * subclasses must provide an implementation of this method.
23
- */
24
- match(state: TraversalState): $ReadOnlyArray<TreeNode> | null | void;
25
-
26
- /**
27
- * Selector subclasses all define a toString() method primarily
28
- * because it makes it easy to write parser tests.
29
- */
30
- toString(): string;
31
- }
@@ -1,253 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- /**
8
- * TreeTransformer is a class for traversing and transforming trees. Create a
9
- * TreeTransformer by passing the root node of the tree to the
10
- * constructor. Then traverse that tree by calling the traverse() method. The
11
- * argument to traverse() is a callback function that will be called once for
12
- * each node in the tree. This is a post-order depth-first traversal: the
13
- * callback is not called on the a way down, but on the way back up. That is,
14
- * the children of a node are traversed before the node itself is.
15
- *
16
- * The traversal callback function is passed three arguments, the node being
17
- * traversed, a TraversalState object, and the concatentated text content of
18
- * the node and all of its descendants. The TraversalState object is the most
19
- * most interesting argument: it has methods for querying the ancestors and
20
- * siblings of the node, and for deleting or replacing the node. These
21
- * transformation methods are why this class is a tree transformer and not
22
- * just a tree traverser.
23
- *
24
- * A typical tree traversal looks like this:
25
- *
26
- * new TreeTransformer(root).traverse((node, state, content) => {
27
- * let parent = state.parent();
28
- * let previous = state.previousSibling();
29
- * // etc.
30
- * });
31
- *
32
- * The traverse() method descends through nodes and arrays of nodes and calls
33
- * the traverse callback on each node on the way back up to the root of the
34
- * tree. (Note that it only calls the callback on the nodes themselves, not
35
- * any arrays that contain nodes.) A node is loosely defined as any object
36
- * with a string-valued `type` property. Objects that do not have a type
37
- * property are assumed to not be part of the tree and are not traversed. When
38
- * traversing an array, all elements of the array are examined, and any that
39
- * are nodes or arrays are recursively traversed. When traversing a node, all
40
- * properties of the object are examined and any node or array values are
41
- * recursively traversed. In typical parse trees, the children of a node are
42
- * in a `children` or `content` array, but this class is designed to handle
43
- * more general trees. The Perseus markdown parser, for example, produces
44
- * nodes of type "table" that have children in the `header` and `cells`
45
- * properties.
46
- *
47
- * CAUTION: the traverse() method does not make any attempt to detect
48
- * cycles. If you call it on a cyclic graph instead of a tree, it will cause
49
- * infinite recursion (or, more likely, a stack overflow).
50
- *
51
- * TODO(davidflanagan): it probably wouldn't be hard to detect cycles: when
52
- * pushing a new node onto the containers stack we could just check that it
53
- * isn't already there.
54
- *
55
- * If a node has a text-valued `content` property, it is taken to be the
56
- * plain-text content of the node. The traverse() method concatenates these
57
- * content strings and passes them to the traversal callback for each
58
- * node. This means that the callback has access the full text content of its
59
- * node and all of the nodes descendants.
60
- *
61
- * See the TraversalState class for more information on what information and
62
- * methods are available to the traversal callback.
63
- */
64
- export type TreeNode = {|
65
- type: string,
66
- |};
67
- export type TraversalCallback = (
68
- node: TreeNode,
69
- state: TraversalState,
70
- content: string
71
- ) => void;
72
- declare export default class TreeTransformer {
73
- root: TreeNode;
74
- constructor(root: TreeNode): this;
75
- static isNode(n: any): boolean;
76
- static isTextNode(n: any): boolean;
77
- traverse(f: TraversalCallback): void;
78
- _traverse(
79
- n: TreeNode | Array<TreeNode>,
80
- state: TraversalState,
81
- f: TraversalCallback
82
- ): string;
83
- }
84
- /**
85
- * This class represents the state of a tree traversal. An instance is created
86
- * by the traverse() method of the TreeTransformer class to maintain the state
87
- * for that traversal, and the instance is passed to the traversal callback
88
- * function for each node that is traversed. This class is not intended to be
89
- * instantiated directly, but is exported so that its type can be used for
90
- * Flow annotaions.
91
- */
92
- declare export class TraversalState {
93
- root: TreeNode;
94
- _currentNode: TreeNode | null | void;
95
- _containers: Stack<TreeNode | Array<TreeNode>>;
96
- _indexes: Stack<string | number>;
97
- _ancestors: Stack<TreeNode>;
98
- constructor(root: TreeNode): this;
99
-
100
- /**
101
- * Return the current node in the traversal. Any time the traversal
102
- * callback is called, this method will return the name value as the
103
- * first argument to the callback.
104
- */
105
- currentNode(): TreeNode;
106
-
107
- /**
108
- * Return the parent of the current node, if there is one, or null.
109
- */
110
- parent(): TreeNode | null | void;
111
-
112
- /**
113
- * Return an array of ancestor nodes. The first element of this array is
114
- * the same as this.parent() and the last element is the root node. If we
115
- * are currently at the root node, the the returned array will be empty.
116
- * This method makes a copy of the internal state, so modifications to the
117
- * returned array have no effect on the traversal.
118
- */
119
- ancestors(): $ReadOnlyArray<TreeNode>;
120
-
121
- /**
122
- * Return the next sibling of this node, if it has one, or null otherwise.
123
- */
124
- nextSibling(): TreeNode | null | void;
125
-
126
- /**
127
- * Return the previous sibling of this node, if it has one, or null
128
- * otherwise.
129
- */
130
- previousSibling(): TreeNode | null | void;
131
-
132
- /**
133
- * Remove the next sibling node (if there is one) from the tree. Returns
134
- * the removed sibling or null. This method makes it easy to traverse a
135
- * tree and concatenate adjacent text nodes into a single node.
136
- */
137
- removeNextSibling(): TreeNode | null | void;
138
-
139
- /**
140
- * Replace the current node in the tree with the specified nodes. If no
141
- * nodes are passed, this is a node deletion. If one node (or array) is
142
- * passed, this is a 1-for-1 replacement. If more than one node is passed
143
- * then this is a combination of deletion and insertion. The new node or
144
- * nodes will not be traversed, so this method can safely be used to
145
- * reparent the current node node beneath a new parent.
146
- *
147
- * This method throws an error if you attempt to replace the root node of
148
- * the tree.
149
- */
150
- replace(...replacements: $ReadOnlyArray<TreeNode>): void;
151
-
152
- /**
153
- * Returns true if the current node has a previous sibling and false
154
- * otherwise. If this method returns false, then previousSibling() will
155
- * return null, and goToPreviousSibling() will throw an error.
156
- */
157
- hasPreviousSibling(): boolean;
158
-
159
- /**
160
- * Modify this traversal state object to have the state it would have had
161
- * when visiting the previous sibling. Note that you may want to use
162
- * clone() to make a copy before modifying the state object like this.
163
- * This mutator method is not typically used during ordinary tree
164
- * traversals, but is used by the Selector class for matching multi-node
165
- * selectors.
166
- */
167
- goToPreviousSibling(): void;
168
-
169
- /**
170
- * Returns true if the current node has an ancestor and false otherwise.
171
- * If this method returns false, then the parent() method will return
172
- * null and goToParent() will throw an error
173
- */
174
- hasParent(): boolean;
175
-
176
- /**
177
- * Modify this object to look like it will look when we (later) visit the
178
- * parent node of this node. You should not modify the instance passed to
179
- * the tree traversal callback. Instead, make a copy with the clone()
180
- * method and modify that. This mutator method is not typically used
181
- * during ordinary tree traversals, but is used by the Selector class for
182
- * matching multi-node selectors that involve parent and ancestor
183
- * selectors.
184
- */
185
- goToParent(): void;
186
-
187
- /**
188
- * Return a new TraversalState object that is a copy of this one.
189
- * This method is useful in conjunction with the mutating methods
190
- * goToParent() and goToPreviousSibling().
191
- */
192
- clone(): TraversalState;
193
-
194
- /**
195
- * Returns true if this TraversalState object is equal to that
196
- * TraversalState object, or false otherwise. This method exists
197
- * primarily for use by our unit tests.
198
- */
199
- equals(that: TraversalState): boolean;
200
- }
201
- /**
202
- * This class is an internal utility that just treats an array as a stack
203
- * and gives us a top() method so we don't have to write expressions like
204
- * `ancestors[ancestors.length-1]`. The values() method automatically
205
- * copies the internal array so we don't have to worry about client code
206
- * modifying our internal stacks. The use of this Stack abstraction makes
207
- * the TraversalState class simpler in a number of places.
208
- */
209
- declare class Stack<T> {
210
- stack: Array<T>;
211
- constructor(array?: $ReadOnlyArray<T> | null): this;
212
-
213
- /**
214
- * Push a value onto the stack.
215
- */
216
- push(v: T): void;
217
-
218
- /**
219
- * Pop a value off of the stack.
220
- */
221
- pop(): T;
222
-
223
- /**
224
- * Return the top value of the stack without popping it.
225
- */
226
- top(): T;
227
-
228
- /**
229
- * Return a copy of the stack as an array
230
- */
231
- values(): $ReadOnlyArray<T>;
232
-
233
- /**
234
- * Return the number of elements in the stack
235
- */
236
- size(): number;
237
-
238
- /**
239
- * Return a string representation of the stack
240
- */
241
- toString(): string;
242
-
243
- /**
244
- * Return a shallow copy of the stack
245
- */
246
- clone(): Stack<T>;
247
-
248
- /**
249
- * Compare this stack to another and return true if the contents of
250
- * the two arrays are the same.
251
- */
252
- equals(that: Stack<T>): boolean;
253
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Flowtype definitions for data
3
- * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.21.0
5
- * @flow
6
- */
7
- export type LinterContextProps = {|
8
- contentType: string,
9
- highlightLint: boolean,
10
- paths: $ReadOnlyArray<string>,
11
- stack: $ReadOnlyArray<string>,
12
- |};
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "exclude": ["dist", "**/*.test.*", "**/*.testdata.*", "**/*.stories.*", "**/*.cypress.*"],
3
- "extends": "../tsconfig-shared.json",
4
- "compilerOptions": {
5
- "outDir": "./dist",
6
- "rootDir": "src",
7
- },
8
- "references": [
9
- {"path": "../perseus-error"},
10
- {"path": "../pure-markdown"},
11
- ]
12
- }