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

Option to exclude check from some file #58

Open
soullivaneuh opened this issue Mar 7, 2018 · 15 comments
Open

Option to exclude check from some file #58

soullivaneuh opened this issue Mar 7, 2018 · 15 comments

Comments

@soullivaneuh
Copy link

Ref: Report #55 (comment)

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.

@mpdude
Copy link

mpdude commented Sep 24, 2019

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.

@Ocramius
Copy link
Collaborator

I think this is fixed by symfony/symfony#33579

@mpdude
Copy link

mpdude commented Sep 25, 2019

Not sure why... does it?

@Ocramius
Copy link
Collaborator

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.

@mpdude
Copy link

mpdude commented Sep 27, 2019

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).

@Ocramius
Copy link
Collaborator

@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.

@VincentLanglet
Copy link
Contributor

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.

@Ocramius
Copy link
Collaborator

That depends on your autoloader configuration

@VincentLanglet
Copy link
Contributor

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 ?

@Ocramius
Copy link
Collaborator

Ocramius commented Jan 24, 2020 via email

@VincentLanglet
Copy link
Contributor

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.

@Ocramius
Copy link
Collaborator

Ocramius commented Jan 24, 2020 via email

@VincentLanglet
Copy link
Contributor

Thanks ! It works perfectly.

MidnightDesign pushed a commit to MidnightDesign/ComposerRequireChecker that referenced this issue Sep 17, 2020
…-when-psalm-runs-on-a-single-file

Fix external dataproviders when psalm runs on a single file
@Jean85
Copy link

Jean85 commented Mar 16, 2022

Sorry for recovering an old issue, but I stumbled on another use case for this option: schmittjoh/serializer#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 schmittjoh/serializer#1381 (comment) (rming the file on the fly), but an exclusion on this side would be highly appreciated.

@maglnet
Copy link
Owner

maglnet commented Mar 18, 2022

Hi @Jean85

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

$blacklist = $composerData['autoload']['exclude-from-classmap'] ?? null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants