Skip to content

Commit ecce97f

Browse files
authored
Require project PHPStan config and remove hidden wrapper fallback behavior (#18)
* Require project PHPStan config and remove hidden fallback behavior * Fix stylelint-fix path rewrite for non-web docroots * Add regression test for stylelint-fix non-web docroot path rewrite * Align wrappers with project config and scope decisions * Align fresh-install cspell expectation with default scope * Move scan scope control into visible config files
1 parent fb15089 commit ecce97f

20 files changed

Lines changed: 586 additions & 334 deletions

‎README.md‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ The template points PHP tooling at `.ddev/drupal-code-quality/tooling/bin` and J
158158
- `ESLINT_TOOLCHAIN=root` forces project root toolchain.
159159
- ESLint config mode:
160160
- `ESLINT_CONFIG_MODE=nearest` (default) groups by nearest config file.
161-
- `ESLINT_CONFIG_MODE=fixed` forces `.eslintrc.passing.json`.
161+
- `ESLINT_CONFIG_MODE=fixed` prefers `.eslintrc.passing.json`, then
162+
`.eslintrc.json` in the project root.
162163
- ESLint warning visibility (GitLab CI parity):
163164
- `DCQ_ESLINT_QUIET=1` (default) adds `--quiet` to `ddev eslint` and
164165
`ddev eslint-fix`, so warnings are suppressed.
@@ -177,26 +178,36 @@ The template points PHP tooling at `.ddev/drupal-code-quality/tooling/bin` and J
177178
- CSpell parity:
178179
- Run `ddev exec php /mnt/ddev_config/drupal-code-quality/tooling/scripts/prepare-cspell.php -s .prepared` once and
179180
replace `.cspell.json` after reviewing the diff.
180-
- `ddev cspell` runs from the repo root (`.`) by default; scope is controlled
181-
by `.cspell.json` `ignorePaths`. Narrow the scan by passing explicit paths.
181+
- `ddev cspell` defaults to scanning `.` when no paths are passed; scope is
182+
controlled by `.cspell.json` (especially `ignorePaths`).
182183
- `.cspell-project-words.txt` is created by the installer (empty) and updated
183184
by `ddev cspell-suggest` when you accept suggested words.
185+
- ESLint / Stylelint / Prettier default scope:
186+
- These wrappers default to scanning the configured docroot when no paths are
187+
passed.
188+
- Scope/exclusions are controlled by visible config files:
189+
`.eslintignore`, `.stylelintignore`, and `.prettierignore`.
190+
- Installer appends DCQ defaults to `.prettierignore` so the file remains the
191+
single source of truth for Prettier scope.
184192
- PHPCS / PHPCBF default scope:
185193
- When a project `.phpcs.xml` is installed by the add-on, `ddev phpcs` and
186194
`ddev phpcbf` with no path default to scanning the configured docroot.
187195
- The generated ruleset excludes `__DOCROOT__/core/**`, `**/contrib/**`,
188196
`**/node_modules/**`, and `__DOCROOT__/sites/*/files/**`.
189197
- You can still pass explicit paths to narrow runs.
198+
- PHP parallel lint scope:
199+
- `ddev php-parallel-lint` remains wrapper-scoped because the tool does not
200+
provide an equivalent project config file for default target paths.
190201
- PHPStan baseline:
191202
- Generate a baseline with `ddev phpstan --generate-baseline`.
192-
- This writes `phpstan-baseline.neon` at the project root; the wrapper will
193-
include it automatically when present.
203+
- This writes `phpstan-baseline.neon` at the project root and updates
204+
`phpstan.neon` to include it.
194205
- Use a baseline to suppress known issues in legacy code or core defaults
195206
(for example, the shipped `settings.php` files), then work it down over
196207
time. Avoid using it to hide new regressions.
197-
- PHPStan config fallback:
198-
- If no project `phpstan.neon*` exists, the wrapper uses the GitLab template
199-
config shipped with the add-on.
208+
- PHPStan config requirement:
209+
- `ddev phpstan` requires project config (`phpstan.neon*`) unless you pass
210+
`--configuration <path>`.
200211
- PHPStan level:
201212
- GitLab CI template defaults use level 0. The installer can set a local default level (0-10).
202213

‎commands/web/checks‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ if [ -z "$DOCROOT" ]; then
1212
DOCROOT="web"
1313
fi
1414

15-
# Collect custom code paths once so tools can reuse them.
16-
CUSTOM_PATHS=()
17-
for candidate in "${DOCROOT}/modules/custom" "${DOCROOT}/themes/custom" "${DOCROOT}/profiles/custom"; do
18-
if [ -d "$candidate" ]; then
19-
CUSTOM_PATHS+=("$candidate")
20-
fi
21-
done
22-
2315
# Ordered list of Drupal.org GitLab CI template default tools to run.
2416
TOOLS=(
2517
"composer-validate"
@@ -66,18 +58,7 @@ for tool in "${TOOLS[@]}"; do
6658
continue
6759
fi
6860

69-
if [ "$tool" = "phpcs" ] && [ "${#CUSTOM_PATHS[@]}" -eq 0 ]; then
70-
# Avoid failing when there is no custom code to lint.
71-
echo "SKIP: no custom code directories found for phpcs." | tee -a "$log_file"
72-
STATUS["$tool"]=SKIP
73-
continue
74-
fi
75-
76-
if [ "$tool" = "phpcs" ]; then
77-
"$tool_path" "${CUSTOM_PATHS[@]}" >"$log_file" 2>&1
78-
else
79-
"$tool_path" >"$log_file" 2>&1
80-
fi
61+
"$tool_path" >"$log_file" 2>&1
8162
exit_code=$?
8263
if [ "$exit_code" -eq 0 ]; then
8364
STATUS["$tool"]=PASS

‎commands/web/checks-full‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ if [ -z "$DOCROOT" ]; then
1212
DOCROOT="web"
1313
fi
1414

15-
# Collect custom code paths once so tools can reuse them.
16-
CUSTOM_PATHS=()
17-
for candidate in "${DOCROOT}/modules/custom" "${DOCROOT}/themes/custom" "${DOCROOT}/profiles/custom"; do
18-
if [ -d "$candidate" ]; then
19-
CUSTOM_PATHS+=("$candidate")
20-
fi
21-
done
22-
2315
# Ordered list of baseline Drupal.org GitLab CI template default tools.
2416
TOOLS=(
2517
"composer-validate"
@@ -82,18 +74,7 @@ for tool in "${ALL_TOOLS[@]}"; do
8274
continue
8375
fi
8476

85-
if [ "$tool" = "phpcs" ] && [ "${#CUSTOM_PATHS[@]}" -eq 0 ]; then
86-
# Avoid failing when there is no custom code to lint.
87-
echo "SKIP: no custom code directories found for phpcs." | tee -a "$log_file"
88-
STATUS["$tool"]=SKIP
89-
continue
90-
fi
91-
92-
if [ "$tool" = "phpcs" ]; then
93-
"$tool_path" "${CUSTOM_PATHS[@]}" >"$log_file" 2>&1
94-
else
95-
"$tool_path" >"$log_file" 2>&1
96-
fi
77+
"$tool_path" >"$log_file" 2>&1
9778
exit_code=$?
9879
if [ "$exit_code" -eq 0 ]; then
9980
STATUS["$tool"]=PASS

‎commands/web/cspell‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ CORE_CSPELL="${DOCROOT_PATH}/core/node_modules/.bin/cspell"
6363
ROOT_CSPELL="${PROJECT_ROOT}/node_modules/.bin/cspell"
6464
CSPELL_BIN=""
6565

66+
if ! command -v node >/dev/null 2>&1; then
67+
echo "Node.js is not available in the DDEV web container." >&2
68+
echo "Install the Drupal core JS toolchain (${DOCROOT}/core) to run CSpell." >&2
69+
exit 127
70+
fi
71+
6672
if [ -x "$ROOT_CSPELL" ]; then
6773
CSPELL_BIN="$ROOT_CSPELL"
6874
elif [ -x "$CORE_CSPELL" ]; then
@@ -85,12 +91,14 @@ fi
8591

8692
CMD=("$CSPELL_BIN")
8793
if [ "$has_config" = false ]; then
88-
# Prefer project config; warn when falling back to core.
89-
if [ -f "${PROJECT_ROOT}/.cspell.json" ]; then
90-
CMD+=(-c "${PROJECT_ROOT}/.cspell.json")
91-
else
92-
CMD+=(-c "${DOCROOT_PATH}/core/.cspell.json")
93-
echo "Warning: using core CSpell config (${DOCROOT}/core/.cspell.json); project config not found." >&2
94+
if [ ! -f "${PROJECT_ROOT}/.cspell.json" ]; then
95+
echo "CSpell config file is missing. Create .cspell.json in the project root (for example by reinstalling the add-on)." >&2
96+
exit 2
97+
fi
98+
CMD+=(-c "${PROJECT_ROOT}/.cspell.json")
99+
project_words_file="${PROJECT_ROOT}/.cspell-project-words.txt"
100+
if [ ! -f "$project_words_file" ]; then
101+
: > "$project_words_file"
94102
fi
95103
fi
96104

@@ -158,8 +166,3 @@ fi
158166

159167
"${CMD[@]}" "${FLAG_ARGS[@]}" "${POSITIONAL_ARGS[@]}"
160168
exit $?
161-
if ! command -v node >/dev/null 2>&1; then
162-
echo "Node.js is not available in the DDEV web container." >&2
163-
echo "Install the Drupal core JS toolchain (${DOCROOT}/core) to run CSpell." >&2
164-
exit 127
165-
fi

‎commands/web/cspell-suggest‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
7373
CORE_CSPELL="${DOCROOT_PATH}/core/node_modules/.bin/cspell"
7474
ROOT_CSPELL="${PROJECT_ROOT}/node_modules/.bin/cspell"
7575
CSPELL_BIN=""
76+
77+
if ! command -v node >/dev/null 2>&1; then
78+
echo "Node.js is not available in the DDEV web container." >&2
79+
echo "Install the Drupal core JS toolchain (${DOCROOT}/core) to run CSpell." >&2
80+
exit 127
81+
fi
82+
7683
REPORT_DIR="${PROJECT_ROOT}/dcq-reports"
7784
if ! mkdir -p "$REPORT_DIR"; then
7885
echo "Unable to create report directory: $REPORT_DIR" >&2
@@ -104,14 +111,16 @@ if [ "$has_version" = true ]; then
104111
exit $?
105112
fi
106113

114+
PROJECT_DICTIONARY="${PROJECT_ROOT}/.cspell-project-words.txt"
107115
CMD=("$CSPELL_BIN")
108116
if [ "$has_config" = false ]; then
109-
# Prefer project config; warn when falling back to core.
110-
if [ -f "${PROJECT_ROOT}/.cspell.json" ]; then
111-
CMD+=(-c "${PROJECT_ROOT}/.cspell.json")
112-
else
113-
CMD+=(-c "${DOCROOT_PATH}/core/.cspell.json")
114-
echo "Warning: using core CSpell config (${DOCROOT}/core/.cspell.json); project config not found." >&2
117+
if [ ! -f "${PROJECT_ROOT}/.cspell.json" ]; then
118+
echo "CSpell config file is missing. Create .cspell.json in the project root (for example by reinstalling the add-on)." >&2
119+
exit 2
120+
fi
121+
CMD+=(-c "${PROJECT_ROOT}/.cspell.json")
122+
if [ ! -f "$PROJECT_DICTIONARY" ]; then
123+
: > "$PROJECT_DICTIONARY"
115124
fi
116125
fi
117126

@@ -189,7 +198,6 @@ else
189198
: > "$UNRECOGNIZED_FILE"
190199
fi
191200

192-
PROJECT_DICTIONARY="${PROJECT_ROOT}/.cspell-project-words.txt"
193201
if [ -f "$PROJECT_DICTIONARY" ]; then
194202
# Merge existing dictionary with new suggestions.
195203
cat "$PROJECT_DICTIONARY" "$UNRECOGNIZED_FILE" | sort -u > "$UPDATED_WORDS_FILE"
@@ -219,8 +227,3 @@ if [ -s "$UNRECOGNIZED_FILE" ]; then
219227
fi
220228

221229
exit 0
222-
if ! command -v node >/dev/null 2>&1; then
223-
echo "Node.js is not available in the DDEV web container." >&2
224-
echo "Install the Drupal core JS toolchain (${DOCROOT}/core) to run CSpell." >&2
225-
exit 127
226-
fi

‎commands/web/eslint‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,21 @@ if [ -n "$RESOLVE_PLUGINS_DIR" ]; then
127127
# Ensure ESLint resolves plugins from the selected toolchain.
128128
CMD+=(--resolve-plugins-relative-to "$RESOLVE_PLUGINS_DIR")
129129
fi
130+
FIXED_CONFIG=""
131+
if [ -f "${PROJECT_ROOT}/.eslintrc.passing.json" ]; then
132+
FIXED_CONFIG="${PROJECT_ROOT}/.eslintrc.passing.json"
133+
elif [ -f "${PROJECT_ROOT}/.eslintrc.json" ]; then
134+
FIXED_CONFIG="${PROJECT_ROOT}/.eslintrc.json"
135+
fi
130136
if [ "$has_config" = false ] && [ "$ESLINT_CONFIG_MODE" != "nearest" ]; then
131-
# Fixed mode: force the passing config for Drupal.org GitLab CI template defaults when requested.
132-
if [ -f "${PROJECT_ROOT}/.eslintrc.passing.json" ]; then
133-
CMD+=(--config="${PROJECT_ROOT}/.eslintrc.passing.json")
134-
else
135-
CMD+=(--config="${DOCROOT_PATH}/core/.eslintrc.passing.json")
136-
echo "Warning: using core ESLint config (${DOCROOT}/core/.eslintrc.passing.json); project config not found." >&2
137+
# Fixed mode: prefer project passing config, then project base config.
138+
if [ -z "$FIXED_CONFIG" ]; then
139+
echo "ESLint config file is missing. Create .eslintrc.passing.json (or .eslintrc.json) in the project root, or pass --config." >&2
140+
exit 2
137141
fi
142+
CMD+=(--config="$FIXED_CONFIG")
138143
fi
139-
CMD+=(--ext .js,.yml --ignore-pattern "**/node_modules/**")
144+
CMD+=(--ext .js,.yml)
140145
CMD+=("${DEFAULT_ARGS[@]}")
141146

142147
find_nearest_config() {
@@ -146,7 +151,7 @@ find_nearest_config() {
146151
while true; do
147152
# Walk up the directory tree to find the closest ESLint config.
148153
for candidate in .eslintrc.passing.json .eslintrc .eslintrc.json .eslintrc.yaml .eslintrc.yml .eslintrc.js .eslintrc.cjs; do
149-
if [ "$dir" = "web" ] || [ "$dir" = "./web" ]; then
154+
if [ "$dir" = "$DOCROOT" ] || [ "$dir" = "./$DOCROOT" ]; then
150155
# Skip docroot configs so nearest-mode prefers theme/module configs or root passing config.
151156
continue
152157
fi
@@ -272,31 +277,24 @@ fi
272277

273278
FILES=()
274279
if [ "$explicit_paths" = false ]; then
275-
DEFAULT_FILES=()
276-
for candidate in "${DOCROOT}/modules/custom" "${DOCROOT}/themes/custom" "${DOCROOT}/profiles/custom"; do
277-
if [ -d "$candidate" ]; then
278-
while IFS= read -r file_path; do
279-
DEFAULT_FILES+=("$file_path")
280-
done < <(find "$candidate" -path '*/node_modules/*' -prune -o -type f \( -name '*.js' -o -name '*.yml' \) -print)
281-
fi
282-
done
283-
if [ "${#DEFAULT_FILES[@]}" -eq 0 ]; then
284-
echo "No custom JS/YML files found under modules/custom, themes/custom, or profiles/custom. Nothing to lint." >&2
280+
if [ ! -d "$DOCROOT" ]; then
281+
echo "Configured docroot '$DOCROOT' does not exist. Nothing to lint." >&2
285282
exit 2
286283
fi
287-
FILES=("${DEFAULT_FILES[@]}")
284+
FILES=("$DOCROOT")
288285
else
289286
FILES=("${FINAL_ARGS[@]}")
290287
fi
291288

292289
DEFAULT_CONFIG=""
293-
if [ -f "${PROJECT_ROOT}/.eslintrc.passing.json" ]; then
294-
DEFAULT_CONFIG="${PROJECT_ROOT}/.eslintrc.passing.json"
295-
elif [ -f "${DOCROOT_PATH}/core/.eslintrc.passing.json" ]; then
296-
DEFAULT_CONFIG="${DOCROOT_PATH}/core/.eslintrc.passing.json"
297-
fi
290+
DEFAULT_CONFIG="$FIXED_CONFIG"
298291

299292
if [ "$ESLINT_CONFIG_MODE" = "nearest" ]; then
293+
if [ "$explicit_paths" = false ]; then
294+
"${CMD[@]}" "${FLAGS_ARGS[@]}" "${FILES[@]}"
295+
exit $?
296+
fi
297+
300298
# Group files by nearest config to avoid plugin conflicts across modules/themes.
301299
declare -A ESLINT_GROUPS
302300
for file_path in "${FILES[@]}"; do
@@ -329,7 +327,7 @@ if [ "$ESLINT_CONFIG_MODE" = "nearest" ]; then
329327
if [ -n "$plugins_dir" ]; then
330328
group_cmd+=(--resolve-plugins-relative-to "$plugins_dir")
331329
fi
332-
group_cmd+=(--ext .js,.yml --ignore-pattern "**/node_modules/**")
330+
group_cmd+=(--ext .js,.yml)
333331
group_cmd+=("${DEFAULT_ARGS[@]}")
334332
"${group_cmd[@]}" "${FLAGS_ARGS[@]}" "${filtered_files[@]}"
335333
status=$?

0 commit comments

Comments
 (0)