function validateExclusivePathTypeField()

in src/validation/validateStates.ts [123:147]


function validateExclusivePathTypeField(
  stateNode: ObjectASTNode,
  propertyName: string,
  document: TextDocument,
): Diagnostic[] {
  let diagnostics: Diagnostic[] = []

  const pathFieldName = `${propertyName}Path`
  const pathNode = findPropChildByName(stateNode, pathFieldName)

  if (pathNode) {
    const validatePathFieldDiagnostics = validatePathField(pathNode, document)
    diagnostics = diagnostics.concat(validatePathFieldDiagnostics)

    // Myfield and MyfieldPath are mutually exclusive
    if (findPropChildByName(stateNode, propertyName)) {
      const { length, offset } = pathNode
      const range = Range.create(document.positionAt(offset), document.positionAt(offset + length))
      const errorMessage = `You cannot set both ${propertyName} and ${pathFieldName} at the same time.`
      diagnostics.push(Diagnostic.create(range, errorMessage, DiagnosticSeverity.Error))
    }
  }

  return diagnostics
}