diff --git a/lib/syntax_tree.rb b/lib/syntax_tree.rb index c2cb3484..418468a9 100644 --- a/lib/syntax_tree.rb +++ b/lib/syntax_tree.rb @@ -40,6 +40,10 @@ module SyntaxTree # optional second argument to ::format. DEFAULT_PRINT_WIDTH = 80 + # This is the default ruby version that we're going to target for formatting. + # It shouldn't really be changed except in very niche circumstances. + DEFAULT_RUBY_VERSION = Formatter::SemanticVersion.new(RUBY_VERSION).freeze + # This is a hook provided so that plugins can register themselves as the # handler for a particular file type. def self.register_handler(extension, handler) diff --git a/lib/syntax_tree/cli.rb b/lib/syntax_tree/cli.rb index 3975df18..392dd627 100644 --- a/lib/syntax_tree/cli.rb +++ b/lib/syntax_tree/cli.rb @@ -377,14 +377,19 @@ class Options :plugins, :print_width, :scripts, - :formatter_options + :target_ruby_version def initialize @ignore_files = [] @plugins = [] @print_width = DEFAULT_PRINT_WIDTH @scripts = [] - @formatter_options = Formatter::Options.new + @target_ruby_version = DEFAULT_RUBY_VERSION + end + + def formatter_options + @formatter_options ||= + Formatter::Options.new(target_ruby_version: target_ruby_version) end def parse(arguments) @@ -430,10 +435,7 @@ def parser # If there is a target ruby version specified on the command line, # parse that out and use it when formatting. opts.on("--target-ruby-version=VERSION") do |version| - @formatter_options = - Formatter::Options.new( - target_ruby_version: Formatter::SemanticVersion.new(version) - ) + @target_ruby_version = Formatter::SemanticVersion.new(version) end end end