Skip to content

Commit 919dafa

Browse files
fix(internal): use null byte as file separator in the fast formatting script
1 parent 71aa1d6 commit 919dafa

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ end
5757
desc("Format `*.rb`")
5858
multitask(:"format:rb") do
5959
# while `syntax_tree` is much faster than `rubocop`, `rubocop` is the only formatter with full syntax support
60-
files = ENV.key?(FILES_ENV) ? %w[sed -E -n -e /\.rb$/p --] << ENV.fetch(FILES_ENV) : %w[find ./lib ./test ./examples -type f -and -name *.rb -print0]
60+
files = ENV.key?(FILES_ENV) ? %w[sed -E -z -n -e /\.rb$/p --] << ENV.fetch(FILES_ENV) : %w[find ./lib ./test ./examples -type f -and -name *.rb -print0]
6161
fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
6262
sh("#{files.shelljoin} | #{fmt.shelljoin}")
6363
end
6464

6565
desc("Format `*.rbi`")
6666
multitask(:"format:rbi") do
67-
files = ENV.key?(FILES_ENV) ? %w[sed -E -n -e /\.rbi$/p --] << ENV.fetch(FILES_ENV) : %w[find ./rbi -type f -and -name *.rbi -print0]
67+
files = ENV.key?(FILES_ENV) ? %w[sed -E -z -n -e /\.rbi$/p --] << ENV.fetch(FILES_ENV) : %w[find ./rbi -type f -and -name *.rbi -print0]
6868
fmt = xargs + %w[stree write --]
6969
sh(ruby_opt, "#{files.shelljoin} | #{fmt.shelljoin}")
7070
end
7171

7272
desc("Format `*.rbs`")
7373
multitask(:"format:rbs") do
74-
files = ENV.key?(FILES_ENV) ? %w[sed -E -n -e /\.rbs$/p --] << ENV.fetch(FILES_ENV) : %w[find ./sig -type f -name *.rbs -print0]
74+
files = ENV.key?(FILES_ENV) ? %w[sed -E -z -n -e /\.rbs$/p --] << ENV.fetch(FILES_ENV) : %w[find ./sig -type f -name *.rbs -print0]
7575
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? ["-i", ""] : %w[-i]
7676
uuid = SecureRandom.uuid
7777

scripts/fast-format

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ echo "Script started with $# arguments"
66
echo "Arguments: $*"
77
echo "Script location: $(dirname "$0")"
88

9-
cd "$(dirname "$0")/.."
10-
echo "Changed to directory: $(pwd)"
9+
cd -- "$(dirname "$0")/.."
10+
echo "Changed to directory: $PWD"
1111

1212
if [ $# -eq 0 ]; then
1313
echo "Usage: $0 <file-with-paths> [additional-formatter-args...]"
1414
echo "The file should contain one file path per line"
1515
exit 1
1616
fi
1717

18-
FORMAT_FILE="$1" exec -- bundle exec rake format
18+
FILE="$(mktemp)"
19+
tr -- '\n' '\0' < "$1" > "$FILE"
20+
21+
exec -- bundle exec rake format FORMAT_FILE="$FILE"

0 commit comments

Comments
 (0)