diff --git a/lib/syntax_tree/formatter.rb b/lib/syntax_tree/formatter.rb index 6efad8d8..c0eb81c4 100644 --- a/lib/syntax_tree/formatter.rb +++ b/lib/syntax_tree/formatter.rb @@ -14,7 +14,7 @@ class Formatter < PrettierPrint # Note that we're keeping this in a global-ish hash instead of just # overriding methods on classes so that other plugins can reference this if # necessary. For example, the RBS plugin references the quote style. - OPTIONS = { quote: "\"", trailing_comma: false } + OPTIONS = { quote: "\"", trailing_comma: false, line_width: 80 } COMMENT_PRIORITY = 1 HEREDOC_PRIORITY = 2 @@ -23,15 +23,18 @@ class Formatter < PrettierPrint # These options are overridden in plugins to we need to make sure they are # available here. - attr_reader :quote, :trailing_comma + attr_reader :quote, :trailing_comma, :line_width alias trailing_comma? trailing_comma def initialize( source, *args, quote: OPTIONS[:quote], - trailing_comma: OPTIONS[:trailing_comma] + trailing_comma: OPTIONS[:trailing_comma], + line_width: OPTIONS[:line_width] ) + # Loads custom line_width plugin + args[1] = line_width super(*args) @source = source diff --git a/lib/syntax_tree/plugin/line_width_100.rb b/lib/syntax_tree/plugin/line_width_100.rb new file mode 100644 index 00000000..2a0b1af8 --- /dev/null +++ b/lib/syntax_tree/plugin/line_width_100.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +SyntaxTree::Formatter::OPTIONS[:line_width] = 100 diff --git a/lib/syntax_tree/plugin/line_width_120.rb b/lib/syntax_tree/plugin/line_width_120.rb new file mode 100644 index 00000000..c2f126c4 --- /dev/null +++ b/lib/syntax_tree/plugin/line_width_120.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +SyntaxTree::Formatter::OPTIONS[:line_width] = 120