Skip to content

Commit ee84d7c

Browse files
committed
Rename plugin/disable_ternary to plugin/disable_auto_ternary
1 parent 475e0c5 commit ee84d7c

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ To register plugins, define a file somewhere in your load path named `syntax_tre
658658

659659
* `plugin/single_quotes` - This will change all of your string literals to use single quotes instead of the default double quotes.
660660
* `plugin/trailing_comma` - This will put trailing commas into multiline array literals, hash literals, and method calls that can support trailing commas.
661-
* `plugin/disable_ternary` - This will prevent the automatic conversion of `if ... else` to ternary expressions.
661+
* `plugin/disable_auto_ternary` - This will prevent the automatic conversion of `if ... else` to ternary expressions.
662662

663663
If you're using Syntax Tree as a library, you can require those files directly or manually pass those options to the formatter initializer through the `SyntaxTree::Formatter::Options` class.
664664

lib/syntax_tree/formatter.rb

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ def initialize(version)
2323
class Options
2424
attr_reader :quote,
2525
:trailing_comma,
26-
:disable_ternary,
26+
:disable_auto_ternary,
2727
:target_ruby_version
2828

2929
def initialize(
3030
quote: :default,
3131
trailing_comma: :default,
32-
disable_ternary: :default,
32+
disable_auto_ternary: :default,
3333
target_ruby_version: :default
3434
)
3535
@quote =
@@ -54,15 +54,15 @@ def initialize(
5454
trailing_comma
5555
end
5656

57-
@disable_ternary =
58-
if disable_ternary == :default
57+
@disable_auto_ternary =
58+
if disable_auto_ternary == :default
5959
# We ship with a disable ternary plugin that will define this
6060
# constant. That constant is responsible for determining the default
6161
# disable ternary value. If it's defined, then we default to true.
6262
# Otherwise we default to false.
6363
defined?(DISABLE_TERNARY)
6464
else
65-
disable_ternary
65+
disable_auto_ternary
6666
end
6767

6868
@target_ruby_version =
@@ -84,9 +84,13 @@ def initialize(
8484

8585
# These options are overridden in plugins to we need to make sure they are
8686
# available here.
87-
attr_reader :quote, :trailing_comma, :disable_ternary, :target_ruby_version
87+
attr_reader :quote,
88+
:trailing_comma,
89+
:disable_auto_ternary,
90+
:target_ruby_version
91+
8892
alias trailing_comma? trailing_comma
89-
alias disable_ternary? disable_ternary
93+
alias disable_auto_ternary? disable_auto_ternary
9094

9195
def initialize(source, *args, options: Options.new)
9296
super(*args)
@@ -97,7 +101,7 @@ def initialize(source, *args, options: Options.new)
97101
# Memoizing these values to make access faster.
98102
@quote = options.quote
99103
@trailing_comma = options.trailing_comma
100-
@disable_ternary = options.disable_ternary
104+
@disable_auto_ternary = options.disable_auto_ternary
101105
@target_ruby_version = options.target_ruby_version
102106
end
103107

lib/syntax_tree/node.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -6139,8 +6139,7 @@ def self.call(parent)
61396139
module Ternaryable
61406140
class << self
61416141
def call(q, node)
6142-
return false if ENV["STREE_FAST_FORMAT"]
6143-
return false if q.disable_ternary?
6142+
return false if ENV["STREE_FAST_FORMAT"] || q.disable_auto_ternary?
61446143

61456144
# If this is a conditional inside of a parentheses as the only content,
61466145
# then we don't want to transform it into a ternary. Presumably the user

test/plugin/disable_ternary_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_short_ternary_unchanged
2121
private
2222

2323
def assert_format(expected, source = expected)
24-
options = Formatter::Options.new(disable_ternary: true)
24+
options = Formatter::Options.new(disable_auto_ternary: true)
2525
formatter = Formatter.new(source, [], options: options)
2626
SyntaxTree.parse(source).format(formatter)
2727

0 commit comments

Comments
 (0)