aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/linters/lint2
-rw-r--r--scripts/linters/src/Linters/PhpSrcDerivationBoundary.php54
2 files changed, 56 insertions, 0 deletions
diff --git a/scripts/linters/lint b/scripts/linters/lint
index bcdf1c67..44ea7f6d 100755
--- a/scripts/linters/lint
+++ b/scripts/linters/lint
@@ -13,6 +13,7 @@ use Shirabe\Lint\Linters\NoFormatTrailingComma;
use Shirabe\Lint\Linters\NoModRs;
use Shirabe\Lint\Linters\NoStdCollectionsMaps;
use Shirabe\Lint\Linters\NoUseAsAlias;
+use Shirabe\Lint\Linters\PhpSrcDerivationBoundary;
use Shirabe\Lint\Linters\SortedDependencies;
use Shirabe\Lint\Runner;
@@ -32,6 +33,7 @@ $runner = new Runner($rootDir, [
[new NoModRs(), []],
[new NoStdCollectionsMaps(), []],
[new NoUseAsAlias(), []],
+ [new PhpSrcDerivationBoundary(), []],
[new SortedDependencies(), []],
]);
diff --git a/scripts/linters/src/Linters/PhpSrcDerivationBoundary.php b/scripts/linters/src/Linters/PhpSrcDerivationBoundary.php
new file mode 100644
index 00000000..6885f171
--- /dev/null
+++ b/scripts/linters/src/Linters/PhpSrcDerivationBoundary.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Shirabe\Lint\Linters;
+
+use Shirabe\Lint\Linter;
+use Shirabe\Lint\Support\FileFinder;
+use Shirabe\Lint\Support\Paths;
+
+final class PhpSrcDerivationBoundary implements Linter
+{
+ private const PHP_SRC_CRATE_PREFIX = 'crates/shirabe-php-src/';
+
+ // The origin marker every php-src derived item carries, plus the bare crate name.
+ private const MARKER_RE = '/php-src/i';
+
+ public function name(): string
+ {
+ return 'php_src_derivation_boundary';
+ }
+
+ public function failureIntro(): string
+ {
+ return "Found `php-src` mentioned outside the `shirabe-php-src` crate.\n"
+ . "Code written by reading php-src is licensed under php-src's terms, not Shirabe's MIT,\n"
+ . 'so it must live in `crates/shirabe-php-src/` and be reached through that crate:';
+ }
+
+ public function check(string $rootDir, array $excludes): array
+ {
+ $errors = [];
+
+ foreach (FileFinder::rustFiles($rootDir) as $path) {
+ $relative = Paths::relativeTo($rootDir, $path);
+ if (str_starts_with($relative, self::PHP_SRC_CRATE_PREFIX)) {
+ continue;
+ }
+ if (in_array($relative, $excludes, true)) {
+ continue;
+ }
+
+ foreach (file($path) as $idx => $raw) {
+ if (!preg_match(self::MARKER_RE, $raw)) {
+ continue;
+ }
+
+ $errors[] = "{$relative}:" . ($idx + 1) . ': ' . trim($raw);
+ }
+ }
+
+ return $errors;
+ }
+}