From 8a9b63baa92d571dea2254cc7ea36b929a066f2e Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Tue, 25 Mar 2025 10:00:08 +0100 Subject: [PATCH 1/5] use checktyle report for more detail get access to the error code, missing from the emacs output also make the quick action work --- linter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linter.py b/linter.py index 65893dd..e470fe8 100644 --- a/linter.py +++ b/linter.py @@ -2,8 +2,8 @@ class Phpcs(ComposerLinter): - cmd = ('phpcs', '--report=emacs', '${args}', '-') - regex = r'^.*:(?P[0-9]+):(?P[0-9]+): (?:(?Perror)|(?Pwarning)) - (?P(.(?!\(\S+\)$))+)( \((?P\S+)\)$)?' # noqa: E501 + cmd = ('phpcs', '--report=checkstyle', '${args}', '-') + regex = r'^\s* Date: Tue, 25 Mar 2025 11:07:03 +0100 Subject: [PATCH 2/5] opt-in to python 3.8 --- .python-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..cc1923a --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8 From 4a9203c3501660c357550082de018d82656bc526 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Tue, 25 Mar 2025 11:47:59 +0100 Subject: [PATCH 3/5] use the CSV format issue: quotes are escaped in the messages --- linter.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/linter.py b/linter.py index e470fe8..02bb556 100644 --- a/linter.py +++ b/linter.py @@ -1,12 +1,23 @@ -from SublimeLinter.lint import ComposerLinter +import csv +from io import StringIO +from SublimeLinter.lint import LintMatch, ComposerLinter class Phpcs(ComposerLinter): - cmd = ('phpcs', '--report=checkstyle', '${args}', '-') - regex = r'^\s* Date: Tue, 25 Mar 2025 12:09:31 +0100 Subject: [PATCH 4/5] use the json report to circumvent escaped strings --- linter.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/linter.py b/linter.py index 02bb556..44bbecb 100644 --- a/linter.py +++ b/linter.py @@ -1,10 +1,9 @@ -import csv -from io import StringIO +import json from SublimeLinter.lint import LintMatch, ComposerLinter class Phpcs(ComposerLinter): - cmd = ('phpcs', '--report=csv', '${args}', '-') + cmd = ('phpcs', '--report=json', '${args}', '-') defaults = { 'selector': 'embedding.php, source.php - text.blade', # we want auto-substitution of the filename, @@ -13,11 +12,14 @@ class Phpcs(ComposerLinter): } def find_errors(self, output): - for match in csv.DictReader(StringIO(output)): - yield LintMatch( - line=int(match.get('Line', 1)) - 1, - col=int(match.get('Column', 1)) - 1, - error_type=match.get('Type', 'warning'), - code=match.get('Source', ''), - message=match.get('Message', ''), - ) + 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'], + ) From 1337322c88784f5a53f99af17c21a2b35adc4166 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Tue, 25 Mar 2025 18:40:22 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 387f3fa..410a756 100644 --- a/README.md +++ b/README.md @@ -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 ] } ```