Skip to content

Commit 0ff5030

Browse files
committed
Support maxwidth on format
1 parent ca1253c commit 0ff5030

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Support an optional `maxwidth` second argument to `SyntaxTree.format`.
12+
913
### Changed
1014

1115
- Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key.

lib/syntax_tree.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def self.parse(source)
4040
end
4141

4242
# Parses the given source and returns the formatted source.
43-
def self.format(source)
44-
formatter = Formatter.new(source, [])
43+
def self.format(source, maxwidth = 80)
44+
formatter = Formatter.new(source, [], maxwidth)
4545
parse(source).format(formatter)
4646

4747
formatter.flush

test/syntax_tree_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_parse_error
2929
assert_raises(Parser::ParseError) { SyntaxTree.parse("<>") }
3030
end
3131

32+
def test_maxwidth_format
33+
assert_equal("foo +\n bar\n", SyntaxTree.format("foo + bar", 5))
34+
end
35+
3236
def test_read
3337
source = SyntaxTree.read(__FILE__)
3438
assert_equal(Encoding.default_external, source.encoding)

0 commit comments

Comments
 (0)