Browse files

php-cs-fixer support for directories

  • Loading branch information...
1 parent 81a803c commit d386906c59d07dd6578313d99498625cfb787ade @benmatselby committed May 24, 2012
Showing with 70 additions and 18 deletions.
  1. +5 −0 Changelog.md
  2. +5 −5 Context.sublime-menu
  3. +4 −4 Default.sublime-commands
  4. +3 −3 Main.sublime-menu
  5. +10 −0 Side Bar.sublime-menu
  6. +43 −6 phpcs.py
View
5 Changelog.md
@@ -1,6 +1,11 @@
Sublime PHP CodeSniffer, Linter and Mess Detector Plugin Changelog
==================================================================
+4.1
+---
+* Added support to use php-cs-fixer on a directory in the side bar
+* Now displays the php-cs-fixer changes in the quick panel
+
4.0
---
* Added basic support for [php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer) based on the work by [Jeremy Romey](https://github.com/jeremyFreeAgent/sublime-php-cs-fixer/)
View
10 Context.sublime-menu
@@ -1,13 +1,13 @@
[
{ "caption": "-" },
{
- "caption": "PHP CodeSniffer",
+ "caption": "PHP Code Sniffer",
"children":
[
- { "command": "phpcs_sniff_this_file" },
- { "command": "phpcs_show_previous_errors" },
- { "command": "phpcs_clear_sniffer_marks" },
- { "command": "phpcs_fix_this_file" }
+ { "command": "phpcs_sniff_this_file", "caption": "Sniff this file" },
+ { "command": "phpcs_show_previous_errors", "caption": "Show previous errors" },
+ { "command": "phpcs_clear_sniffer_marks", "caption": "Clear sniffer marks" },
+ { "command": "phpcs_fix_this_file", "caption": "Fix this file (PHP-CS-Fixer)" }
]
}
]
View
8 Default.sublime-commands
@@ -1,18 +1,18 @@
[
{
- "caption": "PHP CodeSniffer: Sniff This File",
+ "caption": "PHP Code Sniffer: Sniff this file",
"command": "phpcs_sniff_this_file"
},
{
- "caption": "PHP CodeSniffer: Clear Sniffer Marks",
+ "caption": "PHP Code Sniffer: Clear sniffer marks",
"command": "phpcs_clear_sniffer_marks"
},
{
- "caption": "PHP CodeSniffer: Show Previous Errors",
+ "caption": "PHP Code Sniffer: Show previous errors",
"command": "phpcs_show_previous_errors"
},
{
- "caption": "PHP CodeSniffer Fixer: Fix This File",
+ "caption": "PHP Code Sniffer Fixer: Fix this file",
"command": "phpcs_fix_this_file"
}
]
View
6 Main.sublime-menu
@@ -5,9 +5,9 @@
"children":
[
{
- "caption": "PHP CodeSniffer...",
+ "caption": "PHP Code Sniffer...",
"command": "show_overlay",
- "args": {"overlay": "command_palette", "text": "PHP CodeSniffer: " }
+ "args": {"overlay": "command_palette", "text": "PHP Code Sniffer: " }
}
]
},
@@ -24,7 +24,7 @@
"children":
[
{
- "caption": "PHP CodeSniffer",
+ "caption": "PHP Code Sniffer",
"children":
[
{
View
10 Side Bar.sublime-menu
@@ -0,0 +1,10 @@
+[
+ { "caption": "-" },
+ {
+ "caption": "PHP Code Sniffer",
+ "children":
+ [
+ { "command": "phpcs_fix_this_directory", "args": { "paths": [] } }
+ ]
+ }
+]
View
49 phpcs.py
@@ -158,6 +158,7 @@ def execute(self, path):
return
args.append("fix")
+ args.append("--verbose")
# Add the additional arguments from the settings file to the command
for key, value in Pref.php_cs_fixer_additional_args.items():
@@ -172,6 +173,11 @@ def execute(self, path):
def parse_report(self, args):
report = self.shell_out(args)
debug_message(report)
+ lines = re.finditer('.*(?P<line>\d+)\) (?P<file>.*)', report)
+
+ for line in lines:
+ error = CheckstyleError(line.group('line'), line.group('file'))
+ self.error_list.append(error)
class MessDetector(ShellCommand):
@@ -316,17 +322,26 @@ def show_quick_panel(self):
self.window.show_quick_panel(self.error_list, self.on_quick_panel_done)
def fix_standards_errors(self, path):
- Fixer().execute(path)
+ self.error_lines = {}
+ self.error_list = []
+ self.report = []
+ fixes = Fixer().get_errors(path)
+
+ for fix in fixes:
+ self.error_list.append(fix.get_message())
+
+ self.show_quick_panel()
def on_quick_panel_done(self, picked):
if picked == -1:
return
- pt = self.report[picked].get_point()
- self.window.active_view().sel().clear()
- self.window.active_view().sel().add(sublime.Region(pt))
- self.window.active_view().show(pt)
- self.set_status_bar()
+ if (len(self.report) > 0):
+ pt = self.report[picked].get_point()
+ self.window.active_view().sel().clear()
+ self.window.active_view().sel().add(sublime.Region(pt))
+ self.window.active_view().show(pt)
+ self.set_status_bar()
def get_errors(self, line):
if not line + 1 in self.error_lines:
@@ -413,6 +428,28 @@ def is_enabled(self):
return False
+class PhpcsFixThisDirectoryCommand(sublime_plugin.WindowCommand):
+ """Command to use php-cs-fixer to 'fix' the directory"""
+ def run(self, paths=[]):
+ cmd = PhpcsCommand.instance(self.window.active_view())
+ cmd.fix_standards_errors(os.path.normpath(paths[0]))
+
+ def is_enabled(self):
+ if Pref.php_cs_fixer_executable_path != '':
+ return True
+ else:
+ return False
+
+ def is_visible(self, paths=[]):
+ if Pref.php_cs_fixer_executable_path != '':
+ return True
+ else:
+ return False
+
+ def description(self, paths=[]):
+ return 'Fix this directory (PHP-CS-Fixer)'
+
+
class PhpcsEventListener(sublime_plugin.EventListener):
"""Event listener for the plugin"""
def on_post_save(self, view):

0 comments on commit d386906

Please sign in to comment.