<reponame>yrom1/sqlint
"""SQL reserved words style checker. 
The rule: Use uppercase for SQL reserved keywords.
"""

import re
from typing import List, Tuple
from lints.common import remove_multiline_comments, remove_dashdash_comments, remove_punctuation, remove_spacing, find_lowercase_sql_keywords


def main(query: str) -> List[Tuple[int, str, str]]:
    output = []
    original_query = query
    query = remove_multiline_comments(query)
    query = remove_dashdash_comments(query)
    query = remove_punctuation(query)
    query = remove_spacing(query)
    lowercase_keywords = find_lowercase_sql_keywords(query)
    set_lowercase_keywords = set(lowercase_keywords)
    for keyword in set_lowercase_keywords:
        p = re.compile(r'\b' + keyword + r'\b')
        m = p.finditer(original_query)
        for i in m:
            p2 = re.compile('\n')
            m2 = p2.findall(original_query[0:i.start()])
            line_number = len(m2) + 1
            output.append(tuple([line_number, i.group(), 'Lowercased reserved word.']))
    return output


if __name__ == '__main__':
    pass

"""SQL reserved words style checker. 
The rule: Use uppercase for SQL reserved keywords.
"""

import re
from typing import List, Tuple
from lints.common import remove_multiline_comments, remove_dashdash_comments, remove_punctuation, remove_spacing, find_lowercase_sql_keywords


def main(query: str) -> List[Tuple[int, str, str]]:
    output = []
    original_query = query
    query = remove_multiline_comments(query)
    query = remove_dashdash_comments(query)
    query = remove_punctuation(query)
    query = remove_spacing(query)
    lowercase_keywords = find_lowercase_sql_keywords(query)
    set_lowercase_keywords = set(lowercase_keywords)
    for keyword in set_lowercase_keywords:
        p = re.compile(r'\b' + keyword + r'\b')
        m = p.finditer(original_query)
        for i in m:
            p2 = re.compile('\n')
            m2 = p2.findall(original_query[0:i.start()])
            line_number = len(m2) + 1
            output.append(tuple([line_number, i.group(), 'Lowercased reserved word.']))
    return output


if __name__ == '__main__':
    pass
SQL reserved words style checker.  The rule: Use uppercase for SQL reserved keywords.