Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/adminer-plugin/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ your output and `exit` — this is how `sql-gemini.php` answers its own AJAX POS

Our own code is PSR-4 `Desktop\` under `app/src/`, native types on properties, `[]` not
`array()`, enums over magic strings. The downloaded catalogue in `available/` is
**excluded** from phpstan and dresscode (`phpstan.neon`, `dresscode.neon`) — so upstream's
**excluded** from phpstan and dresscode (`phpstan.neon`, `app/dresscode.neon`) — so upstream's
untyped style there is not a signal for code you write. A hook overriding an untyped
adminer method keeps adminer's shape (phpdoc `@param`/`@return`, or a `// dresscode:ignore`),
because PHP forbids narrowing an inherited signature.
Expand Down
10 changes: 9 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ in the packaged app (where `app/` is the document root and there is no root abov
`composer.json`/`composer.lock` moved there too; run composer with
`--working-dir=app`, as the `app/vendor` target does. We do not vendor Go deps.

**`dresscode.neon` stays in `app/`, beside `vendor/`.** Anywhere else DressCode takes `app/` for
foreign code, and a rule that needs types finds nothing there and exits 0. Its type rules read
`phpstan.neon` from that root too, hence `app/phpstan.neon`, which includes the real one. `cli/` lies
outside the root, so `cli/dresscode.sh` names those files and the hook drops `--skip-excluded` for them;
run dresscode through `make dresscode`, because `check -c app/dresscode.neon` alone skips `cli/` and
says OK. That script fails unless `tests/dresscode/override-missing.php`, copied into `app/` and `cli/`
for one run, is reported from both.

**Our code is PSR-4 under `src/`.** `app/composer.json` maps `"Desktop\\": "src/"`, so a
`Desktop\` class loads from the matching path — `Desktop\Settings\Theme\Theme` →
`src/Settings/Theme/Theme.php`, filename and case matching the class. The case match is not
Expand Down Expand Up @@ -275,7 +283,7 @@ type on every property (`private ?string $file`, not a bare `private $file` on a
stays only for what the native type can't say — an array's shape), `[]` not `array()`, and an
enum for a fixed set of values (`Desktop\Mode` for the light/dark scheme) rather than a magic
string. `make qa` enforces these: phpstan at level 6 for parameter, return and value types,
and dresscode (`dresscode.neon`) for what phpstan does not judge — native
and dresscode (`app/dresscode.neon`) for what phpstan does not judge — native
property and constant declarations, short array syntax, tabs, `strict_types`. Both run through the bundled frankenphp, no
separate PHP install. The exceptions are adminer's own downloaded files (excluded) and a
method or property that overrides an untyped one in adminer's base class — those keep
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ phpstan: fetch app/vendor $(PHPSTAN_INI)/phpstan.ini
PHP_INI_SCAN_DIR=$(PHPSTAN_INI) ./bin/frankenphp$(EXE) php-cli app/vendor/phpstan/phpstan/phpstan.phar analyse -c phpstan.neon \
--no-progress --debug --memory-limit=2G

# The conventions phpstan does not judge, listed in dresscode.neon, which also excludes adminer's
# The conventions phpstan does not judge, listed in app/dresscode.neon, which also excludes adminer's
# own downloaded files. --jobs 1 because its workers start through PHP_BINARY, and under
# frankenphp's php-cli that is frankenphp itself, which takes `check` for a command of its own.
dresscode: app/vendor
./bin/frankenphp$(EXE) php-cli app/vendor/bin/dresscode check --jobs 1
# fetch because typeAnalysis reads phpstan.neon, and without the files it names only warns.
Comment thread
landsman marked this conversation as resolved.
Resolved
dresscode: fetch app/vendor
./cli/dresscode.sh ./bin/frankenphp$(EXE)

# What .claude/settings.json runs after an agent's edit, the edit's JSON on stdin. Silent and with no
# prerequisites: what it prints goes to the agent, and an edit must not start a composer install.
Expand Down Expand Up @@ -325,8 +326,8 @@ qa: fetch app/vendor i18n mcp-bridge-data ## Run every static check (php, go, j
|| { echo "launcher: no non-darwin definition of $$f() (menu_other.go stub, or *_linux.go + *_other.go or *_windows.go split)"; exit 1; }; \
done && echo "platform stubs ok"
@command -v shellcheck >/dev/null \
&& { shellcheck check.sh cli/compile-adminer.sh cli/kill-orphans.sh cli/demo-mysql.sh tests/cli/kill-orphans-test.sh tests/launcher/downloads.sh && echo "shellcheck ok"; } \
|| { sh -n check.sh && sh -n cli/compile-adminer.sh && sh -n cli/kill-orphans.sh && sh -n cli/demo-mysql.sh && echo "sh ok (shellcheck not installed)"; }
&& { shellcheck check.sh cli/compile-adminer.sh cli/dresscode.sh cli/kill-orphans.sh cli/demo-mysql.sh tests/cli/dresscode-test.sh tests/cli/dresscode-hook-test.sh tests/cli/kill-orphans-test.sh tests/launcher/downloads.sh && echo "shellcheck ok"; } \
|| { sh -n check.sh && sh -n cli/compile-adminer.sh && sh -n cli/dresscode.sh && sh -n cli/kill-orphans.sh && sh -n cli/demo-mysql.sh && echo "sh ok (shellcheck not installed)"; }
@# Native-shell strings: the `i18n` prerequisite already generated the real files (which is
@# also what makes i18n_gen.h exist before `go vet` compiles the cgo launcher above). Assert the
@# generator's output quality and lint the emitted plists. `make i18n-check` reports coverage.
Expand All @@ -335,6 +336,8 @@ qa: fetch app/vendor i18n mcp-bridge-data ## Run every static check (php, go, j
./bin/frankenphp$(EXE) php-cli tests/shortcuts/ShortcutsTest.php
./bin/frankenphp$(EXE) php-cli tests/cli/WindowsIcoTest.php
@sh tests/cli/kill-orphans-test.sh
@sh tests/cli/dresscode-test.sh
@sh tests/cli/dresscode-hook-test.sh
@# The launcher's own download code against the real webview, every way adminer starts one.
@sh tests/launcher/downloads.sh
@command -v plutil >/dev/null && plutil -lint Info.plist.in lproj/*/Localizable.strings >/dev/null && echo "i18n + plists ok" || echo "i18n ok (plutil skipped, macOS only)"
Expand Down Expand Up @@ -585,6 +588,7 @@ DIST = build.noindex/pkg/adminer-desktop
define package-app
rm -rf $(1)/cli
$(COMPOSER) install --no-dev --no-interaction --working-dir=$(1)
rm -f $(1)/*.neon
$(if $(EXE),,./bin/frankenphp php-cli cli/latte-precompile.php $(1))
endef

Expand Down
1 change: 1 addition & 0 deletions app/AdminerDesktop.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function t(string $idf): string {
* the language files with every other string rather than as a special case.
* @return string
*/
#[Override]
function description(): string {
return $this->t('plugin.description');
}
Expand Down
23 changes: 16 additions & 7 deletions dresscode.neon → app/dresscode.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
# follows adminer's, and only what is decided here gets reported.
# https://dresscode.run/

# cli/ lies outside this root, where a directory is not walked: cli/dresscode.sh names its files.
paths:
- app
- cli
- .

# Beside vendor/ on purpose: from anywhere else DressCode takes app/, its own installation, for
# foreign code, and the rules that need types find nothing there and still exit 0.
typeAnalysis: phpstan

# Everything that ships verbatim from the adminer release keeps its own conventions.
excludePaths:
- app/vendor
- app/adminer.php
- app/editor.php
- app/src/Settings/Plugins/available
- app/src/Settings/Theme/designs
- vendor
- adminer.php
- editor.php
- src/Settings/Plugins/available
- src/Settings/Theme/designs

# composer.json names no PHP version; this is frankenphp's, the one the app runs on.
targets:
Expand All @@ -39,3 +43,8 @@ types:
declaration:
property: required
constant: required

# PHP then refuses a parent renaming a member under us, instead of leaving a silent new one.
upgrading:
classes:
Override: required
3 changes: 3 additions & 0 deletions app/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# What dresscode's type rules read: it looks for this file only in its own root, app/.
includes:
- ../phpstan.neon
1 change: 1 addition & 0 deletions app/src/Latte.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static function engine(): Engine {
// differs on every machine, so a cache compiled by the build would never be found;
// relative to app/ it is the same wherever the app was unpacked.
$latte->setLoader(new class extends FileLoader {
#[\Override]
function getUniqueId(string $file): string {
return str_replace(dirname(__DIR__), "", $file);
}
Expand Down
30 changes: 25 additions & 5 deletions cli/dresscode-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Not nette's php-fixer plugin, which needs a `php` on PATH and starts dresscode through
* PHP_BINARY: there is no `php` here, and that binary is frankenphp.
*
* A rule the file already broke stays broken (--before), and a file dresscode.neon leaves out
* stays as written (--skip-excluded), so an edit never rewrites adminer's own files.
* A rule the file already broke stays broken (--before), and a file dresscode.neon leaves out stays
* as written (--skip-excluded, for all but cli/), so an edit never rewrites adminer's own files.
*/

$input = json_decode((string) file_get_contents("php://stdin"), true);
Expand All @@ -15,8 +15,20 @@
exit(0);
}

$root = dirname(__DIR__);
$command = [PHP_BINARY, "php-cli", $root . "/app/vendor/bin/dresscode", "fix", $file, "--format", "agent", "--no-color", "--skip-excluded", "--jobs", "1"];
$file = (string) realpath($file);

// The hook runs from the session's checkout, but an edit in a worktree belongs to that worktree's
// config and dresscode: an installation outside the config's root finds nothing, and exits 0.
$root = preg_match('~^(.*/\.claude/worktrees/[^/]+)/~', $file, $match) === 1 ? $match[1] : dirname(__DIR__);
Comment thread
landsman marked this conversation as resolved.
Resolved
if (!is_file($root . "/app/vendor/bin/dresscode")) {
tellAgent("dresscode did not run on $file: $root has no app/vendor. Run make qa there.");
exit(0);
}
$command = [PHP_BINARY, "php-cli", $root . "/app/vendor/bin/dresscode", "fix", $file, "-c", $root . "/app/dresscode.neon", "--format", "agent", "--no-color", "--jobs", "1"];
// cli/ lies outside the config's root, so --skip-excluded would leave every file there unchecked.
if (!str_starts_with($file, $root . "/cli/")) {
Comment thread
landsman marked this conversation as resolved.
Resolved
$command[] = "--skip-excluded";
}
$original = $input["tool_response"]["originalFile"] ?? null;
$before = is_string($original) ? tempnam(sys_get_temp_dir(), "dresscode-before-") : false;
if ($before !== false && file_put_contents($before, $original) !== false) {
Expand All @@ -43,6 +55,14 @@
fwrite(STDERR, ($stdout ?: $stderr ?: "dresscode failed on $file with exit code $status") . "\n");
exit(2);
}
// Without adminer's files a method overriding Adminer\Plugin has no parent, and its rules report clean.
if (!is_file($root . "/app/adminer.php")) {
$stdout = trim("$stdout\nThe rules that need adminer's classes did not check $file: $root has no app/adminer.php. Run make fetch there.");
}
if ($stdout !== "") {
echo json_encode(["hookSpecificOutput" => ["hookEventName" => "PostToolUse", "additionalContext" => $stdout]], JSON_INVALID_UTF8_SUBSTITUTE);
tellAgent($stdout);
}

function tellAgent(string $text): void {
echo json_encode(["hookSpecificOutput" => ["hookEventName" => "PostToolUse", "additionalContext" => $text]], JSON_INVALID_UTF8_SUBSTITUTE);
}
42 changes: 42 additions & 0 deletions cli/dresscode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
# Runs dresscode over app/ and each PHP file in cli/, then again with a file that breaks a type rule
# in both. A clean run cannot tell a checked file from one dropped without a word, and the type rules
# go silent with exit 0 when dresscode.neon leaves app/.
# Usage: cli/dresscode.sh <frankenphp>
set -eu

frankenphp=$1

run() {
find cli -name '*.php' -exec "$frankenphp" php-cli app/vendor/bin/dresscode check --jobs 1 -c app/dresscode.neon --no-color "$@" app {} +
}

if [ ! -f app/phpstan.neon ]; then
echo "app/phpstan.neon is missing: dresscode's type rules would run without phpstan.neon, and not say so" >&2
exit 1
fi

run

trap 'rm -f app/override-missing.php cli/override-missing.php' EXIT
# dash skips the EXIT trap on a signal unless the signal itself exits
trap 'exit 130' INT TERM
for file in app/override-missing.php cli/override-missing.php; do
cp tests/dresscode/override-missing.php "$file"
done

# A fixed format: under GitHub Actions the default one prints each finding twice.
output=$(run --format agent || true)
case $output in
*"the types go without it"*)
printf '%s\n' "$output"
echo "dresscode's type rules run without phpstan.neon" >&2
exit 1
;;
esac
found=$(printf '%s\n' "$output" | grep -c upgrading.classes.Override || true)
if [ "$found" != 2 ]; then
printf '%s\n' "$output"
echo "dresscode's type rules went silent: reported tests/dresscode/override-missing.php $found times of 2, once from app/ and once from cli/" >&2
exit 1
fi
23 changes: 23 additions & 0 deletions tests/cli/dresscode-hook-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
# cli/dresscode-hook.php given a file in cli/ spelled through a symlink, as /tmp is on macOS: a plain
# comparison takes it for a file outside cli/ and skips it with exit 0. Run by `make qa`.
set -eu

root=$(cd "$(dirname "$0")/../.." && pwd)
dir=$(mktemp -d)
probe=$root/cli/hook-probe-$$.php
trap 'rm -rf "$dir" "$probe"' EXIT
ln -s "$root" "$dir/link"
cat > "$probe" <<'PHP'
<?php
declare(strict_types=1);
$a = array();
PHP

printf '{"tool_input":{"file_path":"%s"}}' "$dir/link/cli/$(basename "$probe")" \
| "$root/bin/frankenphp" php-cli "$root/cli/dresscode-hook.php" >/dev/null 2>&1 || true
if grep -q 'array()' "$probe"; then
echo "dresscode-hook skipped a file in cli/ reached through a symlink" >&2
exit 1
fi
echo "dresscode-hook ok"
60 changes: 60 additions & 0 deletions tests/cli/dresscode-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
# What cli/dresscode.sh would get wrong silently: passing when a type rule went quiet in app/ or cli/,
# or when phpstan.neon was not read, and leaving its bad files behind. Stubs dresscode. Run by `make qa`.
set -eu

script=$(cd "$(dirname "$0")/../.." && pwd)/cli/dresscode.sh
dir=$(mktemp -d)
trap 'rm -rf "$dir"' EXIT
cd "$dir"
mkdir -p app cli tests/dresscode
touch app/phpstan.neon cli/a.php tests/dresscode/override-missing.php
cat > stub <<'STUB'
#!/bin/sh
[ -e app/override-missing.php ] || exit "${CLEAN_EXIT:-0}"
printf '%b\n' "$REPORT"
exit 1
STUB
chmod +x stub
rule=upgrading.classes.Override
failed=0

check() { # <behaviour> <wanted exit> <report> [clean run's exit]
got=0
REPORT=$3 CLEAN_EXIT=${4:-0} "$script" ./stub >/dev/null 2>&1 || got=$?
if [ "$got" = "$2" ] && [ ! -e app/override-missing.php ] && [ ! -e cli/override-missing.php ]; then
echo "ok $1"
else
echo "FAIL $1 (exit $got)"
failed=1
fi
}

check "passes when both bad files are reported" 0 "$rule\n$rule"
check "fails when only one is reported" 1 "$rule"
check "fails when neither is" 1 "OK"
check "fails when phpstan.neon was not read" 1 "$rule\n$rule\nthe types go without it"
check "fails on a finding in the real code" 1 "" 3

rm app/phpstan.neon
check "fails when app/phpstan.neon is gone" 1 "$rule\n$rule"
touch app/phpstan.neon

cat > stub <<'STUB'
#!/bin/sh
[ -e app/override-missing.php ] || exit 0
touch started
sleep 1
STUB
"$script" ./stub >/dev/null 2>&1 &
pid=$!
while [ ! -e started ]; do sleep 0.1; done
kill -TERM "$pid"
wait "$pid" || true
if [ -e app/override-missing.php ] || [ -e cli/override-missing.php ]; then
echo "FAIL an interrupted run removes its bad files"
failed=1
else
echo "ok an interrupted run removes its bad files"
fi
exit "$failed"
15 changes: 15 additions & 0 deletions tests/dresscode/override-missing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

// Breaks upgrading.classes.Override on purpose: `make dresscode` fails unless it is reported, because
// a rule that needs types can go silent and still exit 0.

class OverrideMissingParent {
function method(): void {
}
}

class OverrideMissingChild extends OverrideMissingParent {
function method(): void {
}
}
Loading