Skip to content

Commit

Permalink
Add support for default config files (phpcs.xml)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmadrid committed Sep 5, 2016
1 parent 982dda3 commit e17cf93
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions phpcs.py
Expand Up @@ -139,6 +139,12 @@ class ShellCommand():
def __init__(self):
self.error_list = []

# Default the working directory for the shell command to the user's home dir.
self.workingDir = expanduser("~")

def setWorkingDir(self, dir):
self.workingDir = dir

def get_errors(self, path):
self.execute(path)
return self.error_list
Expand All @@ -162,15 +168,8 @@ def shell_out(self, cmd):
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

"""
Fixes the fact that PHP_CodeSniffer now caches the reports to cwd()
- http://pear.php.net/package/PHP_CodeSniffer/download/1.5.0
- https://github.com/benmatselby/sublime-phpcs/issues/68
"""
home = expanduser("~")
debug_message("cwd: " + home)

proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=info, cwd=home)
debug_message("cwd: " + self.workingDir)
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=info, cwd=self.workingDir)


if proc.stdout:
Expand Down Expand Up @@ -218,7 +217,13 @@ def execute(self, path):
arg += "=" + value
args.append(arg)

args.append(os.path.normpath(path))
target = os.path.normpath(path)

# Set the working directory for the command to the path of the target file, allowing
# phpcs the opportunity to find a default configuration file (phpcs.xml) in the file's path.
self.setWorkingDir(os.path.dirname(target))

args.append(target)
self.parse_report(args)

def parse_report(self, args):
Expand Down

0 comments on commit e17cf93

Please sign in to comment.