Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85f6134

Browse files
committed
Only write files when content changes
Previously the CLI would call `File.write` for every file, even if the contents was unchanged. This unnecessary filesystem churn can have a knock-on effect on other tools which may be watching directories for changes (e.g. IDEs). This commit updates the `stree write` command so that it only performs a write when the file contents has changed.
1 parent e1d89ee commit 85f6134

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/syntax_tree/cli.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ def run(item)
303303
options.print_width,
304304
options: options.formatter_options
305305
)
306+
changed = source != formatted
306307

307-
File.write(filepath, formatted) if item.writable?
308+
File.write(filepath, formatted) if item.writable? && changed
308309

309-
color = source == formatted ? Color.gray(filepath) : filepath
310+
color = changed ? filepath : Color.gray(filepath)
310311
delta = ((Time.now - start) * 1000).round
311312

312313
puts "#{color} #{delta}ms"

0 commit comments

Comments
 (0)