def line_length(line, tab_width):
    """Calculate the length of a line taking TABs into account.

    :param str line: line of code
    :param int tab_width: tab width

    :returns: The length of the line
    :rtype: int

    """
    length = 0
    for i in line:
        if i == '\t':
            length = (length + tab_width) // tab_width * tab_width
        else:
            length += 1
    return length
