@khanacademy/perseus-linter 5.3.1 → 5.4.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/dist/es/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-utils';
2
- import { PerseusError, Errors, CoreWidgetRegistry, makeSafeUrl } from '@khanacademy/perseus-core';
2
+ import { PerseusError, Errors, CoreWidgetRegistry, makeSafeUrl, SORTER_MAX_CARDS } from '@khanacademy/perseus-core';
3
3
  import * as KAS from '@khanacademy/kas';
4
4
  import { parse, traverseContent } from '@khanacademy/pure-markdown';
5
5
  import { vector } from '@khanacademy/kmath';
6
6
 
7
- const libName="@khanacademy/perseus-linter";const libVersion="5.3.1";addLibraryVersionToPerseusDebug(libName,libVersion);
7
+ const libName="@khanacademy/perseus-linter";const libVersion="5.4.1";addLibraryVersionToPerseusDebug(libName,libVersion);
8
8
 
9
9
  const linterContextDefault={contentType:"",highlightLint:false,stack:[]};
10
10
 
@@ -139,9 +139,9 @@ var PythonProgramWidgetError = Rule.makeRule({name:"python-program-widget-error"
139
139
 
140
140
  var RadioWidgetError = Rule.makeRule({name:"radio-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="radio"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const choices=widget.options.choices;if(!choices.some(choice=>choice.correct)){return "No choice is marked as correct."}const correctChoices=choices.filter(choice=>choice.correct);const hasNotaCorrect=correctChoices.some(choice=>choice.isNoneOfTheAbove);if(hasNotaCorrect&&correctChoices.length>1){return "Cannot mark both None of the Above and another choice as correct."}return}});
141
141
 
142
- const minCards=2;var SorterWidgetError = Rule.makeRule({name:"sorter-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const correct=widget.options.correct??[];if(correct.length<minCards){warnings.push(`Sorter requires at least ${minCards} cards.`);}if(correct.some(card=>card.trim()==="")){warnings.push("Sorter cards cannot be blank.");}return warnings.join("\n\n")}});
142
+ const minCards=2;function hasMixedContent(card){const contentNodes=[];traverseContent(parse(card.trim(),{}),node=>{if(node.type!=="paragraph"){contentNodes.push(node);}});return contentNodes.length>1&&contentNodes.some(node=>node.type==="image")}var SorterWidgetError = Rule.makeRule({name:"sorter-widget-error",severity:Rule.Severity.ERROR,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const correct=widget.options.correct??[];if(correct.length<minCards){warnings.push(`Sorter requires at least ${minCards} cards.`);}if(correct.some(card=>card.trim()==="")){warnings.push("Sorter cards cannot be blank.");}if(correct.some(hasMixedContent)){warnings.push("Sorter cards cannot mix images with other content.");}return warnings.join("\n\n")}});
143
143
 
144
- const sorterMaxCards=10;const sorterMaxIdealCards=5;const sorterMaxHorizontalCards=5;var SorterWidgetWarning = Rule.makeRule({name:"sorter-widget-warning",severity:Rule.Severity.WARNING,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const options=widget.options;const{layout,correct=[]}=options;if(correct.length>sorterMaxCards){warnings.push(`Sorter cannot have more than ${sorterMaxCards} cards.`);}if(layout==="horizontal"&&correct.length>sorterMaxHorizontalCards){warnings.push(`Sorter cannot have more than ${sorterMaxHorizontalCards} cards in horizontal layout.`);}if(correct.length>sorterMaxIdealCards){warnings.push(`Having more than ${sorterMaxIdealCards} cards in Sorter is discouraged.`);}return warnings.join("\n\n")}});
144
+ const sorterMaxIdealCards=5;const sorterMaxHorizontalCards=5;var SorterWidgetWarning = Rule.makeRule({name:"sorter-widget-warning",severity:Rule.Severity.WARNING,selector:"widget",lint:function(state,content,nodes,match,context){if(state.currentNode().widgetType!=="sorter"){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}const warnings=[];const options=widget.options;const{layout,correct=[]}=options;if(correct.length>SORTER_MAX_CARDS){warnings.push(`Sorter cannot have more than ${SORTER_MAX_CARDS} cards.`);}if(layout==="horizontal"&&correct.length>sorterMaxHorizontalCards){warnings.push(`Sorter cannot have more than ${sorterMaxHorizontalCards} cards in horizontal layout.`);}if(correct.length>sorterMaxIdealCards){warnings.push(`Having more than ${sorterMaxIdealCards} cards in Sorter is discouraged.`);}return warnings.join("\n\n")}});
145
145
 
146
146
  var StaticWidgetInQuestionStem = Rule.makeRule({name:"static-widget-in-question-stem",severity:Rule.Severity.WARNING,selector:"widget",lint:(state,content,nodes,match,context)=>{if(context?.contentType!=="exercise"){return}if(context.stack.includes("hint")){return}const nodeId=state.currentNode().id;if(!nodeId){return}const widget=context?.widgets?.[nodeId];if(!widget){return}if(widget.static){return `Widget in question stem is static (non-interactive).`}}});
147
147