yaml-validator icon indicating copy to clipboard operation
yaml-validator copied to clipboard

Simple typo-detection by matching MissingField with ExtraField

Open MathiasPius opened this issue 5 years ago • 1 comments

Misspelling a field in a strictly typed object presently results in a SchemaError::Multiple(FieldMissing, ExtraField) error. It would be cool to do some simple levenshtein distance on these two field names to suggest a typo was made if the similarity is high.

SchemaError { 
  kind: Multiple { 
  errors: [
    SchemaError { 
      kind: FieldMissing { field: "not" }, 
    }, 
    SchemaError { 
      kind: ExtraField { field: "note" },
    }
  ]
}

Would thereby be transformed into:

SchemaError { 
  kind: Typo { 
    extected: "not",
    found: "note",
  }
}

MathiasPius avatar May 13 '20 21:05 MathiasPius

This should probably be implemented in the CLI-tool instead of in the library itself, since there's no reason to increase the possible number of error cases to handle, and it is mostly an aesthetic improvement.

MathiasPius avatar May 13 '20 21:05 MathiasPius