Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Premium rules are not ignored when null and used without premium activated #522

Closed
SharakPL opened this issue Mar 17, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@SharakPL
Copy link

SharakPL commented Mar 17, 2024

I use PSR12, which extends previous standards like PSR1 and PSR2:

"php.format.codeStyle": "PSR-12",

So by default the extension should use this standard in formatting, but it looks like extension settings, even if not set, override chosen standard. First of all you might want to add null to acceptable value types to avoid warnings (unless it's a bug within VSCode itself):
obraz

Even though I don't set any styling rules in settings.json (means this should be null and the rule directly from PSR12 standard should be used) and I don't even have premium active, these rules are used anyway like they were true instead of null:

obraz

For example:

if (isset($myVar)) {
    ...
}

if (!empty($myVar)) {
    ...
{

is formatted as

if (isset ($myVar)) {
    ...
}

if (!empty ($myVar)) {
    ...
{

It breaks rule PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket:

obraz

These are control structures:

  • if
  • else
  • elseif/else if
  • while
  • do-while
  • for
  • foreach
  • break
  • continue
  • switch
  • match
  • declare
  • return
  • require
  • include
  • require_once
  • include_once
  • goto

Of course I'm just guessing that's the rule causing this problem here. It would really help with debugging these if there was code style inspection available 🙏 Something like PHP Sniffer extension has:

obraz

showing specific rule that triggers styling error:

obraz

@HB-2012
Copy link

HB-2012 commented Mar 18, 2024

Since the last update of the extension (1.45), I've noticed that the formatter in this extension automatically (and unwantingly) adds the space before opening parenthesis of the function calls. This was not the case before. I don't have premium and I do not have this setting enabled. Enabling or disabling suppressing premium features makes no difference. I do have some other PHP extensions but none that do formatting.

PHPCS then complains about it because like OP I've got PSR12 defined as coding standard.

I'm not sure what's going on, but since Google led me here after I experience the same warning and cause, I figured I'd share. There's no such thing as a coincidence 😄

@Miloslav
Copy link
Member

Hi guys,

Thank you for reporting this. I can confirm this looks like a bug. Let us look at it and fix it ASAP.

@jakubmisek jakubmisek added the bug Something isn't working label Mar 18, 2024
@jakubmisek jakubmisek added this to To do in Code Formatting via automation Mar 18, 2024
@Miloslav
Copy link
Member

Thanks again for reporting this. The fix will be included in the next pre-release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

4 participants