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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah both works, which is nice but let's be consistent.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs review

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

anavarre’s picture

Checked 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?

anavarre’s picture

And the updated patch if we want it.

anavarre’s picture

Title: _content in routing files should always have a prefixing backslash » _content in routing files should always have a leading backslash
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah 289 vs 10 seems to be a pretty clear sign.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 773a992 on 8.x by catch:
    Issue #2241431 by anavarre: _content in routing files should always have...
alexpott’s picture

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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.