1d87be7d5e
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
- Update REPO: from MokoStandards-API to moko-platform in 125 files - Fix wrong org path (mokoconsulting-tech → MokoConsulting) in 10 files - Fix SPDX-LICENSE-IDENTIFIER case in 2 template files - Add missing REPO: field to 3 files Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.5 KiB
PHP
85 lines
2.5 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: MokoStandards.Scripts.Validate
|
|
* INGROUP: MokoStandards
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
|
* PATH: /validate/check_paths.php
|
|
* BRIEF: Validates that path separators use forward slashes (advisory)
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use MokoEnterprise\CliFramework;
|
|
|
|
/**
|
|
* Warns when backslash characters that look like Windows path separators appear
|
|
* in XML, JSON, YAML and Markdown tracked files (advisory — always exits 0).
|
|
*/
|
|
class CheckPaths extends CliFramework
|
|
{
|
|
/**
|
|
* Configure available arguments.
|
|
*/
|
|
protected function configure(): void
|
|
{
|
|
$this->setDescription('Validates that path separators use forward slashes (advisory)');
|
|
$this->addArgument('--path', 'Repository path to check', '.');
|
|
}
|
|
|
|
/**
|
|
* Scan for backslash path separators (advisory — always exits 0).
|
|
*
|
|
* @return int Exit code: always 0.
|
|
*/
|
|
protected function run(): int
|
|
{
|
|
$path = $this->getArgument('--path');
|
|
$patterns = ['*.xml', '*.json', '*.yml', '*.yaml', '*.md'];
|
|
$quoted = implode(' ', array_map('escapeshellarg', $patterns));
|
|
$output = shell_exec('git -C ' . escapeshellarg($path) . " ls-files {$quoted} 2>/dev/null") ?? '';
|
|
$files = array_values(array_filter(explode("\n", $output)));
|
|
$total = count($files);
|
|
$found = 0;
|
|
|
|
$this->section('Scanning for backslash path separators');
|
|
|
|
foreach ($files as $i => $file) {
|
|
$this->progress($i + 1, $total, $file);
|
|
$fullPath = $path . '/' . $file;
|
|
if (!is_file($fullPath)) {
|
|
continue;
|
|
}
|
|
$content = (string) file_get_contents($fullPath);
|
|
if (preg_match('/\\\\\\\\/', $content)) {
|
|
$stripped = preg_replace('/\\\\(n|t|r|"|\\\\|namespace)/', '', $content);
|
|
if (preg_match('/\\\\\\\\/', (string) $stripped)) {
|
|
$this->progress($i + 1, $total, '', true);
|
|
$this->status(false, $file, 'backslash path separator detected');
|
|
$found++;
|
|
}
|
|
}
|
|
}
|
|
$this->progress($total, $total, '', true);
|
|
|
|
$this->printSummary($total - $found, $found, $this->elapsed());
|
|
|
|
if ($found > 0) {
|
|
$this->log('WARNING', 'Advisory — use forward slashes in path strings');
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
$script = new CheckPaths('check_paths', 'Validates that path separators use forward slashes');
|
|
exit($script->execute());
|