Sorry if i simply missed where the info for this is but i read a ton on the site, googled, few searches here and either it doesnt exist or my search-foo sucks today. I simply want to know how to do an inline ignore of a warning. I do not want to ignore an entire file nor an entire warning across the board.

Looking for like // @php-ignore or // @ignore type functionality for single lines to ignore. Hopefully i am just missing it and someone can educate me.

Thanks!

    JakubMisek No, that is specifically for functions and classes only so it says. Im looking to do the same concept with any line of code, not just greatly limited to a function or a class.

      nitsua I understand, something like

      #suppress PHP0123
      
      #endsuppress

      It is on our to-do list, we don't support it yet.


      Is there some warning, that is not correct? We can fix it.

        JakubMisek That is unfortunate and seems like a pretty big oversight (just my opinion of course).. I was surely hoping it was there and would only be a single line comment like

        // @php-ignore
        // @ignore
        // @ignore PHP0123, PHP4567

        For example i have some code that creates defines dynamically

        $thing = 'THING';
        define(SOME_' . $thing .'_DEFINED', 'whatever');

        Then anytime i use SOME_THING_DEFINED it throws for undefined constants (assuming because it is not defined literally so it cant find it). Either way there are a few things where i do stuff with custom functions that it doesnt recognize as well. Having a simple way to ignore things would just be helpful. I dont really expect it to handle every possible thing a user can conjure up which is why i would have surely thought there was a way to ignore things.

        I know projects are a lot of work and things get added as the developers get time and decide what they want to work on so i do appreciate the effort in the project and glad you have it on the roadmap at some point. I'll look for some other alternatives for now and maybe come back to this later down the road.

        Thanks for the quick responses and answers as well!

          nitsua thank you, it makes sense.

          // @ignore etc. apply just for the line below right?

          JakubMisek Yes that is the idea, or even allow inline as well

          $something = 'warning'; // @ignore
          
          // @ignore-next
          $something = 'ignored';
          $something = 'checked';
          
          // @ignore-start
          $something = 'ignored';
          $something = 'ignored';
          // @ignore-end
          $something = 'checked';
            3 months later

            nitsua thank you for reminding me. We have it on our to-do but have not started it yet.

              3 months later

              JakubMisek Just checking in as i still have lots of yellow "warnings" about code that shouldn't have warnings. Would be nice to be able to stop seeing them everywhere.

              Is there a roadmap or timeline somewhere that can be followed? If it is still going to be months or years i will switch to something else (not the first choice) but i have no idea currently. I understand things get done when they get done, just looking for a way to keep myself updated.

              Thanks.

                nitsua thank you @nitsua for understanding!

                We'd like to avoid reporting false-warnings in the first place.

                I would recommend to disable specific warnings in your .vscode/settings.json for now (https://docs.devsense.com/en/vscode/problems#phpproblemsexclude)

                "php.problems.exclude" : {
                    "/" : [0123, 4567],
                }
                  2 months later

                  JakubMisek Unfortunately ignoring an entire thing such as all undefined constants is not a solution when the real issue is dynamic constants. I want to be told about them, just not the ones that are wrong. This same thing applies to classes it says do not exist but they do (composer loaded for example) so i dont want to ignore it outright.

                  I'll just do some hunting around for other things that might offer a way to ignore errors or even a different IDE entirely that is better for PHP

                  Thanks

                    6 days later

                    nitsua Any IDE in general needs to "see" a declaration of class and constant you want to use.

                    A common approach is to have a generated file that defines your dynamic stuff, for example having a file

                    some-ide-helper.php

                    with generated content:

                    <?php
                    const DYNAMIC_CONST1 = 123;
                    
                    /**
                     * @property int $a_property
                     */
                    class DynamicClasss{}
                      4 months later

                      the upcoming update will support

                      • // phpcs:ignoreFile
                      • // phpcs:ignore
                      • // phpcs:disable
                      • // phpcs:enable
                        Write a Reply...