php-annotations / php-annotations

Industrial-strength annotations for PHP
GNU Lesser General Public License v3.0
137 stars 36 forks source link

Allow indentation of non-PHPDoc annotations #90

Open aik099 opened 9 years ago

aik099 commented 9 years ago

Currently there are 2 types of annotations:

Technically ones that don't have opening parenthesis aren't strictly PHPDoc ones, but still.

The problem I'm facing is DocBlock tag (everything that starts with @) indentation due PHP_CodeSniffer validation (see squizlabs/PHP_CodeSniffer#343).

The DocBlock that triggers an error for PHP_CodeSniffer:

/**
 * Annotation for describing element selector in Selenium style.
 *
 * @link http://bit.ly/qa-tools-find-by-annotation
 * @usage('class'=>true, 'property'=>true, 'inherited'=>true, 'multiple'=>true)
 */

The proposed DocBlock that won't trigger an error for PHP_CodeSniffer, but will trigger an exception for "php-annotations":

/**
 * Annotation for describing element selector in Selenium style.
 *
 * @link     http://bit.ly/qa-tools-find-by-annotation
 * @usage    ('class'=>true, 'property'=>true, 'inherited'=>true, 'multiple'=>true)
 * @internal
 */

Basically what we should allow to do is having variable number of whitespaces after @tagname and opening parenthesis without immediately considering an annotation as PHPDoc one and throwing following exception:

Annotation type 'NoteAnnotation' does not support PHP-DOC style syntax (because it does not implement the mindplay\annotations\IAnnotationParser interface)
mindplay-dk commented 9 years ago

That's a pretty severe BC break. For what?

Surely it's possible to disable these extra annotation checks in code sniffer for a project that uses annotations?

aik099 commented 9 years ago

That's a pretty severe BC break. For what?

How specifically it will break BC? As I said we only optionally allow to put any number of spaces after annotation name and actual ( (e.g. @any-annotation (). The code that doesn't have any extra spaces (e.g. @something('a' => 5)) would still work as before.

Surely it's possible to disable these extra annotation checks in code sniffer for a project that uses annotations?

In that particular case it's not possible to specify ignore rule on tag-name level. You can (in PHP_CodeSniffer ruleset) either enable that particular DocBlock tag indentation check or disable it completely. Even if there would be a possibility to disable indentation checks for particular annotations, then maintaining it would become a mess pretty soon, as projects can't share same coding standard because each project would have it's own annotation indentation exclusion rules.

Any ideas?

P.S. I'm not sure what approach the Doctrine Annotations have taken to resolve this. Maybe it's a problem for them as well.

mindplay-dk commented 9 years ago

If it's not a BC break, whatever.

Personally, I don't feel this is big enough to be worth the time. Bigger fish to fry :-)