ComposerRequireChecker icon indicating copy to clipboard operation
ComposerRequireChecker copied to clipboard

Option to exclude check from some file

Open soullivaneuh opened this issue 7 years ago • 15 comments

Ref: Report https://github.com/maglnet/ComposerRequireChecker/issues/55#issuecomment-371168782

It would be great to be able to specify a file where some symbol check will be ignored.

We can simply provide a list of file to totally exclude:

{
  "exclude-files" : [
    "config/bundles.php",
    "dummy/other/magic_file.php",
  ]
}

Or also provide the namespace to ignore on each file:

{
  "exclude-files" : [
    "config/bundles.php": [
        "Some\\Namespace\\To\\Ignore",
    ],
    "dummy/other/magic_file.php",
  ]
}

As the original issue was about dev dependencies, the best would be also to specified when to also use dev dependencies while checking a file:

{
  "check-dev-files" : [
    "config/bundles.php",
    "dummy/other/magic_file.php",
  ]
}

Note: The option name can/must be improved, it is just an illustration for now.

soullivaneuh avatar Mar 07 '18 16:03 soullivaneuh

I know that Symfony best practices are outside the scope of this project. However, for a long time there has been a practice of keeping tests inside src/Some/Bundle/Tests/*, and so it would be valuable if we could exclude these directories from checks.

mpdude avatar Sep 24 '19 21:09 mpdude

I think this is fixed by https://github.com/symfony/symfony/pull/33579

Ocramius avatar Sep 24 '19 22:09 Ocramius

Not sure why... does it?

mpdude avatar Sep 25 '19 07:09 mpdude

It basically drops rhose tests from the (confusing) source tree of symfony components.

In practice, symfony could split the sources from the tests, which would be a better fix, but the above suffices.

Ocramius avatar Sep 25 '19 07:09 Ocramius

Sorry for the noise... What I meant was that in many Symfony projects that I know, there is src/App/whatever/Tests, because this has been the place suggested for (project-specific) tests in the past.

I think Symfony best practices nowadays suggest something else 🙏🏻. But that makes it hard to convince people to use this tool here if there is no simple way to make it pass on CI as well.

If we could exclude src/App/whatever/**/Tests, things might be easily fixable (just add the dependencies that were really missing).

mpdude avatar Sep 27 '19 13:09 mpdude

@mpdude well, they'd need to be declared as "shadowed" in composer.json somehow.

We should most certainly not add more conventions/configs than what is already very clear from composer.json: moving files is trivial and takes minutes anyway.

Ocramius avatar Sep 27 '19 14:09 Ocramius

In my case, the .phpstorm.meta.php are checked by this library and returning multiple unknown symbol. I would prefer to remove these files from the check.

VincentLanglet avatar Jan 24 '20 15:01 VincentLanglet

That depends on your autoloader configuration

Ocramius avatar Jan 24 '20 15:01 Ocramius

I have

"autoload": {
        "psr-4": {
            "Foo\\": "src/"
        }
    },

You mean I can easily exclude the phpstorm meta from the composer autoload and still having in the src folder ?

VincentLanglet avatar Jan 24 '20 15:01 VincentLanglet

That file doesn't need to be in src in first place

On Fri, Jan 24, 2020, 16:54 Vincent Langlet [email protected] wrote:

I have

"autoload": { "psr-4": { "Foo\": "src/" } },

You mean I can easily exclude the phpstorm meta from the composer autoload and still having in the src folder ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/maglnet/ComposerRequireChecker/issues/58?email_source=notifications&email_token=AABFVEDZUC6PBSN5TBRHT4TQ7MFKPA5CNFSM4EUC5XI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ3HH5A#issuecomment-578188276, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFVEGD3A2VPOOVEGFSBADQ7MFKPANCNFSM4EUC5XIQ .

Ocramius avatar Jan 24 '20 15:01 Ocramius

That file doesn't need to be in src in first place

I agree, it doesn't need to. But I have multiple .phpstorm.meta.php configuring different functions, different classes, ... So it's more convenient to have the meta file next to the file it configures. I never said I had no solution, I just prefer to have a way to exclude the file.

VincentLanglet avatar Jan 24 '20 16:01 VincentLanglet

Would suggest trying "exclude from classmap" or such - support probably to be built for it

On Fri, Jan 24, 2020, 17:04 Vincent Langlet [email protected] wrote:

That file doesn't need to be in src in first place

I agree, it doesn't need to. But I have multiple .phpstorm.meta.php configuring different functions, different classes, ... So it's more convenient to have the meta file next to the file it configures. I never said I had no solution, I just prefer to have a way to exclude the file.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/maglnet/ComposerRequireChecker/issues/58?email_source=notifications&email_token=AABFVEHWSW6KHUHL4KOOWN3Q7MGPZA5CNFSM4EUC5XI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ3IHJA#issuecomment-578192292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFVEEQLE6AS2TVDPKSFEDQ7MGPZANCNFSM4EUC5XIQ .

Ocramius avatar Jan 24 '20 16:01 Ocramius

Thanks ! It works perfectly.

VincentLanglet avatar Jan 24 '20 17:01 VincentLanglet

Sorry for recovering an old issue, but I stumbled on another use case for this option: https://github.com/schmittjoh/serializer/issues/1381

The class is valid up to PHP 8.0, and the library wont drop the class due to BC. In the meantime my hack would be the same as https://github.com/schmittjoh/serializer/issues/1381#issuecomment-1000150120 (rming the file on the fly), but an exclusion on this side would be highly appreciated.

Jean85 avatar Mar 16 '22 10:03 Jean85

Hi @Jean85

maybe you can add the PHP 8.1 incompatible file to your composer.json - autoload.exclude-from-classmap config section?

https://github.com/maglnet/ComposerRequireChecker/blob/e737b9f17c6fdb40fd376e3e51a584df49636d8a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php#L52

maglnet avatar Mar 18 '22 14:03 maglnet