Parse python code, for specific pep8 issues I am aware, that libraries exist for parsing python code, however, for the sake of learning how they parse errors, I'm creating a script that checks a file for only 6 Pep8 errors just for reference.
This is how my current 6 Pep8 functions look (they append an issue to the issues list if the issue was found)
&quot;&quot;&quot;
[S001] Line is longer than 79 characters
[S002] Indentation is not a multiple of four
[S003] Unnecessary semicolon after a statement (note, semicolons are admissible in comments)
[S004] At least two spaces before inline comments required
[S005] TODO found (only in comments; the case does not matter)
[S006] More than two blank lines used before this line (must be output for the first non-empty line)
&quot;&quot;&quot;
def S001(self, ln_num: int, line: str):
    if len(line) &gt; 79:
        self.issues.append(f&quot;Line {ln_num}: S001 Too Long&quot;)


def S002(self, ln_num: int, line: str):
    indentation_length = len(line) - len(line.lstrip())
    if indentation_length % 4 != 0:
        self.issues.append(f&quot;Line {ln_num}: S002 Indentation is not a multiple of four&quot;)


def S003(self, ln_num: int, line: str):
    regex1 = re.compile(&quot;(.*)((;(\s)*#)|(;$))&quot;)
    regex2 = re.compile(&quot;#.*;&quot;)
    if regex1.search(line) and not regex2.search(line):
        self.issues.append(f&quot;Line {ln_num}: S003 Unnecessary semicolon&quot;)


def S004(self, ln_num: int, line: str):
    regex = re.compile(&quot;(([^ ]{2})|(\s[^ ])|([^ ]\s))#&quot;)
    if regex.search(line):
        self.issues.append(f&quot;Line {ln_num}: S004 At least two spaces before inline comments required&quot;)


def S005(self, ln_num: int, line: str):
    regex =  re.compile(&quot;#(.*)todo&quot;, flags=re.IGNORECASE)
    if regex.search(line):
        self.issues.append(f&quot;Line {ln_num}: S005 TODO found&quot;)


def S006(self, ln_num: int, line: str):
    if self.code[ln_num-4:ln_num-1] == ['', '', ''] and line != &quot;&quot;:
        self.issues.append(f&quot;Line {ln_num}: S006 More than two blank lines used before this line&quot;)

Testcases:
&quot;&quot;&quot; Test case 1 &quot;&quot;&quot;
print('What\'s your name?') # reading an input
name = input();
print(f'Hello, {name}');  # here is an obvious comment: this prints greeting with a name


very_big_number = 11_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000
print(very_big_number)



def some_fun():
    print('NO TODO HERE;;')
    pass; # Todo something
&quot;&quot;&quot; END &quot;&quot;&quot;

&quot;&quot;&quot; Test Case 2 &quot;&quot;&quot;
print('hello')
print('hello');
print('hello');;;
print('hello');  # hello
# hello hello hello;
greeting = 'hello;'
print('hello')  # ;
&quot;&quot;&quot; END &quot;&quot;&quot;

&quot;&quot;&quot; Test Case 3 &quot;&quot;&quot;
    print('hello')
    print('hello')  # TODO
    print('hello')  # TODO # TODO
    # todo
    # TODO just do it
    print('todo')
    print('TODO TODO')
    todo()
    todo = 'todo'
&quot;&quot;&quot; END &quot;&quot;&quot;

&quot;&quot;&quot; Test Case 4 &quot;&quot;&quot;
print(&quot;hello&quot;)


print(&quot;bye&quot;)



print(&quot;check&quot;)
&quot;&quot;&quot; END &quot;&quot;&quot;

&quot;&quot;&quot; Test Case 5 &quot;&quot;&quot;
print('hello!')
# just a comment
print('hello!')  #
print('hello!')  # hello

print('hello!') # hello
print('hello!')# hello
&quot;&quot;&quot; END &quot;&quot;&quot;


Testcase 1 Expected Output:
Line 1: S004 At least two spaces before inline comment required
Line 2: S003 Unnecessary semicolon
Line 3: S001 Too long
Line 3: S003 Unnecessary semicolon
Line 6: S001 Too long
Line 11: S006 More than two blank lines used before this line
Line 13: S003 Unnecessary semicolon
Line 13: S004 At least two spaces before inline comment required
Line 13: S005 TODO found

I am aware my code, is not optimal and doesn't satisfy every edge case, but I want an idea, on how they parse the errors properly. I would like improvements or better ideas on how to parse for errors since I personally don't like my answers.
When I copy&amp;paste your code into my editor, it immediately greets me with 50 errors and warnings. To be fair, some of these are duplicates, because I have multiple linters configured. However, well over 20 of those are real. And ironically, at least 6 of those would have been reported by your own code!
PEP8 violations

Maximum line length
Blank lines (after the module docstring before the first method)
Single space around operators
Function names should be lower_snake_case

Missing import
You are missing the import for re.
Missing definitions
You are missing the definitions for issues and code.
Invalid escape sequence
\ is the escape character in string literals, therefore \s is interpreted as an escape sequence, but it is not a valid escape sequence. If you want to have a literal backslash in your string, you need to escape it with another backslash: \\s.
Missing docstrings
All of your functions are missing docstrings.
Naming
regex, regex1, and regex2 are not very descriptive names.
Bugs
S001 should use 72 as the maximum line length for docstrings and comments, and only use 79 for code. Also, there is a problem with PEP8 itself: it limits the line length to 79/72 characters, but it should instead limit the line length to 79/72 columns. There are characters that take up 2 columns, and there are characters that take up 0 columns. Your code uses characters, as specified by PEP8, so it is correct as far as PEP8 is concerned, but columns would make more sense.
S003 will incorrectly flag this:
&quot;&quot;&quot;
;
&quot;&quot;&quot;

S004 will incorrectly flag this:
&quot; #&quot;

S005 will incorrectly flag this:
&quot;# TODO&quot;