You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[#3328] Failed linting on debug calls left in custom code. - #3335
ahoy lint-be now fails with an error on var_dump(), print_r() and dump(), and on the Devel helpers (dpm(), dsm(), kint(), ddm() and the rest), anywhere PHPCS scans: custom modules and themes, web/sites/default, tests and scripts. ahoy lint-fe fails on debugger in custom module and theme JS, next to the existing no-console rule. The same rules apply to the .vortex/installer and .vortex/tests PHPCS configs and to the docs site's ESLint config.
Drupal.Functions.DiscouragedFunctions, part of the Drupal standard, already listed the Devel helpers, but it reports them as warnings and has no entry for plain PHP or Symfony debug output, so a var_dump() left in a custom module passed lint. no-debugger was only on through js.configs.recommended, and the docs site's ESLint config had neither rule.
Each phpcs.xml sets error to true on Drupal.Functions.DiscouragedFunctions and extends its forbiddenFunctions list with extend="true", so the 23 upstream entries stay and 3 are added. That also makes eval() and fnmatch() errors, and no linted path calls either. Method calls such as File::dump() are still ignored. Contrib and core aren't scanned, because the PHPCS <file> list and the ESLint targets never included them. The docs site allows console.warn() and console.error() so its player can still report load failures.
Before / After
BEFORE AFTER
────── ─────
var_dump($x) in web/modules/custom var_dump($x) in web/modules/custom
└─ not in any list ── lint passes └─ ERROR DiscouragedFunctions.Found
dpm($x) in web/modules/custom dpm($x) in web/modules/custom
└─ WARNING DiscouragedFunctions └─ ERROR DiscouragedFunctions.Found
.Discouraged
debugger; in custom JS debugger; in custom JS
└─ error via js.configs.recommended └─ error no-debugger (stated in config)
.vortex/installer, .vortex/tests .vortex/installer, .vortex/tests
└─ Devel helpers warn, var_dump passes └─ same ERROR rule as the template
.vortex/docs ESLint .vortex/docs ESLint
└─ no no-console, no no-debugger └─ no-console (warn/error allowed)
no-debugger
Changes
PHPCS
phpcs.xml, .vortex/installer/phpcs.xml and .vortex/tests/phpcs.xml configure Drupal.Functions.DiscouragedFunctions with error set to true and add var_dump, print_r and dump to its forbiddenFunctions list.
The root phpcs.xml now reads in this order: description, <arg> and <config> entries, <file> targets and global <exclude-pattern>s, then rules, with Drupal.Functions.DiscouragedFunctions last. The move changes no entry.
AssertTrait::assertArrayContainsString() and EnvironmentSettingsTest build their failure messages with var_export($x, TRUE) instead of print_r($x, TRUE).
ESLint
The root and theme eslint.config.mjs files set no-debugger to error next to no-console.
.vortex/docs/eslint.config.mjs adds no-console (allowing warn and error) and no-debugger.
Functional tests (AhoyWorkflowTest)
subtestAhoyLintBeDebugCalls() adds debug calls to sw_base.deploy.php and star_wars.theme and asserts that ahoy lint-be fails with Drupal.Functions.DiscouragedFunctions.Found errors for the 3 added functions and for dpm() and kint() from the upstream list, and that nothing is reported as .Discouraged. A second substep puts var_dump() in a contrib module and in web/core and asserts that phpcs passes.
subtestAhoyLintFeDebugCalls() adds console.log() and debugger to a custom module JS file, then to a custom theme JS file, and asserts that ahoy lint-fe fails with no-console and no-debugger each time.
Docs
phpcs.mdx lists Drupal.Functions.DiscouragedFunctions with its error level and added functions, and shows how to forbid another function.
eslint.mdx adds no-debugger to the rules table. cspell.json accepts kint.
Fixtures
Installer snapshots regenerated for the changed template files.
No actionable comments were generated in the recent review.
Walkthrough
PHP and JavaScript lint configurations reject selected debug calls. Ahoy workflow tests check the rules against custom module and theme code. Documentation describes the rules, and two test failure messages replace print_r with var_export.
PHPCS treats var_dump, print_r, and dump as errors. The root PHPCS configuration also updates scan settings and exclusions. ESLint rejects debugger statements; the .vortex ESLint configuration also rejects console calls other than console.warn and console.error. Documentation describes the rules and how to extend the PHPCS forbidden-function list.
Exercise lint rules in Ahoy workflow .vortex/tests/phpunit/Functional/AhoyWorkflowTest.php, .vortex/tests/phpunit/Traits/Subtests/SubtestAhoyTrait.php, tests/phpunit/Drupal/EnvironmentSettingsTest.php, web/modules/custom/ys_base/tests/src/Traits/AssertTrait.php
The workflow checks that backend lint rejects selected debug calls in custom PHP files and frontend lint rejects console.log and debugger in custom JavaScript files. Two test failure messages use var_export instead of print_r; their assertions remain unchanged.
This change adds lint rules that reject debug calls in custom code, with tests and docs. No merge-blocking risk was found.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Out of Scope Changes check
Changes that connect to #3328 or support it:
- phpcs.xml files (root, .vortex/installer, .vortex/tests): the debug-function rule and forbiddenFunctions entries. - eslint.config.mjs files (root and th…
Confirm against the merge base (4f5cc6e) whether the root phpcs.xml settings for PHP-extension scanning, the sp report, parallel processes, PHP 8.4 compatibility and the build, font, image, node_modules and minified exclusions already exis…
Passed checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the core change: failing lint on debug calls left in custom code. The changeset adds PHPCS and ESLint rules that flag debug calls in custom code, and adds tests for them. The title mat…
Linked Issues check
Issue #3328 has four coding acceptance criteria. The PR addresses each one.
1. [#3328] PHP debug calls fail lint in custom code. The PR sets Drupal.Functions.DiscouragedFunctions to error in phpcs.xm…
Full details: Title check
Explanation
The title names the core change: failing lint on debug calls left in custom code. The changeset adds PHPCS and ESLint rules that flag debug calls in custom code, and adds tests for them. The title matches the main change, so it passes. The title does not mention the specific tools, but that detail is not required.
Full details: Linked Issues check
Explanation
Issue #3328 has four coding acceptance criteria. The PR addresses each one.
[#3328] PHP debug calls fail lint in custom code. The PR sets Drupal.Functions.DiscouragedFunctions to error in phpcs.xml, .vortex/installer/phpcs.xml and .vortex/tests/phpcs.xml. It adds var_dump, print_r and dump to forbiddenFunctions. The upstream Devel helpers (dpm, dsm, kint, ddm) are reported as errors. AhoyWorkflowTest::subtestAhoyLintBeDebugCalls asserts these failures.
[#3328] console.log and debugger fail lint in custom JS. The root and theme eslint.config.mjs files set no-debugger to error beside the existing no-console rule. subtestAhoyLintFeDebugCalls asserts both failures in a custom module and a custom theme.
[#3328] Contrib and core are not scanned. The PHPCS file list and ESLint targets exclude them. The test places var_dump in a contrib module and in web/core and asserts that phpcs passes.
[#3328] Snapshots are updated. Installer snapshots are regenerated for the changed template files.
The issue suggests Generic.PHP.ForbiddenFunctions. The PR uses Drupal.Functions.DiscouragedFunctions with extend="true". The issue lists these as details. Its acceptance criteria are behavioral, and the PR meets them. The PR applies the rule to all PHPCS-scanned paths, which include custom code plus tests, scripts and web/sites/default. None of these are contrib or core.
Limits: no repository inspection was possible in this review. The conclusions rely on the PR description and the change summary. The XML and config contents were not read directly.
Full details: Out of Scope Changes check
Explanation
Changes that connect to #3328 or support it:
phpcs.xml files (root, .vortex/installer, .vortex/tests): the debug-function rule and forbiddenFunctions entries.
eslint.config.mjs files (root and theme): no-debugger beside no-console.
AssertTrait::assertArrayContainsString() and EnvironmentSettingsTest: print_r() replaced with var_export() so the test code passes the new rule.
AhoyWorkflowTest and SubtestAhoyTrait: tests for the new lint behaviour.
Docs (phpcs.mdx, eslint.mdx), cspell.json (kint), and the .vortex/docs ESLint config: documentation and rules for the new behaviour.
Installer snapshots: required by acceptance criterion 4.
Unresolved: the change summary of root phpcs.xml (+29/-17) also describes non-debug settings. These are a PHP-extension scan list, the sp report, 10 parallel processes, PHP 8.4 compatibility, and exclusions for theme build, font, image, node_modules and minified assets. The PR description does not mention them. The summary does not state whether they are new in this PR or already present at the merge base. Those settings do not implement #3328, so they would be out of scope if this PR added them. The commit message describes only a reorder of phpcs.xml. No repository inspection was possible, so this could not be resolved.
Resolution
Confirm against the merge base (4f5cc6e) whether the root phpcs.xml settings for PHP-extension scanning, the sp report, parallel processes, PHP 8.4 compatibility and the build, font, image, node_modules and minified exclusions already existed. If this PR added them, either justify them in the PR description with a link to a related issue or remove them from this PR.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between fbc350f and dd4961e.
Files ignored due to path filters: 14
.vortex/installer/tests/Fixtures/handler_process/_baseline/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/theme_claro/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/theme_olivero/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/theme_stark/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests_circleci/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_no_behat/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_no_theme/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_no_theme/phpcs.xml is excluded by !.vortex/installer/tests/Fixtures/**
Files selected for processing: 1
phpcs.xml
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A1Board worker 1Needs reviewPull request needs a review from assigned developers
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3328
Summary
ahoy lint-benow fails with an error onvar_dump(),print_r()anddump(), and on the Devel helpers (dpm(),dsm(),kint(),ddm()and the rest), anywhere PHPCS scans: custom modules and themes,web/sites/default,testsandscripts.ahoy lint-fefails ondebuggerin custom module and theme JS, next to the existingno-consolerule. The same rules apply to the.vortex/installerand.vortex/testsPHPCS configs and to the docs site's ESLint config.Drupal.Functions.DiscouragedFunctions, part of theDrupalstandard, already listed the Devel helpers, but it reports them as warnings and has no entry for plain PHP or Symfony debug output, so avar_dump()left in a custom module passed lint.no-debuggerwas only on throughjs.configs.recommended, and the docs site's ESLint config had neither rule.Each
phpcs.xmlsetserrortotrueonDrupal.Functions.DiscouragedFunctionsand extends itsforbiddenFunctionslist withextend="true", so the 23 upstream entries stay and 3 are added. That also makeseval()andfnmatch()errors, and no linted path calls either. Method calls such asFile::dump()are still ignored. Contrib and core aren't scanned, because the PHPCS<file>list and the ESLint targets never included them. The docs site allowsconsole.warn()andconsole.error()so its player can still report load failures.Before / After
Changes
PHPCS
phpcs.xml,.vortex/installer/phpcs.xmland.vortex/tests/phpcs.xmlconfigureDrupal.Functions.DiscouragedFunctionswitherrorset totrueand addvar_dump,print_randdumpto itsforbiddenFunctionslist.phpcs.xmlnow reads in this order: description,<arg>and<config>entries,<file>targets and global<exclude-pattern>s, then rules, withDrupal.Functions.DiscouragedFunctionslast. The move changes no entry.AssertTrait::assertArrayContainsString()andEnvironmentSettingsTestbuild their failure messages withvar_export($x, TRUE)instead ofprint_r($x, TRUE).ESLint
eslint.config.mjsfiles setno-debuggertoerrornext tono-console..vortex/docs/eslint.config.mjsaddsno-console(allowingwarnanderror) andno-debugger.Functional tests (
AhoyWorkflowTest)subtestAhoyLintBeDebugCalls()adds debug calls tosw_base.deploy.phpandstar_wars.themeand asserts thatahoy lint-befails withDrupal.Functions.DiscouragedFunctions.Founderrors for the 3 added functions and fordpm()andkint()from the upstream list, and that nothing is reported as.Discouraged. A second substep putsvar_dump()in a contrib module and inweb/coreand asserts thatphpcspasses.subtestAhoyLintFeDebugCalls()addsconsole.log()anddebuggerto a custom module JS file, then to a custom theme JS file, and asserts thatahoy lint-fefails withno-consoleandno-debuggereach time.Docs
phpcs.mdxlistsDrupal.Functions.DiscouragedFunctionswith its error level and added functions, and shows how to forbid another function.eslint.mdxaddsno-debuggerto the rules table.cspell.jsonacceptskint.Fixtures