- Code: Select all
import sublime, sublimeplugin
# phpcs.py
# This is a terribly simple plugin. Running it will call PHP Codesniffer
# and validate your PHP code against the Codesniffer's version of the
# Zend Standards. Output will be shown in the console.
#
# TODO: It should, in theory, be possible to automatically correct certain
# errors by parsing the resulting text from phpcs and applying basic
# string replacements on the correct lines- for example converting
# 56 | ERROR | Opening brace should be on a new line
# to a regex on line 56 to turn ...){... to ...) {...
#
# See http://pear.php.net/package/PHP_CodeSniffer/
class PhpcsCommand(sublimeplugin.TextCommand):
def run(self, view, args):
view.window().runCommand("save")
cmd = "phpcs --standard=Zend " + view.fileName()
view.window().runCommand("exec",["",cmd])
Also, I happen to prefer having this bound to F8 as such:
- Code: Select all
<binding key="f8" command="phpcs" />
Another point of improvement could be to add parameters/ multiple bindings to allow users to validate against multiple standards they may have installed.