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.
I've the code like:
/**
* Topic index callback.
*/
function postcodeanywhere_index_page() {
/*
$output = theme('advanced_help_topic', array(
'module' => 'help_example',
'topic' => 'about-php',
));
*/
$output = '';
$output .= ' ' . t('Click the help icon to view help about the PCA Predict (formely Postcode Anywhere).');
return $output;
}
However when running: phpcs --standard=Drupal,DrupalPractice postcodeanywhere.module
it complains with ERRORs:
ERROR | [x] Line indented incorrectly; expected 2 spaces,
| found 4
ERROR | [x] Line indented incorrectly; expected 2 spaces,
| found 4
ERROR | [x] Line indented incorrectly; expected 3 spaces,
| found 2
which points to the lines with multi-line comment. Secondly, I think it should be a warning.
Comments
Comment #2
moshe weitzman CreditAttribution: moshe weitzman at Acquia commentedI am seeing this as well.
Comment #3
pfrenssenI personally wouldn't bother adding the complexity needed to support indentation of commented out code. It's a bad practice to commit commented out code, we shouldn't encourage this.
Commented out code should be temporary anyway, just slap
// @codingStandardsIgnoreStart
and// @codingStandardsIgnoreEnd
around it and call it a day.Comment #4
klausiAgreed, you shouldn't have commented out code in the first place and for the exceptions we can use @codingStandardsIgnoreStart. Is that good enough for you?
Comment #5
klausiClosing this for now, please reopen if you have more input.
Comment #6
claudiu.cristeaIn #2868078: Use new array syntax in PHP files outside of /core. there's a proposal to include
sites/default/default.settings.php
in the PHPCS check and that seems to be OK. But the file contains commented-out code and this is also OK because that file is like a dist file. So, at least in core, we will, probably, have such cases.Comment #7
pfrenssendefault.settings.php
has a valid use case for containing commented out code since it contains examples for different environments. But this is a very rare exception, I would just use@codingStandardsIgnoreStart
and@codingStandardsIgnoreEnd
for that.Coder is intended to make sure any tested code adheres to the coding standards and there is no mention in the coding standards on how to format commented out code. So technically we cannot adopt it until the coding standards change. That is not likely to happen since committing commented out code is bad practice.
I think this is just something we need to accept. Core is big and there will be exceptions. There are some other coding standards that are also willfully broken by core. For example Views plugins don't follow the right naming conventions. This is also not fixable without breaking backwards compatibility.
In the end that's fine, for those rare edge cases we can use
@codingStandardsIgnoreStart
or add an exception to the ruleset, these mechanisms exist for that reason.Comment #8
pfrenssenAs a side note for people reading this and looking for ways to commit their commented out code and are not happy with "Don't do it!": if you comment out your code using hashes, then Coder doesn't complain:
So this can also be used as an alternative to
@codingStandardsIgnoreStart
and@codingStandardsIgnoreEnd
.