From 140c3921795080a66045f90b39ab3defa153f174 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Mon, 18 Jul 2022 18:50:10 -0300 Subject: [PATCH 1/2] Add 120 line width plugin --- lib/syntax_tree/formatter.rb | 9 ++++++--- lib/syntax_tree/plugin/line_width_120.rb | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 lib/syntax_tree/plugin/line_width_120.rb 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_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 From 5061506d65bb57c33d07bf1389e10600b16e2d18 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Tue, 19 Jul 2022 11:01:17 -0300 Subject: [PATCH 2/2] add 100 width plugin --- lib/syntax_tree/plugin/line_width_100.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/syntax_tree/plugin/line_width_100.rb 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