-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prework for perseus-linter ticket (#1499)
## Summary: Just trying to tidy up before addressing LEMS-2199 ([followup PR](#1531)) Issue: [LEMS-2199](https://khanacademy.atlassian.net/browse/LEMS-2199) [LEMS-2199]: https://khanacademy.atlassian.net/browse/LEMS-2199?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Author: handeyeco Reviewers: SonicScrewdriver, benchristel, handeyeco Required Reviewers: Approved By: SonicScrewdriver, benchristel Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1499
- Loading branch information
Showing
13 changed files
with
236 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus-linter": minor | ||
--- | ||
|
||
Add expression-widget lint rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus-linter": patch | ||
--- | ||
|
||
Cleaning up some types in perseus-linter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Rule from "../rule"; | ||
|
||
function buttonNotInButtonSet(name: string, set: string): string { | ||
return `Answer requires a button not found in the button sets: ${name} (in ${set})`; | ||
} | ||
|
||
const stringToButtonSet = { | ||
"\\sqrt": "prealgebra", | ||
"\\sin": "trig", | ||
"\\cos": "trig", | ||
"\\tan": "trig", | ||
"\\log": "logarithms", | ||
"\\ln": "logarithms", | ||
}; | ||
|
||
/** | ||
* Rule to make sure that Expression questions that require | ||
* a specific math symbol to answer have that math symbol | ||
* available in the keypad (desktop learners can use a keyboard, | ||
* but mobile learners must use the MathInput keypad) | ||
*/ | ||
export default Rule.makeRule({ | ||
name: "expression-widget", | ||
severity: Rule.Severity.WARNING, | ||
selector: "widget", | ||
lint: function (state, content, nodes, match, context) { | ||
// This rule only looks at image widgets | ||
if (state.currentNode().widgetType !== "expression") { | ||
return; | ||
} | ||
|
||
const nodeId = state.currentNode().id; | ||
if (!nodeId) { | ||
return; | ||
} | ||
|
||
// If it can't find a definition for the widget it does nothing | ||
const widget = context?.widgets?.[nodeId]; | ||
if (!widget) { | ||
return; | ||
} | ||
|
||
const answers = widget.options.answerForms; | ||
const buttons = widget.options.buttonSets; | ||
for (const answer of answers) { | ||
for (const [str, set] of Object.entries(stringToButtonSet)) { | ||
if (answer.value.includes(str) && !buttons.includes(set)) { | ||
return buttonNotInButtonSet(str, set); | ||
} | ||
} | ||
} | ||
}, | ||
}) as Rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.