def _check_before_comment(commented_map, key_to_check, first=False):
    """Check if commented_map has a comment before key_to_check or not.

    All our default comments are before a key, so we just check for that.

    :param commented_map:
    :type commented_map: ruamel.yaml.comments.CommentedMap
    :param key_to_check:
    :type key_to_check: str
    :param first: True if the key is the first key in the yaml file, as that comment is associated with the file
    and not with the key.
    :type first: bool
    :return: True if there is a comment before a key.
    :rtype: bool
    """
    if first:
        # In the first case, the comment is associated to the CommentedMap, and not to the key.
        comments_list = commented_map.ca.comment
        if not comments_list:
            return False

        # This is the comment structure in ruamel. They don't have any good method for us to check.
        return len(comments_list) > 1 and comments_list[1] and len(comments_list[1]) > 0
    else:
        comments_dict = commented_map.ca.items
        if not comments_dict:
            return False
        if key_to_check in comments_dict:
            comments_list = comments_dict[key_to_check]
            # This is the comment structure in ruamel. They don't have nay good method for us to check.
            if len(comments_list) > 1 and comments_list[1] and len(comments_list[1]) > 0:
                return True
            else:
                return False
        else:
            # No key exists, so no comments.
            return False