Skip to content

Instantly share code, notes, and snippets.

@gh640
Last active October 4, 2015 04:51
Show Gist options
  • Save gh640/32e731cf4c28203cc432 to your computer and use it in GitHub Desktop.
Save gh640/32e731cf4c28203cc432 to your computer and use it in GitHub Desktop.
SublimeLinter - phpmd linter file for Sublime Text 2
# coding: utf-8
"""
A phpmd linter for Sublime Text 2.
Since [SublimeLinter-phpmd](https://github.com/SublimeLinter/SublimeLinter-phpmd)
is made only for ST3 and cannot be used for ST2 and I maded this one.
Installation:
1. Setup phpmd.
composer g require phpmd/phpmd
2. Download this file and change set executable to proper path.
'executable': '/Users/your_username_here/.composer/vendor/bin/phpmd',
3. Put this file into
- Mac: $HOME/Library/Application\ Support/Sublime\ Text\ 2/Packages/SublimeLinter/sublimelinter/modules
- Windows: ?
4. Done! You can see phpmd hint in php files.
"""
import re
from base_linter import BaseLinter
CONFIG = {
'language': 'PHP',
# !! Change this value to your phpmd path.
'executable': '/Users/your_username_here/.composer/vendor/bin/phpmd',
# Include all the rulesets.
'lint_args': ['{filename}', 'text', 'cleancode,codesize,controversial,design,naming,unusedcode']
}
class Linter(BaseLinter):
def parse_errors(self, view, errors, lines, errorUnderlines, violationUnderlines, warningUnderlines, errorMessages, violationMessages, warningMessages):
print(errors)
for line in errors.splitlines():
match = re.match(r'^(?P<filename>[^\:]+):(?P<line>\d+)\s*(?P<error>.+)', line)
if match:
error, line = match.group('error'), match.group('line')
self.add_message(int(line), lines, error, errorMessages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment