Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ Before using this plugin, ensure that `phpcs` is installed on your system, prefe
- SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html
- Linter settings: http://sublimelinter.com/en/latest/linter_settings.html

Use the `"args"` setting to configure the coding standard, and/or to display the sniff codes for each error:
Use the `"args"` setting to configure the coding standard, if you've not done so via [configuration file](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset).

```json
{
"args": [
"--standard=PEAR", // code standard
"-s" // display sniff codes
]
}
```
Expand Down
19 changes: 16 additions & 3 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from SublimeLinter.lint import ComposerLinter
import json
from SublimeLinter.lint import LintMatch, ComposerLinter


class Phpcs(ComposerLinter):
cmd = ('phpcs', '--report=emacs', '${args}', '-')
regex = r'^.*:(?P<line>[0-9]+):(?P<col>[0-9]+): (?:(?P<error>error)|(?P<warning>warning)) - (?P<message>(.(?!\(\S+\)$))+)( \((?P<code>\S+)\)$)?' # noqa: E501
cmd = ('phpcs', '--report=json', '${args}', '-')
defaults = {
'selector': 'embedding.php, source.php - text.blade',
# we want auto-substitution of the filename,
# but `cmd` does not support that yet
'--stdin-path=': '${file}'
}

def find_errors(self, output):
data = json.loads(output)
for file_path, file_data in data["files"].items():
for error in file_data['messages']:
yield LintMatch(
filename=file_path,
line=error['line'] - 1,
col=error['column'] - 1,
error_type=error['type'].lower(),
code=error['source'],
message=error['message'],
)