diff --git a/README.md b/README.md index 9c33fd42..3a3803ec 100644 --- a/README.md +++ b/README.md @@ -505,6 +505,16 @@ SyntaxTree::Rake::WriteTask.new do |t| end ``` +#### `print_width` + +If you want to use a different print width from the default (80), you can pass that to the `print_width` field, as in: + +```ruby +SyntaxTree::Rake::WriteTask.new do |t| + t.print_width = 100 +end +``` + #### `plugins` If you're running Syntax Tree with plugins (either your own or the pre-built ones), you can pass that to the `plugins` field, as in: diff --git a/lib/syntax_tree/rake/check_task.rb b/lib/syntax_tree/rake/check_task.rb index 354cd172..edaa1000 100644 --- a/lib/syntax_tree/rake/check_task.rb +++ b/lib/syntax_tree/rake/check_task.rb @@ -35,14 +35,20 @@ class CheckTask < ::Rake::TaskLib # Defaults to []. attr_accessor :plugins + # Max line length. + # Defaults to 80. + attr_accessor :print_width + def initialize( name = :"stree:check", source_files = ::Rake::FileList["lib/**/*.rb"], - plugins = [] + plugins = [], + print_width = DEFAULT_PRINT_WIDTH ) @name = name @source_files = source_files @plugins = plugins + @print_width = print_width yield self if block_given? define_task @@ -58,6 +64,7 @@ def define_task def run_task arguments = ["check"] arguments << "--plugins=#{plugins.join(",")}" if plugins.any? + arguments << "--print-width=#{print_width}" if print_width != DEFAULT_PRINT_WIDTH SyntaxTree::CLI.run(arguments + Array(source_files)) end diff --git a/lib/syntax_tree/rake/write_task.rb b/lib/syntax_tree/rake/write_task.rb index 5a957480..83c0e77a 100644 --- a/lib/syntax_tree/rake/write_task.rb +++ b/lib/syntax_tree/rake/write_task.rb @@ -35,14 +35,20 @@ class WriteTask < ::Rake::TaskLib # Defaults to []. attr_accessor :plugins + # Max line length. + # Defaults to 80. + attr_accessor :print_width + def initialize( name = :"stree:write", source_files = ::Rake::FileList["lib/**/*.rb"], - plugins = [] + plugins = [], + print_width = DEFAULT_PRINT_WIDTH ) @name = name @source_files = source_files @plugins = plugins + @print_width = print_width yield self if block_given? define_task @@ -58,6 +64,7 @@ def define_task def run_task arguments = ["write"] arguments << "--plugins=#{plugins.join(",")}" if plugins.any? + arguments << "--print-width=#{print_width}" if print_width != DEFAULT_PRINT_WIDTH SyntaxTree::CLI.run(arguments + Array(source_files)) end