Problem/Motivation
There's lots of commented-out code in the core codebase, especially. Code might be commented for a lot of reasons -- missed cleanup on a patch, accidentally leaving something commented out after debugging, skipped tests for later functionality -- but it is almost always wrong and a code smell that can indicate bugs, incomplete APIs, etc.
Any commented-out code purposefully left for later development should be accompanied by an @todo linking to the issue that will address the point in the future.
Proposed resolution
- Find commented-out code in the Drupal core codebase.
- In each case, use git log -L for the commented lines to figure out when and why the code was commented in the first place, and how the lines around it have changed.
- Do research into the issues that you find. Read them carefully and check comments and interdiffs for how and why the code got commented out.
- Based on this, make a recommendation as to what to do. Possibilities:
- The commented code should be accompanied with an
@todoand followup issue (find or file it). - The commented code is leftover cruft that can be removed. (If this is the case, read the code very carefully to see what the purpose of the code was and that it's no longer needed! Check for test coverage of the code.
- For test code, commented test methods should possibly be marked skipped instead.
- The commented code should be accompanied with an
- Check with the maintainers for the subsystem to make sure your changes are correct.
Fix these together. #3641153: Remove commented out code in 3 tests
- core/tests/Drupal/FunctionalTests/Core/Recipe/StandardRecipeInstallTest.php
- core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php
- core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
- core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
Valid Comment
- core/lib/Drupal/Component/Utility/UserAgent.php
- core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
- core/lib/Drupal/Core/Site/SettingsEditor.php
- core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php
- core/modules/content_translation/src/Controller/ContentTranslationController.php
- core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php
- core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
- core/modules/jsonapi/tests/src/Functional/NodeTest.php
- core/modules/jsonapi/tests/src/Functional/TermTest.php
- core/modules/views/tests/src/Functional/Handler/FieldWebTest.php
- core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php
- core/tests/Drupal/KernelTests/Core/Image/GdToolkitGifImageManipulationTest.php
- core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php
- core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php
- core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
- core/tests/Drupal/Tests/Core/UrlTest.php
todo for closed issue - added to #3123832: [META] Fix @todo items referencing closed issues
- core/modules/image/tests/src/Functional/ImageDimensionsTest.php
Add @todo #3641171: Add @todo for commented out code
- core/modules/views/src/Plugin/views/query/Sql.php
- core/tests/Drupal/Tests/Core/Database/ConditionTest.php
- core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php
Remaining tasks
Search core for commented out code.
This grep, grep -rnl --include \*.php "^\s*//.*=.*;" core | sort finds commented out code in the following files.
- core/lib/Drupal/Component/Utility/UserAgent.php
- core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
- core/lib/Drupal/Core/Site/SettingsEditor.php
- core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php
- core/modules/content_translation/src/Controller/ContentTranslationController.php
- core/modules/image/tests/src/Functional/ImageDimensionsTest.php
- core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php
- core/modules/jsonapi/tests/src/Functional/NodeTest.php
- core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
- core/modules/jsonapi/tests/src/Functional/TermTest.php
- core/modules/views/src/Plugin/views/query/Sql.php
- core/modules/views/tests/src/Functional/Handler/FieldWebTest.php
- core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
- core/tests/Drupal/FunctionalTests/Core/Recipe/StandardRecipeInstallTest.php
- core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
- core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php
- core/tests/Drupal/KernelTests/Core/Image/GdToolkitGifImageManipulationTest.php
- core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php
- core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php
- core/tests/Drupal/Tests/Core/Database/ConditionTest.php
- core/tests/Drupal/Tests/Core/Mail/MailFormatHelperTest.php
- core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
- core/tests/Drupal/Tests/Core/UrlTest.php
- core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php
Where to find other issues
Some examples from #2715485: Fix 'Drupal.Commenting.InlineComment.NoSpaceBefore' coding standard and the related issues:
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
@@ -111,7 +111,7 @@ public static function open(array &$connection_options = []) {
//elseif (phpversion('pdo_pgsql') < 'version_this_was_fixed_in') {
+++ b/core/modules/update/update.module
@@ -349,7 +349,7 @@ function update_get_available($refresh = FALSE) {
//update_create_fetch_task($project);
+++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php
@@ -128,8 +128,8 @@ public function testRenderCaching() {
//$this->assertTrue(in_array('user.roles', $build['#cache']['contexts']));
//$this->assertEqual([], $build['#cache']['tags']);
+++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
@@ -131,11 +131,7 @@ public function testArgumentDefaultFixed() {
//function testArgumentDefaultPhp() {}
-
/**
* Test node default argument.
*/
+++ b/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
@@ -353,7 +353,7 @@ public function testEntityAutocompleteAccess() {
//$form = $form_builder->getForm($this);
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
@@ -100,7 +100,7 @@ protected function setUp() {
//$container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
Comments
Comment #2
xjmMaking the summary a little more legible by removing diff noise from the other issue.
Comment #3
xjmRemoving the Diff examples because we should leave those alone, and added the taxonomy issue I filed.
Comment #4
mfernea commentedI added 3 new child issues and also mentioned them in the "Open issues" section.
Comment #11
alexpottOpen #3177919: Uncomment code in EntityReferenceAutoCreateTest to address one of the remaining things.
Comment #17
quietone commented\Drupal\Tests\ban\Functional\IpAddressBlockingTest::testIPAddressValidation
\Drupal\field\Plugin\migrate\process\d6\FieldInstanceDefaults::transform
\Drupal\field\Plugin\migrate\process\d6\FieldInstanceSettings::transform
\Drupal\views\Plugin\views\query\Sql::execute
\Drupal\Tests\views\Functional\Handler\FieldWebTest::testAlterUrl
\Drupal\Tests\views_ui\Functional\DefaultViewsTest::testDefaultViews
\Drupal\FunctionalTests\Core\Recipe\StandardRecipeInstallTest::setUpSite
\Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteIdInput
\Drupal\KernelTests\Core\Image\ToolkitGdTest::testGifTransparentImages
\Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testSyntaxErrorWithUnknownCharacters
\Drupal\Tests\Core\Database\ConditionTest::dataProviderTestCompileWithKnownOperators
Comment #19
quietone commentedAssigning to myself to work on again in the next two days.
Comment #20
quietone commentedformatting fix in the issue summary
Comment #21
quietone commentedComment #22
quietone commentedComment #23
quietone commentedComment #24
quietone commentedComment #25
quietone commentedAll the files found with
grep -rl --include \*.php "^\s*//.*=.*;" corehave been investigated and a resolution proposed. New code doesn't have commented out code so when the child issues are fixed I think this cane be closed as fixed.