Skip to content

Commit

Permalink
Prevent colon confusion in output parsing
Browse files Browse the repository at this point in the history
By use a magic string that shouldn't appear in code, we
make parsing easier.  Really we should use a parser or
something; but, this is an easy enough fix. 

Fixes mattijn#20
  • Loading branch information
unDeadHerbs committed Oct 3, 2022
1 parent 562ba4a commit b681c96
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pycodestyle_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import logging
import copy
import platform
import pycodestyle as pycodestyle_module
from flake8.api import legacy as flake8_module
from contextlib import redirect_stdout
Expand Down Expand Up @@ -162,7 +163,8 @@ def pycodestyle(line, cell, auto=False):
f.close()
# now we can check the file by name.
# we might be able to use 'stdin', have to check implementation
format = '%(row)d:%(col)d: %(code)s %(text)s'
format_divider = 'FORMAT_DIVIDER'
format = format_divider+'%(row)d'+format_divider'%(col)d'+format_divider+' %(code)s %(text)s'
pycodestyle = pycodestyle_module.StyleGuide(format=format)
# check the filename
pcs_result = pycodestyle.check_files(paths=[f.name])
Expand All @@ -171,8 +173,7 @@ def pycodestyle(line, cell, auto=False):

for line in stdout:
#logger.info(line)
# on windows drive path also contains :
line, col, error = line.split(':')[-4:]
line, col, error = line.split(format_divider,3)[:1]
# do not subtract 1 for line for %%pycodestyle, inc pre py3.6 string
if auto:
add = -1
Expand Down

0 comments on commit b681c96

Please sign in to comment.