Skip to content

Unused triggering on Attributes #3452

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

Closed
rdohms opened this issue Oct 13, 2021 · 2 comments
Closed

Unused triggering on Attributes #3452

rdohms opened this issue Oct 13, 2021 · 2 comments

Comments

@rdohms
Copy link

rdohms commented Oct 13, 2021

Describe the bug
When importing a class to be used as an attribute, PHPCS reports a SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse violation.
As it does not seem to detect the attribute usage as a valid usage.

It's clearly described here by @jrfnl rdohms/phpunit-arraysubset-asserts#57

Code sample

use ReturnTypeWillChange;

class ArrayAccessible implements ArrayAccess, IteratorAggregate
{
     *
     * @return mixed
     */
    #[ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        return $this->array[$offset];
    }
{

Custom ruleset

<ruleset>
    <arg name="basepath" value="." />
    <arg name="extensions" value="php" /> <!-- which extensions to look for -->
    <arg name="parallel" value="80" /> <!-- how many parallel processes to run -->
    <arg name="colors" />
    <arg name="cache" value=".phpcs.cache" /> <!-- cache the results and don't commit them -->
    <arg value="np" /> <!-- n = ignore warnings, p = show progress -->

    <file>assertarraysubset-autoload.php</file>
    <file>src</file>
    <file>tests</file>

    <rule ref="DMS">
        <exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
    </rule>

    <rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator">
        <exclude-pattern>src/Constraint/ArraySubset\.php</exclude-pattern>
    </rule>

    <!-- BC-layer: exclude rules which would prevent code from being PHP cross-version compatible. -->
    <rule ref="Squiz.Classes.ClassFileName.NoMatch">
        <exclude-pattern>assertarraysubset-autoload\.php</exclude-pattern>
        <exclude-pattern>src/ArraySubsetAssertsEmpty\.php</exclude-pattern>
        <exclude-pattern>src/AssertFallThrough\.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
        <exclude-pattern>assertarraysubset-autoload\.php</exclude-pattern>
        <exclude-pattern>src/ArraySubsetAssertsEmpty\.php</exclude-pattern>
        <exclude-pattern>src/AssertFallThrough\.php</exclude-pattern>
        <exclude-pattern>tests/bootstrap\.php</exclude-pattern>
        <exclude-pattern>tests/Availability/*\.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
        <exclude-pattern>assertarraysubset-autoload\.php</exclude-pattern>
        <exclude-pattern>tests/Availability/*\.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
        <exclude-pattern>assertarraysubset-autoload\.php</exclude-pattern>
        <exclude-pattern>src/AssertFallThrough\.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
        <exclude-pattern>assertarraysubset-autoload\.php</exclude-pattern>
        <exclude-pattern>src/AssertFallThrough\.php</exclude-pattern>
        <exclude-pattern>tests/Availability/*\.php</exclude-pattern>
    </rule>

</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Run phpcs test.php ...
  3. See error message displayed
FILE: test.php
------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Type ReturnTypeWillChange is not used in this file.
   |       |     (SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse)
------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------

Expected behavior
No errors should be reported.

Versions (please complete the following information):

  • PHP: 8.0
  • PHPCS: 3.6.1
@jrfnl
Copy link
Contributor

jrfnl commented Oct 13, 2021

@rdohms The sniff you are referring to is not part of PHPCS. Could you please report this to the Slevomat repo instead ?
https://github.com/slevomat/coding-standard

@rdohms
Copy link
Author

rdohms commented Oct 13, 2021

Derp, that explains why i could not find a report similar... my bad.

@rdohms rdohms closed this as completed Oct 13, 2021
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

2 participants