@khanacademy/perseus-linter 0.0.0-PR862-20231207182234 → 0.0.0-PR875-20250221232857

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 (65) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +7 -0
  3. package/dist/es/index.js +156 -38
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.js +181 -38
  6. package/dist/index.js.map +1 -1
  7. package/dist/proptypes.d.ts +1 -7
  8. package/dist/rule.d.ts +24 -8
  9. package/dist/rules/expression-widget.d.ts +9 -0
  10. package/dist/rules/lint-utils.d.ts +0 -1
  11. package/dist/shared-utils/add-library-version-to-perseus-debug.d.ts +9 -0
  12. package/dist/tree-transformer.d.ts +3 -1
  13. package/package.json +35 -35
  14. package/.eslintrc.js +0 -12
  15. package/CHANGELOG.md +0 -148
  16. package/src/README.md +0 -41
  17. package/src/__tests__/matcher.test.ts +0 -498
  18. package/src/__tests__/rule.test.ts +0 -110
  19. package/src/__tests__/rules.test.ts +0 -548
  20. package/src/__tests__/selector-parser.test.ts +0 -51
  21. package/src/__tests__/tree-transformer.test.ts +0 -444
  22. package/src/index.ts +0 -281
  23. package/src/proptypes.ts +0 -19
  24. package/src/rule.ts +0 -419
  25. package/src/rules/absolute-url.ts +0 -23
  26. package/src/rules/all-rules.ts +0 -71
  27. package/src/rules/blockquoted-math.ts +0 -9
  28. package/src/rules/blockquoted-widget.ts +0 -9
  29. package/src/rules/double-spacing-after-terminal.ts +0 -11
  30. package/src/rules/extra-content-spacing.ts +0 -11
  31. package/src/rules/heading-level-1.ts +0 -13
  32. package/src/rules/heading-level-skip.ts +0 -19
  33. package/src/rules/heading-sentence-case.ts +0 -10
  34. package/src/rules/heading-title-case.ts +0 -68
  35. package/src/rules/image-alt-text.ts +0 -20
  36. package/src/rules/image-in-table.ts +0 -9
  37. package/src/rules/image-spaces-around-urls.ts +0 -34
  38. package/src/rules/image-widget.ts +0 -49
  39. package/src/rules/link-click-here.ts +0 -10
  40. package/src/rules/lint-utils.ts +0 -47
  41. package/src/rules/long-paragraph.ts +0 -13
  42. package/src/rules/math-adjacent.ts +0 -9
  43. package/src/rules/math-align-extra-break.ts +0 -10
  44. package/src/rules/math-align-linebreaks.ts +0 -42
  45. package/src/rules/math-empty.ts +0 -9
  46. package/src/rules/math-font-size.ts +0 -11
  47. package/src/rules/math-frac.ts +0 -9
  48. package/src/rules/math-nested.ts +0 -10
  49. package/src/rules/math-starts-with-space.ts +0 -11
  50. package/src/rules/math-text-empty.ts +0 -9
  51. package/src/rules/math-without-dollars.ts +0 -13
  52. package/src/rules/nested-lists.ts +0 -10
  53. package/src/rules/profanity.ts +0 -9
  54. package/src/rules/table-missing-cells.ts +0 -19
  55. package/src/rules/unbalanced-code-delimiters.ts +0 -13
  56. package/src/rules/unescaped-dollar.ts +0 -9
  57. package/src/rules/widget-in-table.ts +0 -9
  58. package/src/selector.ts +0 -504
  59. package/src/tree-transformer.ts +0 -583
  60. package/src/types.ts +0 -7
  61. package/src/version.ts +0 -10
  62. package/tsconfig-build.json +0 -12
  63. package/tsconfig-build.tsbuildinfo +0 -1
  64. /package/dist/rules/{math-font-size.d.ts → image-url-empty.d.ts} +0 -0
  65. /package/dist/rules/{profanity.d.ts → static-widget-in-question-stem.d.ts} +0 -0
@@ -1,9 +1,3 @@
1
- import PropTypes from "prop-types";
2
1
  import type { LinterContextProps } from "./types";
3
- export declare const linterContextProps: PropTypes.Requireable<PropTypes.InferProps<{
4
- contentType: PropTypes.Requireable<string>;
5
- highlightLint: PropTypes.Requireable<boolean>;
6
- paths: PropTypes.Requireable<(string | null | undefined)[]>;
7
- stack: PropTypes.Requireable<(string | null | undefined)[]>;
8
- }>>;
2
+ export declare const linterContextProps: any;
9
3
  export declare const linterContextDefault: LinterContextProps;
package/dist/rule.d.ts CHANGED
@@ -122,22 +122,37 @@
122
122
  */
123
123
  import Selector from "./selector";
124
124
  import type { TraversalState, TreeNode } from "./tree-transformer";
125
- export type PatternMatchType = any;
126
- export type RuleCheckReturnType = {
125
+ export type MakeRuleOptions = {
126
+ name: string;
127
+ pattern?: RegExp;
128
+ severity?: number;
129
+ selector?: string;
130
+ locale?: string;
131
+ message?: string;
132
+ lint?: (state: TraversalState, content: string, nodes: any, match: any, context: LintRuleContextObject) => string | undefined;
133
+ applies?: AppliesTester;
134
+ };
135
+ type PatternMatchType = any;
136
+ type RuleCheckReturnType = {
127
137
  rule: string;
128
138
  message: string;
129
139
  start: number;
130
140
  end: number;
131
141
  severity?: number;
132
142
  } | null | undefined;
133
- export type LintTesterReturnType = string | {
143
+ type LintTesterReturnType = string | {
134
144
  message: string;
135
145
  start: number;
136
146
  end: number;
137
147
  } | null | undefined;
138
- export type LintRuleContextObject = any | null | undefined;
139
- export type LintTester = (state: TraversalState, content: string, selectorMatch: ReadonlyArray<TreeNode>, patternMatch: PatternMatchType, context: LintRuleContextObject) => LintTesterReturnType;
140
- export type AppliesTester = (context: LintRuleContextObject) => boolean;
148
+ type LintRuleContextObject = {
149
+ content: string;
150
+ contentType: "article" | "exercise";
151
+ stack: string[];
152
+ widgets: any[];
153
+ } | null | undefined;
154
+ type LintTester = (state: TraversalState, content: string, selectorMatch: ReadonlyArray<TreeNode>, patternMatch: PatternMatchType, context: LintRuleContextObject) => LintTesterReturnType;
155
+ type AppliesTester = (context: LintRuleContextObject) => boolean;
141
156
  /**
142
157
  * A Rule object describes a Perseus lint rule. See the comment at the top of
143
158
  * this file for detailed description.
@@ -151,8 +166,8 @@ export default class Rule {
151
166
  applies: AppliesTester;
152
167
  message: string | null | undefined;
153
168
  static DEFAULT_SELECTOR: Selector;
154
- constructor(name: string | null | undefined, severity: number | null | undefined, selector: Selector | null | undefined, pattern: RegExp | null | undefined, lint: LintTester | string, applies: AppliesTester);
155
- static makeRule(options: any): Rule;
169
+ constructor(name: string | null | undefined, severity: number | null | undefined, selector: Selector | null | undefined, pattern: RegExp | null | undefined, lint: LintTester | string | undefined, applies: AppliesTester | undefined);
170
+ static makeRule(options: MakeRuleOptions): Rule;
156
171
  check(node: TreeNode, traversalState: TraversalState, content: string, context: LintRuleContextObject): RuleCheckReturnType;
157
172
  _defaultLintFunction(state: TraversalState, content: string, selectorMatch: ReadonlyArray<TreeNode>, patternMatch: PatternMatchType, context: LintRuleContextObject): {
158
173
  end: number;
@@ -168,3 +183,4 @@ export default class Rule {
168
183
  WARNING: number;
169
184
  };
170
185
  }
186
+ export {};
@@ -0,0 +1,9 @@
1
+ import Rule from "../rule";
2
+ /**
3
+ * Rule to make sure that Expression questions that require
4
+ * a specific math symbol to answer have that math symbol
5
+ * available in the keypad (desktop learners can use a keyboard,
6
+ * but mobile learners must use the MathInput keypad)
7
+ */
8
+ declare const _default: Rule;
9
+ export default _default;
@@ -1,2 +1 @@
1
1
  export declare function getHostname(url: string): string;
2
- export declare function isInternalURL(url: string): boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Adds the given perseus library version information to the __perseus_debug__
3
+ * object and ensures that the object is attached to `globalThis` (`window` in
4
+ * browser environments).
5
+ *
6
+ * This allows each library to provide runtime version information to assist in
7
+ * debugging in production environments.
8
+ */
9
+ export declare const addLibraryVersionToPerseusDebug: (libraryName: string, libraryVersion: string) => void;
@@ -57,8 +57,10 @@
57
57
  **/
58
58
  export type TreeNode = {
59
59
  type: string;
60
+ widgetType?: string;
61
+ id?: string;
60
62
  };
61
- export type TraversalCallback = (node: TreeNode, state: TraversalState, content: string) => void;
63
+ type TraversalCallback = (node: TreeNode, state: TraversalState, content: string) => void;
62
64
  export default class TreeTransformer {
63
65
  root: TreeNode;
64
66
  constructor(root: TreeNode);
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "@khanacademy/perseus-linter",
3
- "description": "Linter engine for Perseus",
4
- "author": "Khan Academy",
5
- "license": "MIT",
6
- "version": "0.0.0-PR862-20231207182234",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/Khan/perseus.git",
13
- "directory": "packages/perseus-linter"
14
- },
15
- "bugs": {
16
- "url": "https://github.com/Khan/perseus/issues"
17
- },
18
- "module": "dist/es/index.js",
19
- "main": "dist/index.js",
20
- "source": "src/index.ts",
21
- "scripts": {
22
- "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
23
- },
24
- "dependencies": {
25
- "@khanacademy/perseus-core": "0.0.0-PR862-20231207182234",
26
- "@khanacademy/perseus-error": "^0.0.0-PR862-20231207182234"
27
- },
28
- "devDependencies": {
29
- "@khanacademy/pure-markdown": "^0.0.0-PR862-20231207182234",
30
- "prop-types": "^15.6.1"
31
- },
32
- "peerDependencies": {
33
- "prop-types": "^15.6.1"
34
- },
35
- "keywords": []
36
- }
2
+ "name": "@khanacademy/perseus-linter",
3
+ "description": "Linter engine for Perseus",
4
+ "author": "Khan Academy",
5
+ "license": "MIT",
6
+ "version": "0.0.0-PR875-20250221232857",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/Khan/perseus.git",
13
+ "directory": "packages/perseus-linter"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/Khan/perseus/issues"
17
+ },
18
+ "module": "dist/es/index.js",
19
+ "main": "dist/index.js",
20
+ "source": "src/index.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@khanacademy/perseus-core": "0.0.0-PR875-20250221232857"
26
+ },
27
+ "devDependencies": {
28
+ "prop-types": "15.6.1",
29
+ "@khanacademy/pure-markdown": "0.0.0-PR875-20250221232857"
30
+ },
31
+ "peerDependencies": {
32
+ "prop-types": "15.6.1"
33
+ },
34
+ "keywords": [],
35
+ "scripts": {}
36
+ }
package/.eslintrc.js DELETED
@@ -1,12 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- /* eslint-disable import/no-commonjs */
3
- const path = require("path");
4
-
5
- module.exports = {
6
- rules: {
7
- "import/no-extraneous-dependencies": [
8
- "error",
9
- {packageDir: [__dirname, path.join(__dirname, "../../")]},
10
- ],
11
- },
12
- };
package/CHANGELOG.md DELETED
@@ -1,148 +0,0 @@
1
- # @khanacademy/perseus-linter
2
-
3
- ## 0.0.0-PR862-20231207182234
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@0.0.0-PR862-20231207182234
9
- - @khanacademy/perseus-error@0.0.0-PR862-20231207182234
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
-
21
- ## 0.3.8
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [[`79403e06`](https://github.com/Khan/perseus/commit/79403e06eedb597d7818d6c858bbba6f51ff3fe1)]:
26
- - @khanacademy/perseus-core@1.3.0
27
- - @khanacademy/perseus-error@0.2.7
28
-
29
- ## 0.3.7
30
-
31
- ### Patch Changes
32
-
33
- - Updated dependencies [[`376eb0e4`](https://github.com/Khan/perseus/commit/376eb0e4aaaa4c7a90fd6107a84bb74d382b077c)]:
34
- - @khanacademy/perseus-core@1.2.0
35
- - @khanacademy/perseus-error@0.2.6
36
-
37
- ## 0.3.6
38
-
39
- ### Patch Changes
40
-
41
- - Updated dependencies [22a9c408]
42
- - @khanacademy/perseus-core@1.1.2
43
- - @khanacademy/perseus-error@0.2.5
44
-
45
- ## 0.3.5
46
-
47
- ### Patch Changes
48
-
49
- - 55d4cd00: Print package name and version when loaded in the page
50
- - Updated dependencies [55d4cd00]
51
- - @khanacademy/perseus-core@1.1.1
52
- - @khanacademy/perseus-error@0.2.4
53
-
54
- ## 0.3.4
55
-
56
- ### Patch Changes
57
-
58
- - 388b6506: Convert runLinter doc comment to /\*\* \*/ format so editors pick it up better (VSCode).
59
- - Updated dependencies [388b6506]
60
- - @khanacademy/perseus-error@0.2.3
61
-
62
- ## 0.3.3
63
-
64
- ### Patch Changes
65
-
66
- - Updated dependencies [a383823d]
67
- - @khanacademy/perseus-error@0.2.2
68
-
69
- ## 0.3.2
70
-
71
- ### Patch Changes
72
-
73
- - ce5e6297: Upgrade wonder-blocks deps to package versions without Flow types
74
-
75
- ## 0.3.1
76
-
77
- ### Patch Changes
78
-
79
- - 1f062e98: Bump all package versions since the build settings have been updated
80
- - Updated dependencies [1f062e98]
81
- - @khanacademy/perseus-error@0.2.1
82
-
83
- ## 0.3.0
84
-
85
- ### Minor Changes
86
-
87
- - 53fd3768: Migrate source code to TypeScript
88
-
89
- ### Patch Changes
90
-
91
- - Updated dependencies [53fd3768]
92
- - @khanacademy/perseus-error@0.2.0
93
-
94
- ## 0.2.5
95
-
96
- ### Patch Changes
97
-
98
- - Updated dependencies [a1b4ab3c]
99
- - @khanacademy/perseus-error@0.1.5
100
-
101
- ## 0.2.4
102
-
103
- ### Patch Changes
104
-
105
- - Updated dependencies [6a7f36be]
106
- - @khanacademy/perseus-error@0.1.4
107
-
108
- ## 0.2.3
109
-
110
- ### Patch Changes
111
-
112
- - f567f660: Update the eslint config to look at both the package.json for the package and the one from the root
113
- - Updated dependencies [f567f660]
114
- - @khanacademy/perseus-error@0.1.3
115
-
116
- ## 0.2.2
117
-
118
- ### Patch Changes
119
-
120
- - bf180fe1: Fix our use of import/no-extraneous-dependencies
121
- - Updated dependencies [bf180fe1]
122
- - @khanacademy/perseus-error@0.1.2
123
-
124
- ## 0.2.1
125
-
126
- ### Patch Changes
127
-
128
- - 98d283ff: Fix storybook
129
- - Updated dependencies [98d283ff]
130
- - @khanacademy/perseus-error@0.1.1
131
-
132
- ## 0.2.0
133
-
134
- ### Minor Changes
135
-
136
- - 2578bd16: Rename NotGorgon to TranslationLinter
137
- - 2578bd16: Rename Gorgon to PerseusLinter
138
-
139
- ## 0.1.0
140
-
141
- ### Minor Changes
142
-
143
- - a4f10ace: Move Gorgon, PerseusError, PureMarkdown into their own packages
144
-
145
- ### Patch Changes
146
-
147
- - Updated dependencies [a4f10ace]
148
- - @khanacademy/perseus-error@0.1.0
package/src/README.md DELETED
@@ -1,41 +0,0 @@
1
- # perseus-linter
2
-
3
- The linter is implemented by the following files:
4
-
5
- tree-transformer.js:
6
-
7
- This file defines a TreeTransformer class for traversing (and
8
- optionally transforming by inserting, reparenting and removing
9
- nodes) markdown parse trees. When traversing a tree, a
10
- TreeTransformer calls the function you specify on each node. This is
11
- a post-order traversal: the function is called on the way back up,
12
- not on the way down. When the function is invoked, it is passed the
13
- current node, a state object, and the concatenated content of the
14
- node and its descendants. The state object is the interesting one:
15
- it is an instance of TraversalState, which is a class defined in
16
- (but not exported by) this same file. TraversalState has an API for
17
- querying the ancestors and siblings of the current node, and also an
18
- API for replacing the current node with a new one.
19
-
20
- selector.js:
21
-
22
- This file defines the Selector class which works like a CSS selector
23
- for markdown parse trees. Selector.parse() converts strings like
24
- "heading + paragraph > text" to Selector objects. A Selector object
25
- has a match() method that tests whether a given node in a parse tree
26
- matches. The match() method takes a TraversalState object as its
27
- argument, so selectors can only be used during a TreeTransformer
28
- traversal.
29
-
30
- rule.js:
31
-
32
- This file defines the Rule class which represents a single lint
33
- rule. A Rule object has a check() method that takes the same (node,
34
- state, content) arguments that a TreeTransformer passes to the
35
- traversal callback function. Rules can have a selector, a regular
36
- expression, and a function. If a node matches the selector and its
37
- content matches the regular expression, then the function is called
38
- to check the node and return a warning message if the node does, in
39
- fact, have lint.
40
-
41
- See the individual file for additional documentation.