diff --git a/.rubocop-version b/.rubocop-version index bb399dd22..f288d1114 100644 --- a/.rubocop-version +++ b/.rubocop-version @@ -1 +1 @@ -1.60.2 +1.85.0 diff --git a/.rubocop.yml b/.rubocop.yml index ca805939a..0cba5b96e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,7 +39,7 @@ Style/MultilineMemoization: Style/StderrPuts: Enabled: false -Naming/PredicateName: +Naming/PredicatePrefix: Enabled: false # Lots of false positive because of our class_eval-like blocks like e.g. @@ -54,7 +54,7 @@ Metrics/ModuleLength: - '**/test/**/*_test.rb' Metrics/BlockLength: - ExcludedMethods: + AllowedMethods: - describe - it diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 34231c157..5ef3a8c85 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1522,7 +1522,7 @@ Naming/MethodParameterName: # ForbiddenPrefixes: is_, has_, have_ # AllowedMethods: is_a? # MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: +Naming/PredicatePrefix: Exclude: - 'spec/**/*' - 'lib/roby/actions/action.rb' diff --git a/benchmark/ruby/set_intersect_vs_hash_merge.rb b/benchmark/ruby/set_intersect_vs_hash_merge.rb index bf3bee366..1360e80f0 100644 --- a/benchmark/ruby/set_intersect_vs_hash_merge.rb +++ b/benchmark/ruby/set_intersect_vs_hash_merge.rb @@ -21,8 +21,8 @@ def intersect_with_merge(other) left = Set.new right = Set.new count.times do - left << (elements[rand(count * 2)]) - right << (elements[rand(count * 2)]) + left << elements[rand(count * 2)] + right << elements[rand(count * 2)] end sets << [left, right] end diff --git a/benchmark/ruby/yield_vs_block.rb b/benchmark/ruby/yield_vs_block.rb index bf0358301..a7fdba0e0 100644 --- a/benchmark/ruby/yield_vs_block.rb +++ b/benchmark/ruby/yield_vs_block.rb @@ -22,10 +22,10 @@ def call_block(enum, &block) call_block(enum) { |v| } end x.report(format("yield - %.0e calls", calls: cost_of_call)) do - cost_of_call.times { call_yield((1..1)) { |v| } } + cost_of_call.times { call_yield(1..1) { |v| } } end x.report(format("block - %.0e calls", calls: cost_of_call)) do - cost_of_call.times { call_block((1..1)) { |v| } } + cost_of_call.times { call_block(1..1) { |v| } } end x.report(format("yield - %.0e calls and %.0e elements", calls: call_count, elements: call_enum.size)) do diff --git a/lib/roby/app.rb b/lib/roby/app.rb index 885912c05..c250e0adc 100644 --- a/lib/roby/app.rb +++ b/lib/roby/app.rb @@ -2690,8 +2690,6 @@ def find_dirs(*dir_path) raise ArgumentError, "expected either :specific_first or :specific_last for the :order argument, but got #{options[:order]}" end - relative_paths = [] - base_dir_path = dir_path.dup base_dir_path.delete_if { |p| p =~ /ROBOT/ } relative_paths = [base_dir_path] diff --git a/lib/roby/app/scripts.rb b/lib/roby/app/scripts.rb index 3e56fa933..f2eaa832c 100644 --- a/lib/roby/app/scripts.rb +++ b/lib/roby/app/scripts.rb @@ -45,7 +45,6 @@ def run( *args, banner: "", option_parser: default_option_parser(banner: banner) ) - app.guess_app_dir app.shell app.single diff --git a/lib/roby/droby/plan_rebuilder.rb b/lib/roby/droby/plan_rebuilder.rb index 7145dbea3..8679ed516 100644 --- a/lib/roby/droby/plan_rebuilder.rb +++ b/lib/roby/droby/plan_rebuilder.rb @@ -128,7 +128,7 @@ def process_one_event(m, sec, usec, args) case obj when NilClass then "nil" when Time then obj.to_hms - else (obj.to_s rescue "failed_to_s") + else obj.to_s rescue "failed_to_s" end end diff --git a/lib/roby/event_constraints.rb b/lib/roby/event_constraints.rb index cb59d7b4f..2893931d7 100644 --- a/lib/roby/event_constraints.rb +++ b/lib/roby/event_constraints.rb @@ -623,7 +623,7 @@ def explain_static(task) def has_atomic_predicate?(pred) pred = pred.to_unbound_task_predicate each_atomic_predicate do |p| - return(true) if p == pred + return true if p == pred end false end diff --git a/lib/roby/execution_engine.rb b/lib/roby/execution_engine.rb index 54a05a391..ca50b0d18 100644 --- a/lib/roby/execution_engine.rb +++ b/lib/roby/execution_engine.rb @@ -1539,7 +1539,7 @@ def process_waiting_work unhandled_errors = finished.find_all do |work| work.rejected? && - (work.respond_to?(:handled_error?) && !work.handled_error?) + work.respond_to?(:handled_error?) && !work.handled_error? end unhandled_errors.each do |work| @@ -1574,7 +1574,6 @@ def initialize(called_generators = Set.new, handled_errors = [], inhibited_errors = [], framework_errors = []) - self.called_generators = called_generators.to_set self.emitted_events = emitted_events.to_set self.kill_tasks = kill_tasks.to_set diff --git a/lib/roby/gui/chronicle_widget.rb b/lib/roby/gui/chronicle_widget.rb index 0671f35d8..9019f9e39 100644 --- a/lib/roby/gui/chronicle_widget.rb +++ b/lib/roby/gui/chronicle_widget.rb @@ -514,9 +514,9 @@ def update_current_tasks(force: false) start_time, end_time = displayed_time_range - if start_time && (show_mode == :running || show_mode == :current) + if start_time && %i[running current].include?(show_mode) current_tasks = current_tasks.find_all do |t| - (t.start_time && t.start_time < end_time) && + t.start_time && t.start_time < end_time && (!t.end_time || t.end_time > start_time) end diff --git a/lib/roby/gui/model_views/action_interface.rb b/lib/roby/gui/model_views/action_interface.rb index dedb7c2ed..1951b6c4c 100644 --- a/lib/roby/gui/model_views/action_interface.rb +++ b/lib/roby/gui/model_views/action_interface.rb @@ -22,8 +22,7 @@ def render(model, options = {}) def self.find_definition_place(model) location = model.definition_location.find do |location| - break if location.label == "require" || - location.label == "using_task_library" + break if %w[require using_task_library].include?(location.label) Roby.app.app_file?(location.absolute_path) end diff --git a/lib/roby/gui/plan_dot_layout.rb b/lib/roby/gui/plan_dot_layout.rb index ea00c0b8f..c603a7410 100644 --- a/lib/roby/gui/plan_dot_layout.rb +++ b/lib/roby/gui/plan_dot_layout.rb @@ -295,7 +295,7 @@ def self.parse_dot_layout(dot_layout, options = {}) dot_layout.each do |line| line.chomp! full_line << line.strip - if line[-1] == "\\" || line[-1] == "," + if ["\\", ","].include?(line[-1]) full_line.chomp! next end diff --git a/lib/roby/gui/plan_rebuilder_widget.rb b/lib/roby/gui/plan_rebuilder_widget.rb index b4e1dd235..429a3a6b4 100644 --- a/lib/roby/gui/plan_rebuilder_widget.rb +++ b/lib/roby/gui/plan_rebuilder_widget.rb @@ -218,7 +218,7 @@ def self.analyze(plan_rebuilder, logfile, until_cycle: nil) start = Time.now puts "log file is #{(end_time - start_time).ceil}s long" - dialog = Qt::ProgressDialog.new("Analyzing log file", "Quit", 0, (end_time - start_time)) + dialog = Qt::ProgressDialog.new("Analyzing log file", "Quit", 0, end_time - start_time) dialog.setWindowModality(Qt::WindowModal) dialog.show diff --git a/lib/roby/interface/rest/server.rb b/lib/roby/interface/rest/server.rb index 1d8da17a7..cd559d13c 100644 --- a/lib/roby/interface/rest/server.rb +++ b/lib/roby/interface/rest/server.rb @@ -48,7 +48,6 @@ def initialize(app, roby_execute: true, middlewares: VERBOSE_MIDDLEWARES, **thin_options) - @app = app @host = host @main_route = main_route diff --git a/lib/roby/interface/v1/shell_client.rb b/lib/roby/interface/v1/shell_client.rb index 655a4c129..ef41f6014 100644 --- a/lib/roby/interface/v1/shell_client.rb +++ b/lib/roby/interface/v1/shell_client.rb @@ -334,7 +334,7 @@ def method_missing(m, *args) nil else begin - call Hash[], [], m, *args + call({}, [], m, *args) rescue NoMethodError => e if e.message =~ /undefined method .#{m}./ puts "invalid command name #{m}, call 'help' for more information" diff --git a/lib/roby/interface/v2/shell_client.rb b/lib/roby/interface/v2/shell_client.rb index 2d9b751b1..e77dd1fd3 100644 --- a/lib/roby/interface/v2/shell_client.rb +++ b/lib/roby/interface/v2/shell_client.rb @@ -356,7 +356,7 @@ def method_missing(m, *args) nil else begin - call Hash[], [], m, *args + call({}, [], m, *args) rescue NoMethodError => e if e.message =~ /undefined method .#{m}./ puts "invalid command name #{m}, call 'help' for more information" diff --git a/lib/roby/plan_object.rb b/lib/roby/plan_object.rb index 10b6235dd..7c5b425fe 100644 --- a/lib/roby/plan_object.rb +++ b/lib/roby/plan_object.rb @@ -356,7 +356,7 @@ def merged_relations(enumerator, intrusive, &block) # If this object is executable def executable? - @executable || (@executable.nil? && !garbage? && plan && plan.executable?) + @executable || (@executable.nil? && !garbage? && plan&.executable?) end # @!method garbage? @@ -619,7 +619,7 @@ def finalized!(timestamp = nil) def when_finalized(options = {}, &block) options = InstanceHandler.validate_options options check_arity(block, 1) - finalization_handlers << InstanceHandler.new(block, (options[:on_replace] == :copy)) + finalization_handlers << InstanceHandler.new(block, options[:on_replace] == :copy) end # True if this plan object has been finalized (i.e. removed from plan), diff --git a/lib/roby/relations/graph.rb b/lib/roby/relations/graph.rb index b38a15c80..668518bc9 100644 --- a/lib/roby/relations/graph.rb +++ b/lib/roby/relations/graph.rb @@ -114,7 +114,6 @@ def initialize( noinfo: !self.class.embeds_info?, subsets: Set.new ) - @observer = observer @distribute = distribute @dag = dag diff --git a/lib/roby/relations/space.rb b/lib/roby/relations/space.rb index a6fe5d977..3f2d3c3fb 100644 --- a/lib/roby/relations/space.rb +++ b/lib/roby/relations/space.rb @@ -44,7 +44,7 @@ def self.new_relation_graph_mapping if k if k.kind_of?(Class) known_relations = h.each_key.find_all { |rel| rel.kind_of?(Class) } - .map { |o| o.name.to_s }.join(", ") + .map { |o| o.name.to_s }.join(", ") raise ArgumentError, "#{k} is not a known relation (known relations "\ "are #{known_relations})" @@ -213,7 +213,6 @@ def relation(relation_name, noinfo: false, subsets: Set.new, **submodel_options) - if block_given? raise ArgumentError, "calling relation with a block is not supported anymore. Reopen #{const_name}::Extension after the relation call to add helper methods" elsif strong && weak diff --git a/lib/roby/standard_errors.rb b/lib/roby/standard_errors.rb index a4019fec1..ddce54b53 100644 --- a/lib/roby/standard_errors.rb +++ b/lib/roby/standard_errors.rb @@ -117,7 +117,7 @@ def initialize(failure_point) @failed_task = failure_point end - if !@failed_task && @failed_generator && @failed_generator.respond_to?(:task) + if !@failed_task && @failed_generator.respond_to?(:task) @failed_task = failed_generator.task end if !@failed_task && !@failed_generator diff --git a/lib/roby/support.rb b/lib/roby/support.rb index 4e3c99107..490911a95 100644 --- a/lib/roby/support.rb +++ b/lib/roby/support.rb @@ -184,7 +184,7 @@ def self.error_deprecated(msg, caller_depth = 1) # # which('ruby') #=> /usr/bin/ruby def self.find_in_path(cmd) - return cmd if cmd =~ (/#{File::SEPARATOR}/) && File.file?(cmd) + return cmd if cmd =~ /#{File::SEPARATOR}/ && File.file?(cmd) exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| diff --git a/lib/roby/task.rb b/lib/roby/task.rb index 5401ce6db..efd8a2a2a 100644 --- a/lib/roby/task.rb +++ b/lib/roby/task.rb @@ -1176,7 +1176,7 @@ def execute(options = {}, &block) check_arity(block, 1) @execute_handlers << - InstanceHandler.new(block, (options[:on_replace] == :copy)) + InstanceHandler.new(block, options[:on_replace] == :copy) ensure_poll_handler_called end @@ -1194,7 +1194,7 @@ def poll(options = {}, &block) ) check_arity(block, 1) - handler = InstanceHandler.new(block, (options[:on_replace] == :copy)) + handler = InstanceHandler.new(block, options[:on_replace] == :copy) @poll_handlers << handler ensure_poll_handler_called Roby.disposable { @poll_handlers.delete(handler) } diff --git a/lib/roby/test/teardown_plans.rb b/lib/roby/test/teardown_plans.rb index 28abbd7a7..cdfb0a086 100644 --- a/lib/roby/test/teardown_plans.rb +++ b/lib/roby/test/teardown_plans.rb @@ -68,7 +68,7 @@ def teardown_registered_plans( unless success Roby.warn "clean teardown failed, trying to force-kill all tasks" teardown_forced_killall( - teardown_warn, (teardown_fail - teardown_force), teardown_poll + teardown_warn, teardown_fail - teardown_force, teardown_poll ) end diff --git a/lib/roby/test/testcase.rb b/lib/roby/test/testcase.rb index e4f450161..10257bfae 100644 --- a/lib/roby/test/testcase.rb +++ b/lib/roby/test/testcase.rb @@ -70,8 +70,8 @@ def self.apply_robot_setup name, kind, block = app_setup # Ignore the test suites which use a different robot - if name || kind && (app.robot_name && - (app.robot_name != name || app.robot_type != kind)) + if name || kind && app.robot_name && + (app.robot_name != name || app.robot_type != kind) Test.info "ignoring #{self} as it is for robot #{name} and we are running for #{app.robot_name}:#{app.robot_type}" return end diff --git a/lib/roby/test/tools.rb b/lib/roby/test/tools.rb index 53444577e..e83c0eca2 100644 --- a/lib/roby/test/tools.rb +++ b/lib/roby/test/tools.rb @@ -100,7 +100,7 @@ def stats(samples, spec) fields.each do |name| next unless value = sample[name] - unless spec[name] == :absolute || spec[name] == :absolute_rate + unless %i[absolute absolute_rate].include?(spec[name]) if last_sample && last_sample[name] sample[name] -= last_sample[name] else @@ -118,7 +118,7 @@ def stats(samples, spec) fields.each do |name| next unless value = sample[name] - if spec[name] == :rate || spec[name] == :absolute_rate + if %i[rate absolute_rate].include?(spec[name]) if sample.dt sample[name] = value / sample.dt else diff --git a/lib/roby/test/validate_state_machine.rb b/lib/roby/test/validate_state_machine.rb index 19e774327..d788176f5 100644 --- a/lib/roby/test/validate_state_machine.rb +++ b/lib/roby/test/validate_state_machine.rb @@ -86,7 +86,7 @@ def assert_transitions_to_state(state_name, timeout: 5) @state_machines.each do |m| m.on_transition do |_, new_state| done ||= matchers.any? do - (_1 === new_state.name) + _1 === new_state.name end end end diff --git a/lib/roby/yard.rb b/lib/roby/yard.rb index 991866154..bfb78a1c8 100644 --- a/lib/roby/yard.rb +++ b/lib/roby/yard.rb @@ -132,7 +132,7 @@ def process controlable = false if statement.parameters[1] statement.parameters[1].jump(:assoc).to_a.each_slice(2) do |key, value| - if key.source == "controlable:" || key.source == "command:" + if ["controlable:", "command:"].include?(key.source) controlable = true end end diff --git a/test/app/cucumber/test_helpers.rb b/test/app/cucumber/test_helpers.rb index 2f5bc5d81..a55eb1c27 100644 --- a/test/app/cucumber/test_helpers.rb +++ b/test/app/cucumber/test_helpers.rb @@ -101,7 +101,7 @@ module App describe "unit validation" do it "raises UnexpectedArgument if strict is set and the argument does not have a quantity" do assert_raises(CucumberHelpers::UnexpectedArgument) do - CucumberHelpers.parse_arguments("x=20m", Hash[], strict: true) + CucumberHelpers.parse_arguments("x=20m", {}, strict: true) end end it "validates that the unit and the quantity match" do diff --git a/test/interface/test_interface.rb b/test/interface/test_interface.rb index de0482fc2..76c1c414d 100644 --- a/test/interface/test_interface.rb +++ b/test/interface/test_interface.rb @@ -80,7 +80,7 @@ def an_action; end end it "should not return job tasks that have no job ID" do plan.add(job_task_m.new) - assert_equal Hash[], interface.jobs + assert_equal({}, interface.jobs) end end diff --git a/test/interface/v2/test_channel.rb b/test/interface/v2/test_channel.rb index c3ad210c0..f9efaf7fd 100644 --- a/test/interface/v2/test_channel.rb +++ b/test/interface/v2/test_channel.rb @@ -328,7 +328,7 @@ module V2 end it "returns ranges as-is" do - assert_equal (0..20), @channel.marshal_filter_object((0..20)) + assert_equal (0..20), @channel.marshal_filter_object(0..20) end it "returns any objects whose class was set up with "\ diff --git a/test/relations/test_directed_relation_support.rb b/test/relations/test_directed_relation_support.rb index 887b0f4bd..fb4470719 100644 --- a/test/relations/test_directed_relation_support.rb +++ b/test/relations/test_directed_relation_support.rb @@ -9,7 +9,7 @@ module Relations before do @graph_m = graph_m = Graph.new_submodel - @graph = graph = graph_m.new + @graph = graph = graph_m.new @vertex_m = Class.new(Object) do include DirectedRelationSupport define_method(:relation_graphs) { Hash[graph_m => graph] } diff --git a/test/relations/test_graph.rb b/test/relations/test_graph.rb index 21717d171..5bba0d170 100644 --- a/test/relations/test_graph.rb +++ b/test/relations/test_graph.rb @@ -168,7 +168,7 @@ module Relations end it "moves the in-edges of the old vertex to the new vertex" do - graph.add_edge(parent, old, (info = Object.new)) + graph.add_edge(parent, old, info = Object.new) graph.replace_vertex(old, new) assert graph.has_edge?(parent, new) assert_same info, graph.edge_info(parent, new) @@ -176,7 +176,7 @@ module Relations end it "does not touch the existing in-edges of the new vertex" do - graph.add_edge(parent, new, (info = Object.new)) + graph.add_edge(parent, new, info = Object.new) graph.replace_vertex(old, new) assert graph.has_edge?(parent, new) assert_same info, graph.edge_info(parent, new) @@ -184,7 +184,7 @@ module Relations end it "moves the out-edges of the old vertex to the new vertex" do - graph.add_edge(old, child, (info = Object.new)) + graph.add_edge(old, child, info = Object.new) graph.replace_vertex(old, new) assert graph.has_edge?(new, child) assert_same info, graph.edge_info(new, child) @@ -192,7 +192,7 @@ module Relations end it "does not touch the existing out-edges of the new vertex" do - graph.add_edge(new, child, (info = Object.new)) + graph.add_edge(new, child, info = Object.new) graph.replace_vertex(old, new) assert graph.has_edge?(new, child) assert_same info, graph.edge_info(new, child) diff --git a/test/task_structure/test_dependency.rb b/test/task_structure/test_dependency.rb index a7a296a8e..8ef9c496e 100644 --- a/test/task_structure/test_dependency.rb +++ b/test/task_structure/test_dependency.rb @@ -33,7 +33,7 @@ def test_definition # Check validation of the model child = nil - t1.depends_on((child = klass.new), model: Tasks::Simple) + t1.depends_on(child = klass.new, model: Tasks::Simple) assert_equal([[Tasks::Simple], {}], t1[child, Dependency][:model]) t1.depends_on klass.new, model: [Roby::Task, {}] @@ -591,10 +591,10 @@ def dependency_graph it "picks the most specialized task model" do target = [task_m, [target_tag_m], Hash[arg0: 10]] subclass_m = task_m.new_submodel - merged = Dependency.merge_fullfilled_model(target, [subclass_m], Hash[]) + merged = Dependency.merge_fullfilled_model(target, [subclass_m], {}) assert_equal subclass_m, merged[0] target[0] = subclass_m - merged = Dependency.merge_fullfilled_model(target, [task_m], Hash[]) + merged = Dependency.merge_fullfilled_model(target, [task_m], {}) assert_equal subclass_m, merged[0] end it "concatenates tags" do diff --git a/test/test_task.rb b/test/test_task.rb index 0e3431315..c4bc8c7fc 100644 --- a/test/test_task.rb +++ b/test/test_task.rb @@ -2461,7 +2461,7 @@ def aggregator_test(a, *tasks) def test_task_parallel_aggregator t1, t2 = EmptyTask.new, EmptyTask.new plan.add([t1, t2]) - aggregator_test((t1 | t2), t1, t2) + aggregator_test(t1 | t2, t1, t2) t1, t2 = EmptyTask.new, EmptyTask.new plan.add([t1, t2]) aggregator_test((t1 | t2).to_task, t1, t2) @@ -2477,7 +2477,7 @@ def task_tuple(count) end def test_sequence - task_tuple(2) { |t1, t2| aggregator_test((t1 + t2), t1, t2) } + task_tuple(2) { |t1, t2| aggregator_test(t1 + t2, t1, t2) } task_tuple(2) do |t1, t2| s = t1 + t2 aggregator_test(s.to_task, t1, t2) @@ -2887,7 +2887,7 @@ def test_delayed_argument_from_task assert !planning_task.fully_instanciated? planned_task.arg = Object.new assert !planning_task.fully_instanciated? - plan.force_replace_task(planned_task, (planned_task = klass.new)) + plan.force_replace_task(planned_task, planned_task = klass.new) planned_task.arg = 10 assert planning_task.fully_instanciated? execute { planning_task.start! } diff --git a/test/test_task_arguments.rb b/test/test_task_arguments.rb index 52c57250b..5341a35f5 100644 --- a/test/test_task_arguments.rb +++ b/test/test_task_arguments.rb @@ -206,14 +206,14 @@ r.should_receive(:evaluate_delayed_argument).and_throw(:no_value) end task = task_m.new arg: delayed_arg - assert_equal Hash[], task.arguments.evaluate_delayed_arguments + assert_equal({}, task.arguments.evaluate_delayed_arguments) end it "sets evaluated delayed arguments" do delayed_arg = flexmock do |r| r.should_receive(:evaluate_delayed_argument).and_return(20) end task = task_m.new arg: delayed_arg - assert_equal Hash[arg: 20], task.arguments.evaluate_delayed_arguments + assert_equal({ arg: 20 }, task.arguments.evaluate_delayed_arguments) end end