Skip to content

Commit 0e5f01c

Browse files
authored
Merge pull request #56 from SublimeLinter/checkstyle
add error code, aka "source" to the output
2 parents e356ce2 + 1337322 commit 0e5f01c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ Before using this plugin, ensure that `phpcs` is installed on your system, prefe
2121
- SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html
2222
- Linter settings: http://sublimelinter.com/en/latest/linter_settings.html
2323

24-
Use the `"args"` setting to configure the coding standard, and/or to display the sniff codes for each error:
24+
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).
2525

2626
```json
2727
{
2828
"args": [
2929
"--standard=PEAR", // code standard
30-
"-s" // display sniff codes
3130
]
3231
}
3332
```

linter.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
from SublimeLinter.lint import ComposerLinter
1+
import json
2+
from SublimeLinter.lint import LintMatch, ComposerLinter
23

34

45
class Phpcs(ComposerLinter):
5-
cmd = ('phpcs', '--report=emacs', '${args}', '-')
6-
regex = r'^.*:(?P<line>[0-9]+):(?P<col>[0-9]+): (?:(?P<error>error)|(?P<warning>warning)) - (?P<message>(.(?!\(\S+\)$))+)( \((?P<code>\S+)\)$)?' # noqa: E501
6+
cmd = ('phpcs', '--report=json', '${args}', '-')
77
defaults = {
88
'selector': 'embedding.php, source.php - text.blade',
99
# we want auto-substitution of the filename,
1010
# but `cmd` does not support that yet
1111
'--stdin-path=': '${file}'
1212
}
13+
14+
def find_errors(self, output):
15+
data = json.loads(output)
16+
for file_path, file_data in data["files"].items():
17+
for error in file_data['messages']:
18+
yield LintMatch(
19+
filename=file_path,
20+
line=error['line'] - 1,
21+
col=error['column'] - 1,
22+
error_type=error['type'].lower(),
23+
code=error['source'],
24+
message=error['message'],
25+
)

0 commit comments

Comments
 (0)