Hello. I often have dozens of PHP6601 "Name x can be simplified with y" Infos. It's tedious to go through and fix each one, though I can come up with a regex to do it. Is there a command for the extension to auto-fix all of these? Thanks.

    6 days later

    That's a good point.

    We will mark safe quick fixes as auto-fixable. VSCode should fix all of them upon invoking "source.fixAll" action.

    The upcoming pre-releae will allow the following VSCode setting:

    "editor.codeActionsOnSave": {
        "source.fixAll": "explicit",
        "source.organizeImports": "explicit"
    }

    So these safe quick fixes will be applied upon file saving.

    Would it work for you?

    JakubMisek Awesome, I appreciate it! I think this may work as VS Code should give me the ability to manually auto-fix all problems as well since I don't use codeActionsOnSave yet.

      AnthonyANI I haven't found how to invoke the "source.fixAll" action yet. I just assume there is some way :-)

      It's already available in the pre-release, the full release will be out soon.

      JakubMisek Tested the new release and it does indeed fix all safe fixes on save. Thanks! However as you mentioned I was not able to find a way to manually trigger this so I don't have to use the on-save feature which sometimes is undesired. VS Code does have some commands in the palette, but they seem to not do anything or may require further configuration for Auto Fix/Preferred Fix.

        JakubMisek I should also mention that the code actions on save fixAll is only fixing one batch of problems at a time. For example, it will simplify one set of FQCN parameters in a function on one save, then on the next save it will do it for the next function. Something is preventing it from doing all of them on one save.

          AnthonyANI I see, good points.

          • We may add our own command or hook on the "Auto Fix..."
          • Not sure, why VSCode fixes only one suggestion - I'll try to find out.
          25 days later

          JakubMisek we have implemented "auto-fix" for some code actions;

          More at https://www.devsense.com/en/download/vscode#sourcefixall-action

          The following setting enable auto-fix on file save:

          "editor.codeActionsOnSave": {
              "source.fixAll": true,
              "source.organizeImports": true
          }

          The "auto-fix" corrects the casing of type names, and might perform other minor cleanups to your code (such as simplifying names).

            Thank you very much! Wouldn't it be nice to have features like this, which are currently only available clicking the specific code for fixing to be available on right click in the file for a global operation? That might be the expected and more intuitive UI.

            I think it would not only be nice for this case (Fix all fixable issues), but also for generating all getters / setters and maybe other actions?

            I think I came to this idea, as I used other IDE's before... and I expect it's the same for other users.

              JPustkuchen thank you for the suggestion.

              I would expect the UI to be provided by VSCode itself - but we can add something in the future by ourselves.

              • For now, all fixable issues can be fixed using the "editor.codeActionsOnSave" setting.

              • Generating all missing doc comments in a class has a code action:

              Write a Reply...