Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Report with HEAD cloned on 2014-04-15:
$ find . -type f -name "*.yml" | xargs grep -E --color=auto "(_content: '\\\Drupal)" | echo "Found $(wc -l) occurences with a prefixing backslash" && find . -type f -name "*.yml" | xargs grep -E --color=auto "(_content: 'Drupal)" | echo "Found $(wc -l) occurences without a prefixing backslash"
Found 288 occurences with a prefixing backslash
Found 11 occurences without a prefixing backslash
We should always use \Drupal
to explicitly use a class from the global namespace and not the one the class is in. Patch attached.
Comment | File | Size | Author |
---|---|---|---|
#4 | routing-prefixing-backslash-4.patch | 4.56 KB | anavarre |
routing-prefixing-backslash.patch | 4.94 KB | anavarre | |
Comments
Comment #1
dawehnerYeah both works, which is nice but let's be consistent.
Comment #2
tstoecklerActually our coding standards dictate to not prefix with a leading backslash in PHP strings. This is not exactly a PHP string but very similar, so not sure what would be more consistent here.
Comment #3
anavarreChecked again today and we're now having 289 occurrences versus 10 only without the leading backslash. Seems like for consistency it would be good to go with one or the other. I've been having that discussion at least 3 times in the last weeks, just because people are confused on what approach to take.
That being said, is it a fair assumption to assume that it might be our coding standards that would need to be updated according to how we're doing things now?
Comment #4
anavarreAnd the updated patch if we want it.
Comment #5
anavarreComment #6
dawehnerYeah 289 vs 10 seems to be a pretty clear sign.
Comment #7
catchCommitted/pushed to 8.x, thanks!
Comment #9
alexpottI would really like to see coding standards tests being added for things like this. Opened #2254825: Add coding standards tests for YAML definition files to do just that.
Also pointers in the issue to where the docs are and ensuring they are consistent would be nice - for example evidence that https://drupal.org/developing/api/8/routing and it's sub pages have been checked would be nice.