This repository was archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhpcsfixerCommand.py
53 lines (43 loc) · 1.54 KB
/
PhpcsfixerCommand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import sublime
import subprocess
import sublime_plugin
def phpcsfix(view):
path = view.file_name()
conf = sublime.load_settings('phpcsfixer.sublime-settings')
# The command line params
cmd = [
conf.get('phpcsfixer_php_path'),
conf.get('phpcsfixer_phar_path'),
"fix",
path
]
# Append extra options if any
for key, value in conf.get('phpcsfixer_options').items():
arg = key
if value != "":
arg += "=" + value
cmd.append(arg)
# Info for winOS
info = None
if os.name == 'nt':
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=info)
if proc.stdout:
data = proc.communicate()[0]
return True
class PhpcsfixerCommand(sublime_plugin.TextCommand):
"""A minimal PHP cs fixer plugin for sublime - by Jitendra Adhikari"""
def run(self, edit):
return phpcsfix(self.view)
def is_enabled(self):
ext = os.path.splitext(self.view.file_name())[1]
conf = sublime.load_settings('phpcsfixer.sublime-settings')
return ext[1:] in conf.get('phpcsfixer_file_extensions')
class RunFixerOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
conf = sublime.load_settings('phpcsfixer.sublime-settings')
if conf.get('phpcsfixer_fix_on_save'):
return phpcsfix(view)