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

Annotation errors reported against wrong token/line #250

Closed
Majkl578 opened this issue Jan 28, 2018 · 2 comments
Closed

Annotation errors reported against wrong token/line #250

Majkl578 opened this issue Jan 28, 2018 · 2 comments

Comments

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 28, 2018

Currently annotation errors are bound to the element they're for - either T_VARIABLE or T_FUNCTION.
The error should be reported on the line (pointer) of the annotation itself.

Example

<?php

class Foo
{
    /**
     * @var integer
     */
    public $foo;

    /**
     * Doing foo.
     * @param int $foo
     * @return int
     */
    public function foo(int $foo) : int
    {
        return 123;
    }
}

Actual output

  8 | ERROR | [x] Expected "int" but found "integer" in @var annotation. (SlevomatCodingStandard.TypeHints.LongTypeHints.UsedLongTypeHint)
 15 | ERROR | [x] Method \Foo::foo() has useless @return annotation. (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation)
 15 | ERROR | [x] Method \Foo::foo() has useless @param annotation for parameter $foo. (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessParameterAnnotation)

Expected output

  6 | ERROR | [x] Expected "int" but found "integer" in @var annotation. (SlevomatCodingStandard.TypeHints.LongTypeHints.UsedLongTypeHint)
 12 | ERROR | [x] Method \Foo::foo() has useless @return annotation. (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation)
 13 | ERROR | [x] Method \Foo::foo() has useless @param annotation for parameter $foo. (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessParameterAnnotation)

This currently makes trouble in Doctrine DBAL (doctrine/dbal#2996, doctrine/dbal#2998) where we use line-based CS validation (so new/changed code obeys CS rules, but existing is still not compliant due the amount of conflicts it would cause).

Supporting this in UselessLongTypeHint sniff should be easy, just by storing $pointer in Annotation itself, but TypeHintDeclaration sniff may not be that trivial.

@kukulich
Copy link
Contributor

Ok, I fixed other situations caused by my laziness :)

See 6bf6846, bb3ee02, 2189ea4

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants