sublimelsp / LSP-intelephense

PHP support for Sublime's LSP plugin provided through intelephense.
MIT License
96 stars 3 forks source link

How to enable formatting check? #80

Closed rusproject closed 3 months ago

rusproject commented 1 year ago

Intelephense doesn't show any formatting issues, although as I can see at https://github.com/bmewburn/vscode-intelephense/blob/master/package.json, formatting is set to PSR-12 and enabled by default. I've tried to explicitly add this settings but that doesn't work:

image

How can I enable formatting check so I can see if any of my code is not comply with PSR-12?

jfcherng commented 1 year ago

I don't think it provides any style check but weirdly I can't find anyone asking on https://github.com/bmewburn/vscode-intelephense/issues either. intelephense.format.braces is for the braces style when running formatting with intelephense. TBH, either style check or formatting, intelephense is an inferior solution IMHO.

There are plenty of solutions, especially for style check. I use php-cs-fixer, in command line, if you ask.


Or if you are talking about intelephense doesn't format your codes to fit PSR-12, then it's an issue of intelephense. But intelephense.format.braces, is as its name I guess.

rusproject commented 1 year ago

Thanks for the clarification, I will look for some codestyle plugin, thought intelephense has this feature built-in.

About your last sentence, what do you mean by "... Intelephense doesn't format your code ..."? What code and when (or how) can be formatted by the Intelephense?

jfcherng commented 1 year ago

About your last sentence, what do you mean by "... Intelephense doesn't format your code ..."? What code and when (or how) can be formatted by the Intelephense?

Intelephense as a formatter...

before:

final
class
Combined
extends
AbstractHtml {}

after:

final
class
Combined
extends
AbstractHtml
{
}

The golden result (PSR-12):

final class Combined extends AbstractHtml
{
}

There are many other PSR-12 rules that intelephense's formatting just doesn't/can't follow.

No need to constrain yourself on intelephense or even in ST (there are many command line treasures 😄, you/people can integrate them into ST for sure but that won't necessarily happen).


But if you just want to make your code looks better because you randomly miss whitespaces, then intelephense is fine for that.

rusproject commented 1 year ago

Oh I'm sorry, now I can see that LSP-intelephense has "Format file" command, which is really fixes some issues. Yeah it isn't perfect, and doesn't actually solve the problem: I would like to have a tool which will highlight formatting issues (just like SublimeLinter+ESlint does for .js files for example), not fixing issues itself (like intelephense or php-cs-fixer).

Can't find any working solution as for now. Any clue what tool or plugin for ST could I use?

rchl commented 1 year ago

I'm not into php ecosystem but I would suggest trying to find some existing tool that does decent linting of php. If it exists then there should exist one way or another to run it as LSP (or SublimeLinter).

jfcherng commented 1 year ago

Yes, for example, https://packagecontrol.io/packages/SublimeLinter-phpcs. I am sure PHP_CodeSniffer can check for PSR-12 but you may need to find how to properly configure it with SublimeLinter-phpcs. And if you prefer the LSP diagnostic panel, use https://github.com/iamcco/diagnostic-languageserver along with PHP_CodeSniffer should probably a way to go too.

rusproject commented 1 year ago

@jfcherng Thank you, phpcs + sublimeLinter seems to work.

image

Now trying to figure out how to control rules, because I don't actually need "tabs instead of spaces" error and some other.

willrowe commented 3 months ago

Closing this since some solutions were discussed and no issues with this package were identified.