ίʔυEJGG جຊతͳมߋ
w legacy_sourceͱͯ͠ݩͷҾͰ
ड͚ೖΕΔΑ͏ʹ͢Δ
w legacy_source͕͞Εͨ߹ܯ
ࠂΛදࣔͯ͠ɺͦͷΛ༏ઌͯ͠͏
Slide 84
Slide 84 text
ͦΕΛ"1*
Slide 85
Slide 85 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
"1*ͷରԠͱ
Slide 86
Slide 86 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
ϝιου໊
"1*ͷରԠͱ
Slide 87
Slide 87 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
Ҿ໊
"1*ͷରԠͱ
Slide 88
Slide 88 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
Ҿͷ
"1*ͷରԠͱ
Slide 89
Slide 89 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
σϑΥϧτ
"1*ͷରԠͱ
Slide 90
Slide 90 text
def saying(legacy_source = NOT_GIVEN, source: nil)
if legacy_source != NOT_GIVEN
warn_with_uplevel 'Passing `source` with the \
1st argument of `Dune.saying` is deprecated. \
Use keyword argument like \
`Dune.saying(source: ...)` instead.',
uplevel: 1
source = legacy_source
end
end
ܯࠂจ
"1*ͷରԠͱ
CBEέʔεΛଊ͑Δ࣮ྫ
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
Slide 100
Slide 100 text
CBEέʔεΛଊ͑Δ࣮ྫ
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
EFGϊʔυͷॲཧ
Slide 101
Slide 101 text
CBEέʔεΛଊ͑Δ࣮ྫ
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
ܯࠂΛग़͢"1*
Slide 102
Slide 102 text
CBEέʔεΛଊ͑Δ࣮ྫ
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
ܯࠂ͠ͳ͍݅
Slide 103
Slide 103 text
CBEέʔεΛଊ͑Δ࣮ྫ
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
ܯࠂ͠ͳ͍݅
ϊʔυͷλΠϓ
% ruby-parse -e 'def do_something(foo:, bar: 1);
end'
(def :do_something
(args
(kwarg :foo)
(kwoptarg :bar
(int 1))) nil)
Slide 104
Slide 104 text
class BreakingChangeArguments < Cop
def on_def(node)
return unless node.arguments.all? {|argument|
argument.kwarg_type? ||
argument.kwoptarg_type?
}
node.arguments.reverse_each do |argument|
message = format(
MSG, name: argument.children.first
)
add_offense(argument, message: message)
end
end
end
ܯࠂ͠ͳ͍݅
% ruby-parse -e 'def do_something(foo:, bar: 1);
end'
(def :do_something
(args
(kwarg :foo)
(kwoptarg :bar
(int 1))) nil)
CBEέʔεΛଊ͑Δ࣮ྫ
ϊʔυͷλΠϓ
Slide 105
Slide 105 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
def autocorrect(node)
kwarg = node.children.first
argument_index =
node.parent.parent.arguments.map {|argument|
argument.children.first
}.index(kwarg) + 1
index = case argument_index
when 1; '1st'
when 2; '2nd'
when 3; '3rd'
else
"#{argument_index}th"
end
Slide 106
Slide 106 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
def autocorrect(node)
kwarg = node.children.first
argument_index =
node.parent.parent.arguments.map {|argument|
argument.children.first
}.index(kwarg) + 1
index = case argument_index
when 1; '1st'
when 2; '2nd'
when 3; '3rd'
else
"#{argument_index}th"
end
ࣗಈमਖ਼
ͷίʔϧόοΫ
ఆٛ
Slide 107
Slide 107 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
def autocorrect(node)
kwarg = node.children.first
argument_index =
node.parent.parent.arguments.map {|argument|
argument.children.first
}.index(kwarg) + 1
index = case argument_index
when 1; '1st'
when 2; '2nd'
when 3; '3rd'
else
"#{argument_index}th"
end
LXBSHͷ
ϊʔυ
Slide 108
Slide 108 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
def autocorrect(node)
kwarg = node.children.first
argument_index =
node.parent.parent.arguments.map {|argument|
argument.children.first
}.index(kwarg) + 1
index = case argument_index
when 1; '1st'
when 2; '2nd'
when 3; '3rd'
else
"#{argument_index}th"
end
LXBSHͷ
ҾҐஔ
Slide 109
Slide 109 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
legacy_argument = "legacy_#{kwarg}"
class_name = find_class_name(node)
method_name = node.parent.parent.method_name
condition += <<-RUBY
if #{legacy_argument} != NOT_GIVEN
warn_with_uplevel 'Passing `#{kwarg}` with
the #{index} argument of
`#{class_name}.#{method_name}` is deprecated. Use
keyword argument like `#{class_name}.#{method_name}
(#{kwarg}: ...)` instead.', uplevel: 1
#{kwarg} = #{legacy_argument}
end
RUBY
Slide 110
Slide 110 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
legacy_argument = "legacy_#{kwarg}"
class_name = find_class_name(node)
method_name = node.parent.parent.method_name
condition += <<-RUBY
if #{legacy_argument} != NOT_GIVEN
warn_with_uplevel 'Passing `#{kwarg}` with
the #{index} argument of
`#{class_name}.#{method_name}` is deprecated. Use
keyword argument like `#{class_name}.#{method_name}
(#{kwarg}: ...)` instead.', uplevel: 1
#{kwarg} = #{legacy_argument}
end
RUBY
ޓมͷ࡞
Slide 111
Slide 111 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
legacy_argument = "legacy_#{kwarg}"
class_name = find_class_name(node)
method_name = node.parent.parent.method_name
condition += <<-RUBY
if #{legacy_argument} != NOT_GIVEN
warn_with_uplevel 'Passing `#{kwarg}` with
the #{index} argument of
`#{class_name}.#{method_name}` is deprecated. Use
keyword argument like `#{class_name}.#{method_name}
(#{kwarg}: ...)` instead.', uplevel: 1
#{kwarg} = #{legacy_argument}
end
RUBY
private
def find_class_name(node)
if node.class_type?
return node.identifier.source
end
find_class_name(node.parent)
end
Slide 112
Slide 112 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
legacy_argument = "legacy_#{kwarg}"
class_name = find_class_name(node)
method_name = node.parent.parent.method_name
condition += <<-RUBY
if #{legacy_argument} != NOT_GIVEN
warn_with_uplevel 'Passing `#{kwarg}` with
the #{index} argument of
`#{class_name}.#{method_name}` is deprecated. Use
keyword argument like `#{class_name}.#{method_name}
(#{kwarg}: ...)` instead.', uplevel: 1
#{kwarg} = #{legacy_argument}
end
RUBY
ࣗಈमਖ਼ίʔυͷ
ஔจࣈྻ
Slide 113
Slide 113 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
lambda do |corrector|
corrector.insert_before(
arguments_range(node),
"#{legacy_argument} = NOT_GIVEN, "
)
corrector.insert_before(
node.parent.parent.children.last.source_range,
condition
)
end
Slide 114
Slide 114 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
lambda do |corrector|
corrector.insert_before(
arguments_range(node),
"#{legacy_argument} = NOT_GIVEN, "
)
corrector.insert_before(
node.parent.parent.children.last.source_range,
condition
)
end
मਖ਼ίʔυ
ͷஔ
Slide 115
Slide 115 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
lambda do |corrector|
corrector.insert_before(
arguments_range(node),
"#{legacy_argument} = NOT_GIVEN, "
)
corrector.insert_before(
node.parent.parent.children.last.source_range,
condition
)
end
ޓҾͷૠೖ
Slide 116
Slide 116 text
CBEέʔεΛࣗಈमਖ਼͢Δ࣮ྫ
lambda do |corrector|
corrector.insert_before(
arguments_range(node),
"#{legacy_argument} = NOT_GIVEN, "
)
corrector.insert_before(
node.parent.parent.children.last.source_range,
condition
)
end
ܯࠂ݅ͷૠೖ
w ࠷ॳ͔Βऑͷͳ͍ઃܭΛ͢Δͷ͍͠
w ιϑτΣΞΛΑΓྑ͍ܗʹ͢ΔͨΊʹɺࢭΉΛ
ಘͣޙํޓΛؾʹ͔͚ͭͭఘΊΔ߹͕͋Δ
w CVOEMFVQEBUFͰখ͞ͳϦϓϨʔεΛ܁Γฦ
͢͜ͱͰେ͖ͳϦϓϨʔεΛ͙
w มߋൣғ͕ڱ͍ํ͕ݪҼͷಛఆ͕༰қ
w ͋ͳͨͱ·ΘΓݹ͍όʔδϣϯ͔৽͍͠όʔδϣ
ϯͲͪΒΛ͏ͷ͕ΈͰ͔͢ʁ
ഁյతมߋΛӽ͑Δ
Slide 148
Slide 148 text
όʔδϣϯӽ͑
lޙੈʹ͢ͷz
ະདྷ
Slide 149
Slide 149 text
w ͋ͳͨʹΑͬͯෆඞཁ͔ͩͬͨ͠Εͳ͍
ഁյతͳมߋΛࢭΊΔ͜ͱ͕Ͱ͖Δ͔͠
Εͳ͍
w ͋ͳͨʹΑͬͯഁյతͳมߋͷμϝʔδ
Λ؇Ͱ͖Δ͔͠Εͳ͍
w ·ͣखݩͷඇਪܯࠂΛݟͯΈΑ͏
w ΈΜͳͰ3VCZͷΞοϓ
άϨʔυࣗຫΛ͍͖ͯ͠·͠ΐ͏
͋ͳ͕ͨίϛϡχςΟ
Slide 150
Slide 150 text
l
ίϛϡχςΟͱ୭͔ɻͪΖ
Μɺ͋ͳͨͷ͜ͱͩɻ͋ͳ͕ͨ
ίϛϡχςΟͰ͋ΓɺͦΕҎ֎
ʹίϛϡχςΟ͍ͳ͍ɻ͋ͳ
ͨͷΑ͏ͳਓʑͷू·ΓΛɺί
ϛϡχςΟͱݺͿͷͩɻ
IUUQTNBHB[JOFSVCZJTUOFUBSUJDMFT'PSF8PSEIUNM
Community is yourself