1
0

triple-dot-checker.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. $directories = [
  7. __DIR__ . '/../apps',
  8. __DIR__ . '/../core'
  9. ];
  10. $errors = [];
  11. foreach ($directories as $dir) {
  12. $it = new \RecursiveDirectoryIterator($dir);
  13. foreach (new RecursiveIteratorIterator($it) as $file) {
  14. if (($file->getExtension() === 'map') || $file->isDir()) {
  15. continue;
  16. }
  17. $content = file_get_contents($file->getPathname());
  18. $matches = preg_grep('/[^A-Za-z][tn]\([\'"][^\'"]*?[\'"],( ?)[\'"][^\'"]*?(\.\.\.)[^\'"]*?[\'"]/sU', explode(PHP_EOL, $content));
  19. foreach ($matches as $ln => $match) {
  20. if (file_exists($file->getPathname() . '.map')) {
  21. $errors[] = sprintf('At line %d in file %s (file may be transpiled)', $ln, $file);
  22. } else {
  23. $errors[] = sprintf('At line %d in file %s', $ln, $file);
  24. }
  25. }
  26. }
  27. }
  28. echo PHP_EOL . PHP_EOL;
  29. if (count($errors) > 0) {
  30. if (count($errors) > 1) {
  31. echo sprintf('ERROR: There are %d uses of triple dot instead of ellipsis:', count($errors)) . PHP_EOL;
  32. } else {
  33. echo 'ERROR: There is 1 use of triple dot instead of ellipsis:' . PHP_EOL;
  34. }
  35. echo implode(PHP_EOL, $errors) . PHP_EOL;
  36. exit(1);
  37. }
  38. echo 'OK: all good! No use of triple dot instead of ellipsis found.' . PHP_EOL;
  39. exit(0);