SublimeLinter / SublimeLinter-phpmd

SublimeLinter plugin for php, using phpmd.
MIT License
15 stars 9 forks source link

Errors outputting to sublime console, but no styles being applied to editor / empty diagnostics panel #28

Open MarketHubb opened 7 months ago

MarketHubb commented 7 months ago

Issue

With the debug enabled, I can see that the package is formatting the command correctly (i.e., index.php text cleancode,codesize,controversial,design,naming,unusedcode), and the errors and warnings are outputting to the Sublime console exactly as they are if I run the command directly in my terminal.

However, no "error" or "warning" styles are being applied to the buffer, nor is anything outputting to the diagnostics panel via SublimeLinter --> Open diagnostics panel

Setup Sublime 4169 SublimeLinter 4.23.5 SublimeLinter-phpmd 1.3.0

User config

// SublimeLinter Settings - User
{
    // "gutter_theme": "ProjectIcons",
    "debug": true,
    "lint_mode": "background",
    "linters": {
        "phpmd": {
            "disable": false,
            "executable": "/Users/chris/.composer/vendor/bin/phpmd",
            "selector": "source.php, embedding.php, text.html.php, meta.embedded.php, source.php.embedded.html",
            "real_file_mode": true,
        },
        "phpcs": {
            "disable": false,
            "args": [],
            "executable": "/Users/chris/.composer/vendor/bin/phpcs",
            "env": {},
            "excludes": [],
            "filter_errors": [],
            "lint_mode": "background",
            "selector": "",
            "styles": [
                {
                    "codes": [
                        ""
                    ]
                }
            ],
            "working_dir": "",
            "disable_if_not_dependency": false
        }
    },
    "paths": {
        "linux": [],
        "osx": [
            "/Users/chris/.composer/vendor/bin"
        ],
        "windows": []
    },
}
kaste commented 7 months ago

Hm, I would expect some lines with "No match for line ..." in the console output. That would indicate that our regex can't parse the output format of phpmd. I guess "phpcs" is working so the setup/install of SublimeLinter itself is working as well.

You can of course have a post-filter applied (e.g. the plugin/addon SublimeLinter-addon-filter can do this).

Maybe post the console output.

MarketHubb commented 7 months ago

Hey @kaste,

Thank you for the quick response. I should have included those logs in the initial report. It is actually is logging a ton of "No match for file..."

Here are some log examples I'm seeing:

(Linter command)

INFO:SublimeLinter.plugin.phpmd:Running ...

  /Users/chris/Dropbox/valet/markethub  (working dir)
  $ /Users/chris/.composer/vendor/bin/phpmd /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php text cleancode,codesize,controversial,design,naming,unusedcode

(STDOUT)

SublimeLinter: #5 linter.py:1241      phpmd: output:
  - Unexpected token: problemFnc, line: 8, col: 10, file: /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php.

(No match)

SublimeLinter: #5 linter.py:1293      phpmd: No match for line: '   -   Unexpected token: problemFnc, line: 8, col: 10, file: /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php.'
INFO:SublimeLinter.plugin.phpmd:phpmd: No match for line: ' -   Unexpected token: problemFnc, line: 8, col: 10, file: /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php.'
kaste commented 7 months ago

Yeah, that's not the formatting we expect here. We have a very simple regex (.+):(?P<line>\d+)\s*(?P<message>.+)$ which very obvious does not match for e.g.

    -   Unexpected token: problemFnc, line: 8, col: 10, file: /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php.
    -   Unexpected token: problemFnc, line: 8, col: 10, file: /Users/chris/Dropbox/valet/markethub/wp-content/themes/markethubb-theme/footer.php.

You probably set that somewhere as usually the linters don't change defaults as it would break anyone. Or did they: we run 'phpmd', target, 'text' so it should be the "text" format

That said your formatting is also better as it has column information in it.

MarketHubb commented 7 months ago

@kaste,

I can write custom regex for the diagnostics panel, but shouldn't there still be some sort of output in the buffer / gutter where the errors are being found, or do I misunderstand how the package is set up to work?

kaste commented 7 months ago

It works like this: we run the linter, grab its output, parse it line-by-line to get a standardized form of each error. These are then stored in the store, and various "views" react to that: they draw squiggles or show them in the bottom panel when open, or in the status bar or in a tooltip on hover etc.

You can't write a custom regex though. The regex is the same for all users. The question is why you have such a format. The text format should be very compact, e.g. file:18 The message.

MarketHubb commented 7 months ago

@kaste,

Would you be comfortable sharing your phpmd.xml so I can mimic yours exactly and remove that variable?

Also, feel free to send it to me on the Sublime Discord if that's easier.

kaste commented 7 months ago

I actually don't have a phpmd.xml file as I'm not using phpmd. Where is yours from? I don't recognize your formatting style. Could that be a custom renderer or a custom phpmd?

As we explicitly ask for the text format, see their tests of how that should look like: https://github.com/phpmd/phpmd/blob/e9c0e1f47a391c54e473ddde783ccbf22e2d457c/src/test/php/PHPMD/Renderer/TextRendererTest.php#L68-L72

(Now, we should probably also extract the rule names as separate entities and not as part of the message but that's a completely other point.)