You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

triple-dot-checker.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  4. * @copyright Copyright (c) 2020 Gary Kim <gary@garykim.dev>
  5. *
  6. * @author Gary Kim <gary@garykim.dev>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. $directories = [
  25. __DIR__ . '/../apps',
  26. __DIR__ . '/../core'
  27. ];
  28. $errors = [];
  29. foreach ($directories as $dir) {
  30. $it = new \RecursiveDirectoryIterator($dir);
  31. foreach (new RecursiveIteratorIterator($it) as $file) {
  32. if (($file->getExtension() === 'map') || $file->isDir()) {
  33. continue;
  34. }
  35. $content = file_get_contents($file->getPathname());
  36. $matches = preg_grep('/[^A-Za-z][tn]\([\'"][^\'"]*?[\'"],( ?)[\'"][^\'"]*?(\.\.\.)[^\'"]*?[\'"]/sU', explode(PHP_EOL, $content));
  37. foreach ($matches as $ln => $match) {
  38. if (file_exists($file->getPathname() . '.map')) {
  39. $errors[] = sprintf('At line %d in file %s (file may be transpiled)', $ln, $file);
  40. } else {
  41. $errors[] = sprintf('At line %d in file %s', $ln, $file);
  42. }
  43. }
  44. }
  45. }
  46. echo PHP_EOL . PHP_EOL;
  47. if (count($errors) > 0) {
  48. if (count($errors) > 1) {
  49. echo sprintf('ERROR: There are %d uses of triple dot instead of ellipsis:', count($errors)) . PHP_EOL;
  50. } else {
  51. echo 'ERROR: There is 1 use of triple dot instead of ellipsis:' . PHP_EOL;
  52. }
  53. echo implode(PHP_EOL, $errors) . PHP_EOL;
  54. exit(1);
  55. }
  56. echo 'OK: all good! No use of triple dot instead of ellipsis found.' . PHP_EOL;
  57. exit(0);