eclipse-pdt / pdt

PHP Development Tools project (PDT)
https://eclipse.org/pdt
Eclipse Public License 2.0
188 stars 46 forks source link

Adds falsy `use const False\MyClass\true;` statements when using phpcs #256

Open cracksalad opened 9 months ago

cracksalad commented 9 months ago

Describe the bug

When the setting PHP > Editor > Save Actions > Organize use statements is on and you use true in a namespaced class, eclipse/PDT will add a use statement use const False\MyClass\true; on save. This use statement can not be resolved and thereby effectivly kills the class.

Describe the eclipse environment

Tested in eclipse 2023-06 and 2023-09. PDT 8.0 and 8.1. My project uses squizlabs/php_codesniffer as a composer dependency. If I uninstall it, the falsy use statements are gone!

Describe your system

To Reproduce

  1. Use PHP_CodeSniffer as a composer dependency in your project
  2. Switch the setting "PHP > Editor > Save Actions > Organize use statements" on
  3. Create a namespaced class and use the constant true in it
  4. Hit save and observe the (namespace) use statements

Expected behavior

use statements should generally be added, but not if they are not needed and can not be resolved.

Workaround

  1. Disable this setting (I do not want to, I like it)
  2. Use the global search (magnifier icon) to replace those statements (using regex) use const False\\MyClass\\true;\n with empty string - everytime you change a file.
pounard commented 9 months ago

It happens a lot to me, but it's very hard to reproduce. Mostly it happens when I hit Ctrl+S then Ctrl+Shift+O while save is unfinished, or when the file is being validated after some change. It's quite random, arbitrary, it happens in many files.

zulus commented 9 months ago

yeah, not only here. Auto generated getter/setter completely ignore FQN's . Probably due same reason

I'll take a look