Skip to content

Commit dd75007

Browse files
committed
Fix linting errors in question-validator.ts
- Remove unnecessary conditional checks for correctAnswer - correctAnswer is now guaranteed to be enum ['A', 'B', 'C', 'D'] by schema - Clean up redundant null/undefined checks - All TypeScript linting errors resolved
1 parent d666cb4 commit dd75007

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

app/lib/ai/question-validator.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const containsKeyInfo = (text: string, keyInfo: string): boolean => {
5959
const validateAnswerConsistency = (exercise: ExerciseContent): boolean => {
6060
const { correctAnswer, options, relevantText } = exercise;
6161

62-
if (!correctAnswer || !options[correctAnswer as keyof typeof options]) {
62+
// correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
63+
if (!options[correctAnswer as keyof typeof options]) {
6364
return false;
6465
}
6566

@@ -72,7 +73,7 @@ const validateAnswerConsistency = (exercise: ExerciseContent): boolean => {
7273
const validateExplanationConsistency = (exercise: ExerciseContent): boolean => {
7374
const { correctAnswer, allExplanations, options } = exercise;
7475

75-
if (!correctAnswer) return false;
76+
// correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
7677

7778
const correctAnswerText = options[correctAnswer as keyof typeof options];
7879
const correctExplanation = allExplanations[correctAnswer as keyof typeof allExplanations];
@@ -107,7 +108,8 @@ const validateQuestionAnswerCoherence = (exercise: ExerciseContent): boolean =>
107108
const validateSemanticAnswerValidation = (exercise: ExerciseContent): boolean => {
108109
const { correctAnswer, options, relevantText, paragraph } = exercise;
109110

110-
if (!correctAnswer || !options[correctAnswer as keyof typeof options]) {
111+
// correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
112+
if (!options[correctAnswer as keyof typeof options]) {
111113
return false;
112114
}
113115

@@ -136,8 +138,7 @@ export const validateQuestionQuality = (
136138
),
137139
optionsLength: Object.values(exercise.options).map((opt) => opt.length),
138140
relevantTextLength: exercise.relevantText.length,
139-
hasCorrectAnswer:
140-
!!exercise.correctAnswer && ['A', 'B', 'C', 'D'].includes(exercise.correctAnswer),
141+
hasCorrectAnswer: ['A', 'B', 'C', 'D'].includes(exercise.correctAnswer),
141142
allExplanationsPresent:
142143
Object.keys(exercise.allExplanations).length === 4 &&
143144
Object.values(exercise.allExplanations).every((exp) => exp.length > 0),
@@ -255,10 +256,8 @@ export const debugValidationFailure = (exercise: ExerciseContent, reason: string
255256
});
256257

257258
// Show what the correct answer should be based on the text
258-
if (
259-
exercise.correctAnswer &&
260-
exercise.options[exercise.correctAnswer as keyof typeof exercise.options]
261-
) {
259+
// correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
260+
if (exercise.options[exercise.correctAnswer as keyof typeof exercise.options]) {
262261
const correctAnswerText =
263262
exercise.options[exercise.correctAnswer as keyof typeof exercise.options];
264263
console.error(`[ValidationDebug] Correct answer text: "${correctAnswerText}"`);

0 commit comments

Comments
 (0)