Skip to content

Commit cf97c1b

Browse files
authored
Merge pull request #123 from molawson/rake-print-width-arg
Add print_width config option for rake tasks
2 parents 515aaff + b5758af commit cf97c1b

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,16 @@ SyntaxTree::Rake::WriteTask.new do |t|
505505
end
506506
```
507507

508+
#### `print_width`
509+
510+
If you want to use a different print width from the default (80), you can pass that to the `print_width` field, as in:
511+
512+
```ruby
513+
SyntaxTree::Rake::WriteTask.new do |t|
514+
t.print_width = 100
515+
end
516+
```
517+
508518
#### `plugins`
509519

510520
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:

lib/syntax_tree/rake/check_task.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ class CheckTask < ::Rake::TaskLib
3535
# Defaults to [].
3636
attr_accessor :plugins
3737

38+
# Max line length.
39+
# Defaults to 80.
40+
attr_accessor :print_width
41+
3842
def initialize(
3943
name = :"stree:check",
4044
source_files = ::Rake::FileList["lib/**/*.rb"],
41-
plugins = []
45+
plugins = [],
46+
print_width = DEFAULT_PRINT_WIDTH
4247
)
4348
@name = name
4449
@source_files = source_files
4550
@plugins = plugins
51+
@print_width = print_width
4652

4753
yield self if block_given?
4854
define_task
@@ -58,6 +64,7 @@ def define_task
5864
def run_task
5965
arguments = ["check"]
6066
arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
67+
arguments << "--print-width=#{print_width}" if print_width != DEFAULT_PRINT_WIDTH
6168

6269
SyntaxTree::CLI.run(arguments + Array(source_files))
6370
end

lib/syntax_tree/rake/write_task.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ class WriteTask < ::Rake::TaskLib
3535
# Defaults to [].
3636
attr_accessor :plugins
3737

38+
# Max line length.
39+
# Defaults to 80.
40+
attr_accessor :print_width
41+
3842
def initialize(
3943
name = :"stree:write",
4044
source_files = ::Rake::FileList["lib/**/*.rb"],
41-
plugins = []
45+
plugins = [],
46+
print_width = DEFAULT_PRINT_WIDTH
4247
)
4348
@name = name
4449
@source_files = source_files
4550
@plugins = plugins
51+
@print_width = print_width
4652

4753
yield self if block_given?
4854
define_task
@@ -58,6 +64,7 @@ def define_task
5864
def run_task
5965
arguments = ["write"]
6066
arguments << "--plugins=#{plugins.join(",")}" if plugins.any?
67+
arguments << "--print-width=#{print_width}" if print_width != DEFAULT_PRINT_WIDTH
6168

6269
SyntaxTree::CLI.run(arguments + Array(source_files))
6370
end

0 commit comments

Comments
 (0)