Skip to content

Commit 1438415

Browse files
authored
Align ESLint quiet behavior across CLI and VS Code (#4)
* Remove hidden --quiet flag from eslint wrapper * Remove hidden --quiet flag from eslint-fix wrapper * Make ESLint quiet default explicit and IDE-aligned * Clarify ESLint quiet config for CLI and VS Code
1 parent 87a4ad3 commit 1438415

7 files changed

Lines changed: 126 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ The template points PHP tooling at `.ddev/drupal-code-quality/tooling/bin` and J
137137
- ESLint config mode:
138138
- `ESLINT_CONFIG_MODE=nearest` (default) groups by nearest config file.
139139
- `ESLINT_CONFIG_MODE=fixed` forces `.eslintrc.passing.json`.
140+
- ESLint warning visibility (GitLab CI parity):
141+
- `DCQ_ESLINT_QUIET=1` (default) adds `--quiet` to `ddev eslint` and
142+
`ddev eslint-fix`, so warnings are suppressed.
143+
- Set `DCQ_ESLINT_QUIET=0` to include warnings in CLI output. Persist this in
144+
`.ddev/config.yaml` (or `.ddev/config.yml`):
145+
```yaml
146+
web_environment:
147+
- DCQ_ESLINT_QUIET=0
148+
```
149+
- VS Code uses its own setting for extension diagnostics. Set
150+
`"eslint.quiet": false` in `.vscode/settings.json` to include warnings in
151+
the IDE.
152+
- Installer behavior: `overwrite` regenerates IDE settings from template;
153+
`merge` only adds missing keys and will not change an existing
154+
`eslint.quiet` value.
140155
- CSpell parity:
141156
- Run `ddev exec php /mnt/ddev_config/drupal-code-quality/tooling/scripts/prepare-cspell.php -s .prepared` once and
142157
replace `.cspell.json` after reviewing the diff.
@@ -161,14 +176,17 @@ The template points PHP tooling at `.ddev/drupal-code-quality/tooling/bin` and J
161176
- If no project `phpstan.neon*` exists, the wrapper uses the GitLab template
162177
config shipped with the add-on.
163178
- PHPStan level:
164-
- GitLab CI template defaults use level 0. The installer can set a local default level (0-10).
179+
- GitLab CI template defaults use level 0. The installer can set a local default level (0-10).
165180

166181
## Installer environment variables
167182

168183
- `DCQ_INSTALL_MODE`: `replace`, `skip`, or `abort` for conflict handling.
169184
- `DCQ_NONINTERACTIVE=true`: disable prompts; if no overrides are set, applies
170185
the recommended settings automatically.
171186
- `DCQ_PHPSTAN_LEVEL`: set `phpstan.neon` level (0-10) without prompting.
187+
- `DCQ_ESLINT_QUIET`: `1`/unset to suppress ESLint warnings by default
188+
(GitLab CI parity), `0` to include warnings. This can be set in
189+
`.ddev/config.yaml` under `web_environment`.
172190
- `DCQ_INSTALL_DEPS`: `install`/`true` to auto-install missing `drupal/core-dev`,
173191
`skip`/`false` to skip, or unset to prompt when interactive.
174192
- `DCQ_INSTALL_NODE_DEPS`: `root` to install JS deps in the project root (creates

‎commands/web/eslint‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ print_help() {
99
Usage: ddev eslint [args]
1010
1111
Runs ESLint inside the DDEV web container with Drupal.org GitLab CI template defaults.
12+
13+
Defaults:
14+
- Uses --quiet (GitLab CI parity). Set DCQ_ESLINT_QUIET=0 to include warnings.
1215
USAGE
1316
}
1417

@@ -28,6 +31,11 @@ NODE_PATH=""
2831
RESOLVE_PLUGINS_DIR=""
2932
ESLINT_TOOLCHAIN="${ESLINT_TOOLCHAIN:-auto}"
3033
ESLINT_CONFIG_MODE="${ESLINT_CONFIG_MODE:-nearest}"
34+
DCQ_ESLINT_QUIET="${DCQ_ESLINT_QUIET:-1}"
35+
QUIET_ENABLED=1
36+
case "$DCQ_ESLINT_QUIET" in
37+
0|false|FALSE|False|no|NO|off|OFF) QUIET_ENABLED=0 ;;
38+
esac
3139

3240
for arg in "$@"; do
3341
if [ "$seen_double_dash" = true ]; then
@@ -110,7 +118,11 @@ if [ "$has_version" = true ]; then
110118
exit $?
111119
fi
112120

113-
CMD=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet)
121+
CMD=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN")
122+
DEFAULT_ARGS=()
123+
if [ "$QUIET_ENABLED" -eq 1 ]; then
124+
DEFAULT_ARGS+=(--quiet)
125+
fi
114126
if [ -n "$RESOLVE_PLUGINS_DIR" ]; then
115127
# Ensure ESLint resolves plugins from the selected toolchain.
116128
CMD+=(--resolve-plugins-relative-to "$RESOLVE_PLUGINS_DIR")
@@ -125,6 +137,7 @@ if [ "$has_config" = false ] && [ "$ESLINT_CONFIG_MODE" != "nearest" ]; then
125137
fi
126138
fi
127139
CMD+=(--ext .js,.yml --ignore-pattern "**/node_modules/**")
140+
CMD+=("${DEFAULT_ARGS[@]}")
128141

129142
find_nearest_config() {
130143
local file_path="$1"
@@ -312,11 +325,12 @@ if [ "$ESLINT_CONFIG_MODE" = "nearest" ]; then
312325
config_dir="$(dirname "$config_path")"
313326
plugins_dir="$(resolve_plugins_dir "$config_dir")"
314327
echo "ESLint nearest-mode: config ${config_path} (${#group_files[@]} file(s))." >&2
315-
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet --config="$config_path")
328+
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --config="$config_path")
316329
if [ -n "$plugins_dir" ]; then
317330
group_cmd+=(--resolve-plugins-relative-to "$plugins_dir")
318331
fi
319332
group_cmd+=(--ext .js,.yml --ignore-pattern "**/node_modules/**")
333+
group_cmd+=("${DEFAULT_ARGS[@]}")
320334
"${group_cmd[@]}" "${FLAGS_ARGS[@]}" "${filtered_files[@]}"
321335
status=$?
322336
if [ $status -ne 0 ]; then

‎commands/web/eslint-fix‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Usage: ddev eslint-fix [args]
1111
1212
Applies ESLint fixes directly to files (matches standard eslint --fix behavior).
1313
14+
Defaults:
15+
- Uses --quiet (GitLab CI parity). Set DCQ_ESLINT_QUIET=0 to include warnings.
16+
1417
Use --preview to see a patch preview and confirm before applying fixes.
1518
This generates a patch in dcq-reports/ and prompts for confirmation.
1619
@@ -31,6 +34,11 @@ preview_mode=false
3134
clean_args=()
3235
ESLINT_TOOLCHAIN="${ESLINT_TOOLCHAIN:-auto}"
3336
ESLINT_CONFIG_MODE="${ESLINT_CONFIG_MODE:-nearest}"
37+
DCQ_ESLINT_QUIET="${DCQ_ESLINT_QUIET:-1}"
38+
QUIET_ENABLED=1
39+
case "$DCQ_ESLINT_QUIET" in
40+
0|false|FALSE|False|no|NO|off|OFF) QUIET_ENABLED=0 ;;
41+
esac
3442

3543
for arg in "$@"; do
3644
if [ "$arg" = "--preview" ]; then
@@ -191,7 +199,11 @@ else
191199
done
192200
fi
193201

194-
CMD_BASE=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet)
202+
CMD_BASE=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN")
203+
DEFAULT_ARGS=()
204+
if [ "$QUIET_ENABLED" -eq 1 ]; then
205+
DEFAULT_ARGS+=(--quiet)
206+
fi
195207
if [ -n "$RESOLVE_PLUGINS_DIR" ]; then
196208
CMD_BASE+=(--resolve-plugins-relative-to "$RESOLVE_PLUGINS_DIR")
197209
fi
@@ -204,6 +216,7 @@ if [ "$has_config" = false ] && [ "$ESLINT_CONFIG_MODE" != "nearest" ]; then
204216
fi
205217
fi
206218
CMD_BASE+=(--ext .js,.yml --ignore-pattern "**/node_modules/**")
219+
CMD_BASE+=("${DEFAULT_ARGS[@]}")
207220

208221
find_nearest_config() {
209222
local file_path="$1"
@@ -410,11 +423,12 @@ if [ "$preview_mode" = true ]; then
410423
config_dir="$(dirname "$config_path_abs")"
411424
plugins_dir="$(resolve_plugins_dir "$config_dir")"
412425
echo "ESLint-fix preview: config ${config_path_abs} (${#filtered_files[@]} file(s))." >&2
413-
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet --config="$config_path_run")
426+
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --config="$config_path_run")
414427
if [ -n "$plugins_dir" ]; then
415428
group_cmd+=(--resolve-plugins-relative-to "$plugins_dir")
416429
fi
417430
group_cmd+=(--ext .js,.yml --ignore-pattern "**/node_modules/**" --fix)
431+
group_cmd+=("${DEFAULT_ARGS[@]}")
418432
(cd "$tmp_root" && "${group_cmd[@]}" "${filtered_files[@]}")
419433
status=$?
420434
if [ $status -ne 0 ]; then
@@ -496,11 +510,12 @@ if [ "$preview_mode" = true ]; then
496510
config_dir="$(dirname "$config_path_abs")"
497511
plugins_dir="$(resolve_plugins_dir "$config_dir")"
498512
echo "Applying ESLint fixes: config ${config_path_abs} (${#filtered_files[@]} file(s))." >&2
499-
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet --config="$config_path_run")
513+
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --config="$config_path_run")
500514
if [ -n "$plugins_dir" ]; then
501515
group_cmd+=(--resolve-plugins-relative-to "$plugins_dir")
502516
fi
503517
group_cmd+=(--ext .js,.yml --ignore-pattern "**/node_modules/**" --fix)
518+
group_cmd+=("${DEFAULT_ARGS[@]}")
504519
"${group_cmd[@]}" "${filtered_files[@]}"
505520
status=$?
506521
if [ $status -ne 0 ]; then
@@ -567,11 +582,12 @@ if [ "$ESLINT_CONFIG_MODE" = "nearest" ]; then
567582
fi
568583
config_dir="$(dirname "$config_path_abs")"
569584
plugins_dir="$(resolve_plugins_dir "$config_dir")"
570-
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --quiet --config="$config_path_run")
585+
group_cmd=(env "NODE_PATH=$NODE_PATH" node "$TOOLCHAIN_BIN" --config="$config_path_run")
571586
if [ -n "$plugins_dir" ]; then
572587
group_cmd+=(--resolve-plugins-relative-to "$plugins_dir")
573588
fi
574589
group_cmd+=(--ext .js,.yml --ignore-pattern "**/node_modules/**" --fix)
590+
group_cmd+=("${DEFAULT_ARGS[@]}")
575591
"${group_cmd[@]}" "${filtered_files[@]}"
576592
status=$?
577593
if [ $status -ne 0 ]; then

‎dcq-install.sh‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,40 @@ escape_sed_replacement() {
10741074
printf '%s' "${1:-}" | sed 's/[&|]/\\&/g'
10751075
}
10761076

1077+
eslint_quiet_disabled() {
1078+
case "${1:-}" in
1079+
0|false|FALSE|False|no|NO|off|OFF)
1080+
return 0
1081+
;;
1082+
esac
1083+
return 1
1084+
}
1085+
1086+
resolve_eslint_quiet_setting() {
1087+
local app_root="$1"
1088+
local raw="${DCQ_ESLINT_QUIET:-}"
1089+
local config_file=""
1090+
local matched_line=""
1091+
1092+
if [ -z "$raw" ]; then
1093+
for config_file in "${app_root%/}/.ddev/config.yaml" "${app_root%/}/.ddev/config.yml"; do
1094+
[ -f "$config_file" ] || continue
1095+
matched_line="$(grep -E '^[[:space:]-]*["'"'"']?DCQ_ESLINT_QUIET=' "$config_file" | tail -n 1 || true)"
1096+
[ -n "$matched_line" ] || continue
1097+
raw="${matched_line#*=}"
1098+
raw="${raw%%#*}"
1099+
raw="$(printf '%s' "$raw" | tr -d "\"'" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
1100+
[ -n "$raw" ] && break
1101+
done
1102+
fi
1103+
1104+
if eslint_quiet_disabled "$raw"; then
1105+
printf 'false'
1106+
return
1107+
fi
1108+
printf 'true'
1109+
}
1110+
10771111
render_ide_template() {
10781112
# Render IDE settings template with resolved shim and tool paths.
10791113
local template="$1"
@@ -1083,17 +1117,20 @@ render_ide_template() {
10831117
local prettier_path="$5"
10841118
local eslint_node_path="$6"
10851119
local eslint_resolve_plugins="$7"
1120+
local eslint_quiet="$8"
10861121
local escaped_shim
10871122
local escaped_stylelint
10881123
local escaped_prettier
10891124
local escaped_node_path
10901125
local escaped_resolve_plugins
1126+
local escaped_eslint_quiet
10911127

10921128
escaped_shim="$(escape_sed_replacement "$shim_setting")"
10931129
escaped_stylelint="$(escape_sed_replacement "$stylelint_path")"
10941130
escaped_prettier="$(escape_sed_replacement "$prettier_path")"
10951131
escaped_node_path="$(escape_sed_replacement "$eslint_node_path")"
10961132
escaped_resolve_plugins="$(escape_sed_replacement "$eslint_resolve_plugins")"
1133+
escaped_eslint_quiet="$(escape_sed_replacement "$eslint_quiet")"
10971134

10981135
sed \
10991136
-e '1{/^#ddev-generated$/d;}' \
@@ -1102,6 +1139,7 @@ render_ide_template() {
11021139
-e "s|__DCQ_PRETTIER_PATH__|${escaped_prettier}|g" \
11031140
-e "s|__DCQ_ESLINT_NODE_PATH__|${escaped_node_path}|g" \
11041141
-e "s|__DCQ_ESLINT_RESOLVE_PLUGINS__|${escaped_resolve_plugins}|g" \
1142+
-e "s|__DCQ_ESLINT_QUIET__|${escaped_eslint_quiet}|g" \
11051143
"$template" >"$output"
11061144
}
11071145

@@ -2190,6 +2228,7 @@ if [ -f "$ide_settings_template" ] || [ -f "$ide_extensions_template" ]; then
21902228
js_modules=""
21912229
eslint_node_path=""
21922230
eslint_resolve_plugins=""
2231+
eslint_quiet="$(resolve_eslint_quiet_setting "$app_root")"
21932232
if [ "$ide_node_mode" = "root" ] && [ "$has_root_node_modules" -eq 1 ]; then
21942233
js_modules="./node_modules"
21952234
eslint_node_path="node_modules"
@@ -2205,7 +2244,7 @@ if [ -f "$ide_settings_template" ] || [ -f "$ide_extensions_template" ]; then
22052244
fi
22062245

22072246
render_ide_template "$ide_settings_template" "$ide_tmp" "$shim_setting" \
2208-
"$stylelint_path" "$prettier_path" "$eslint_node_path" "$eslint_resolve_plugins"
2247+
"$stylelint_path" "$prettier_path" "$eslint_node_path" "$eslint_resolve_plugins" "$eslint_quiet"
22092248
if [ "$ide_js_paths_set" -eq 0 ]; then
22102249
strip_ide_js_settings "$ide_tmp" || true
22112250
emit 'JS tool paths not configured (node_modules missing). Install JS deps and re-run the installer or update settings manually.\n'

‎drupal-code-quality/ide-settings/vscode/README.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ Stylelint, Prettier, CSpell) use local `node_modules` paths. The installer uses
1919
the Node toolchain choice (prompt or `DCQ_INSTALL_NODE_DEPS`) to configure those
2020
paths when dependencies are available. Override the paths if you prefer a
2121
different location. Run `ddev <tool>` in the terminal to use the containerized
22-
CLI wrappers.
22+
CLI wrappers. The generated settings also set `eslint.quiet` by default to
23+
match GitLab CI behavior; set `DCQ_ESLINT_QUIET=0` before install to disable.
24+
To persist this in DDEV commands, add `DCQ_ESLINT_QUIET=0` under
25+
`web_environment` in `.ddev/config.yaml`.
26+
27+
For existing projects, update `.vscode/settings.json` as well:
28+
- Set `"eslint.quiet": false` to show warnings in the IDE.
29+
- Set `"eslint.quiet": true` to hide warnings in the IDE.
30+
31+
Note: installer `merge` mode only adds missing settings. It does not overwrite
32+
an existing `eslint.quiet` value.

‎drupal-code-quality/ide-settings/vscode/settings.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"phpstan.configFile": "./phpstan.neon",
1515
"intelephense.environment.phpVersion": "8.3",
1616
"eslint.enable": true,
17+
"eslint.quiet": __DCQ_ESLINT_QUIET__,
1718
"eslint.workingDirectories": [
1819
{
1920
"directory": ".",

‎tests/test.bats‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ with open(path, encoding="utf-8") as fh:
818818
819819
assert data.get("dcq.customSetting") == "keep"
820820
assert data.get("eslint.nodePath") == "custom"
821+
assert data.get("eslint.quiet") is True
821822
PY
822823
assert_success
823824

@@ -899,12 +900,29 @@ PY
899900
assert_failure
900901
run grep -q '"eslint.options"' ".vscode/settings.json"
901902
assert_failure
903+
run grep -q '"eslint.quiet": true' ".vscode/settings.json"
904+
assert_success
902905
run grep -q '"stylelint.stylelintPath"' ".vscode/settings.json"
903906
assert_failure
904907
run grep -q '"prettier.prettierPath"' ".vscode/settings.json"
905908
assert_failure
906909
}
907910

911+
@test "VS Code settings respect DCQ_ESLINT_QUIET override" {
912+
set -u -o pipefail
913+
export DCQ_INSTALL_DEPS=skip
914+
export DCQ_INSTALL_NODE_DEPS=skip
915+
export DCQ_INSTALL_IDE_SETTINGS=overwrite
916+
export DCQ_ESLINT_QUIET=0
917+
918+
run ddev add-on get "${DIR}"
919+
assert_success
920+
921+
assert_file_exist ".vscode/settings.json"
922+
run grep -q '"eslint.quiet": false' ".vscode/settings.json"
923+
assert_success
924+
}
925+
908926
@test "path map prefers DDEV_HOST_PROJECT_ROOT" {
909927
set -u -o pipefail
910928
run ddev add-on get "${DIR}"
@@ -1161,6 +1179,7 @@ PY
11611179
assert_log_contains '"stylelint.stylelintPath": "./node_modules/stylelint"' ".vscode/settings.json"
11621180
assert_log_contains '"prettier.prettierPath": "./node_modules/prettier"' ".vscode/settings.json"
11631181
assert_log_contains '"eslint.nodePath": "node_modules"' ".vscode/settings.json"
1182+
assert_log_contains '"eslint.quiet": true' ".vscode/settings.json"
11641183
assert_log_contains '"resolvePluginsRelativeTo": "."' ".vscode/settings.json"
11651184

11661185
run ./.ddev/drupal-code-quality/tooling/bin/phpstan --version

0 commit comments

Comments
 (0)