remove-trailing-whitespace.php 943B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/php
  2. <?php
  3. chdir(dirname(__FILE__));
  4. require_once 'common.php';
  5. assertCli();
  6. /**
  7. * @file
  8. * Removes trailing whitespace from files.
  9. */
  10. chdir(dirname(__FILE__) . '/..');
  11. $FS = new FSTools();
  12. $files = $FS->globr('.', '{,.}*', GLOB_BRACE);
  13. foreach ($files as $file) {
  14. if (
  15. !is_file($file) ||
  16. prefix_is('./.git', $file) ||
  17. prefix_is('./docs/doxygen', $file) ||
  18. postfix_is('.ser', $file) ||
  19. postfix_is('.tgz', $file) ||
  20. postfix_is('.patch', $file) ||
  21. postfix_is('.dtd', $file) ||
  22. postfix_is('.ent', $file) ||
  23. $file == './library/HTMLPurifier/Lexer/PH5P.php' ||
  24. $file == './maintenance/PH5P.php'
  25. ) continue;
  26. $contents = file_get_contents($file);
  27. $result = preg_replace('/^(.*?)[ \t]+(\r?)$/m', '\1\2', $contents, -1, $count);
  28. if (!$count) continue;
  29. echo "$file\n";
  30. file_put_contents($file, $result);
  31. }
  32. // vim: et sw=4 sts=4