Skip to content

Add print_width config option for rake tasks #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion lib/syntax_tree/rake/check_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/syntax_tree/rake/write_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down