diff --git a/.rubocop.yml b/.rubocop.yml index 41494b286b..f37ec8a794 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,9 @@ +inherit_gem: + rubocop-inst: + - rubocop.yml + - rubocop-rspec.yml + require: - - rubocop-performance - rubocop-rake - rubocop-rspec @@ -35,18 +39,8 @@ Lint/BinaryOperatorWithIdenticalOperands: Exclude: - spec/openhab/core/types/*_spec.rb -Metrics: - Enabled: false - -Performance/Casecmp: - AutoCorrect: false - RSpec/DescribeClass: Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWording: - DisallowedExamples: [] RSpec/ExpectActual: Exclude: - spec/openhab/core/types/*_spec.rb @@ -58,6 +52,8 @@ RSpec/FilePath: RSpec/IdenticalEqualityAssertion: Exclude: - spec/openhab/core/types/*_spec.rb +RSpec/IndexedLet: + Enabled: false RSpec/MessageSpies: Enabled: false RSpec/MultipleExpectations: @@ -69,8 +65,6 @@ RSpec/NestedGroups: RSpec/NoExpectationExample: Enabled: false -Style/Alias: - EnforcedStyle: prefer_alias_method Style/CaseEquality: Exclude: # we're explicitly testing this operator - spec/openhab/core/types/*_spec.rb @@ -90,22 +84,8 @@ Style/GlobalVars: - $scriptExtension - $sharedCache - $things -Style/HashSyntax: - EnforcedStyle: ruby19_no_mixed_keys -Style/PercentQLiterals: - EnforcedStyle: upper_case_q -Style/PerlBackrefs: - Enabled: false -Style/RescueStandardError: - EnforcedStyle: implicit Style/SpecialGlobalVars: Enabled: false -Style/StringLiterals: - EnforcedStyle: double_quotes -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes -Style/TernaryParentheses: - EnforcedStyle: require_parentheses_when_complex Style/YodaCondition: Exclude: - spec/openhab/core/types/*_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 888c827b31..c47637b42f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,13 +18,13 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (6.1.7.3) + activesupport (6.1.7.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - addressable (2.8.3) + addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) async (1.31.0) @@ -39,18 +39,18 @@ GEM protocol-http1 (~> 0.14.0) protocol-http2 (~> 0.14.0) traces (>= 0.8.0) - async-http-faraday (0.11.0) + async-http-faraday (0.12.0) async-http (~> 0.42) faraday - async-io (1.34.3) + async-io (1.35.0) async async-pool (0.4.0) async (>= 1.25) builder (3.2.4) byebug (11.1.3) coderay (1.1.3) - commonmarker (0.23.8) - concurrent-ruby (1.2.0) + commonmarker (0.23.10) + concurrent-ruby (1.2.2) console (1.15.3) fiber-local cucumber (8.0.0) @@ -65,7 +65,7 @@ GEM mime-types (~> 3.4, >= 3.4.1) multi_test (~> 1.1, >= 1.1.0) sys-uname (~> 1.2, >= 1.2.2) - cucumber-ci-environment (9.1.0) + cucumber-ci-environment (9.2.0) cucumber-core (11.0.0) cucumber-gherkin (~> 23.0, >= 23.0.1) cucumber-messages (~> 18.0, >= 18.0.0) @@ -85,13 +85,13 @@ GEM diff-lcs (1.5.0) eventmachine (1.2.7) eventmachine (1.2.7-java) - faraday (2.7.4) + faraday (2.7.10) faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) - faraday-http-cache (2.4.1) + faraday-http-cache (2.5.0) faraday (>= 0.8) faraday-net_http (3.0.2) - faraday-retry (2.1.0) + faraday-retry (2.2.0) faraday (~> 2.0) ffi (1.15.5) ffi (1.15.5-java) @@ -131,25 +131,25 @@ GEM httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) io-console (0.6.0) io-console (0.6.0-java) - irb (1.6.2) + irb (1.6.3) reline (>= 0.3.0) json (2.6.3) json (2.6.3-java) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - lumberjack (1.2.8) + lumberjack (1.2.9) marcel (1.0.2) method_source (1.0.0) - mime-types (3.4.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) - mini_mime (1.1.2) - minitest (5.18.0) + mime-types-data (3.2023.0808) + mini_mime (1.1.5) + minitest (5.20.0) multi_json (1.15.0) multi_test (1.1.0) multi_xml (0.6.0) @@ -170,9 +170,10 @@ GEM octokit (4.25.1) faraday (>= 1, < 3) sawyer (~> 0.9) - parallel (1.22.1) - parser (3.2.1.0) + parallel (1.23.0) + parser (3.2.2.3) ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) persistent_http (1.0.6) @@ -182,7 +183,7 @@ GEM persistent_http (< 2) process_exists (0.2.0) protocol-hpack (1.4.2) - protocol-http (0.24.1) + protocol-http (0.24.4) protocol-http1 (0.14.6) protocol-http (~> 0.22) protocol-http2 (0.14.2) @@ -195,55 +196,58 @@ GEM coderay (~> 1.1) method_source (~> 1.0) spoon (~> 0.0) - public_suffix (5.0.1) - racc (1.6.2) - racc (1.6.2-java) - rack (2.2.6.2) + public_suffix (5.0.3) + racc (1.7.1) + racc (1.7.1-java) + rack (2.2.8) rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (2.7.0) - reline (0.3.2) + regexp_parser (2.8.1) + reline (0.3.8) io-console (~> 0.5) - rexml (3.2.5) + rexml (3.2.6) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) rspec-mocks (~> 3.12.0) - rspec-core (3.12.1) + rspec-core (3.12.2) rspec-support (~> 3.12.0) - rspec-expectations (3.12.2) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.3) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-support (3.12.0) - rubocop (1.45.1) + rspec-support (3.12.1) + rubocop (1.50.2) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.26.0) + rubocop-ast (1.29.0) parser (>= 3.2.1.0) - rubocop-capybara (2.17.1) + rubocop-capybara (2.18.0) rubocop (~> 1.41) - rubocop-performance (1.16.0) + rubocop-inst (1.0.2) + rubocop (~> 1.50) + rubocop-performance (~> 1.17) + rubocop-performance (1.17.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.18.1) + rubocop-rspec (2.20.0) rubocop (~> 1.33) rubocop-capybara (~> 2.17) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sawyer (0.9.2) addressable (>= 2.3.5) @@ -251,16 +255,16 @@ GEM shellany (0.0.1) spoon (0.0.6) ffi - sys-uname (1.2.2) + sys-uname (1.2.3) ffi (~> 1.1) - thin (1.8.1) + thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (1.2.1) - timecop (0.9.6) + thor (1.2.2) + timecop (0.9.8) timers (4.3.5) - traces (0.9.1) + traces (0.11.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) @@ -269,7 +273,7 @@ GEM unicode-display_width (2.4.2) webrick (1.7.0) yaml-lint (0.1.2) - zeitwerk (2.6.7) + zeitwerk (2.6.11) PLATFORMS arm64-darwin-21 @@ -292,14 +296,13 @@ DEPENDENCIES guard-yard (~> 2.2) httparty (~> 0.20) irb (~> 1.4) - nokogiri (~> 1.13.9) + nokogiri (~> 1.13) openhab-scripting! persistent_httparty (~> 0.1) process_exists (~> 0.2) rake (~> 13.0) rspec (~> 3.11) - rubocop (~> 1.8) - rubocop-performance (~> 1.11) + rubocop-inst rubocop-rake (~> 0.6) rubocop-rspec (~> 2.11) thin (~> 1.8.1) @@ -309,4 +312,4 @@ DEPENDENCIES yard! BUNDLED WITH - 2.3.26 + 2.4.19 diff --git a/lib/openhab/core/actions/audio.rb b/lib/openhab/core/actions/audio.rb index 5a60492b8f..e681ccde76 100644 --- a/lib/openhab/core/actions/audio.rb +++ b/lib/openhab/core/actions/audio.rb @@ -23,8 +23,11 @@ class << self # def play_sound(filename, sink: nil, volume: nil) volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil? - java_send :playSound, [java.lang.String, java.lang.String, PercentType.java_class], - sink, filename.to_s, volume + java_send :playSound, + [java.lang.String, java.lang.String, PercentType.java_class], + sink, + filename.to_s, + volume end # diff --git a/lib/openhab/core/items/semantics.rb b/lib/openhab/core/items/semantics.rb index 110fd685b5..cf9da16a2a 100644 --- a/lib/openhab/core/items/semantics.rb +++ b/lib/openhab/core/items/semantics.rb @@ -308,7 +308,7 @@ def add(label: nil, synonyms: "", description: "", **tags) raise ArgumentError, "Additional options can only be specified when creating one tag" end - synonyms = Array.wrap(synonyms).map(&:to_s).map(&:strip) + synonyms = Array.wrap(synonyms).map { |s| s.to_s.strip } tags.map do |name, parent| # @deprecated OH4.0.0.M4 missing registry @@ -317,7 +317,9 @@ def add(label: nil, synonyms: "", description: "", **tags) next if lookup(name) next unless parent - new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}", label, description, + new_tag = org.openhab.core.semantics.SemanticTagImpl.new("#{parent.uid}_#{name}", + label, + description, synonyms) Provider.instance.add(new_tag) lookup(name) diff --git a/lib/openhab/core/things/proxy.rb b/lib/openhab/core/things/proxy.rb index 15ebf1fb4d..0a37c67a91 100644 --- a/lib/openhab/core/things/proxy.rb +++ b/lib/openhab/core/things/proxy.rb @@ -13,7 +13,8 @@ class Proxy < Delegator def_delegators :__getobj__, :class, :is_a?, :kind_of? # @!visibility private - EVENTS = [Events::ThingAddedEvent::TYPE, Events::ThingUpdatedEvent::TYPE, + EVENTS = [Events::ThingAddedEvent::TYPE, + Events::ThingUpdatedEvent::TYPE, Events::ThingRemovedEvent::TYPE].freeze # @!visibility private UID_METHOD = :uid diff --git a/lib/openhab/core/types/date_time_type.rb b/lib/openhab/core/types/date_time_type.rb index 59e05c9c87..34161d07a7 100644 --- a/lib/openhab/core/types/date_time_type.rb +++ b/lib/openhab/core/types/date_time_type.rb @@ -144,7 +144,8 @@ def <=>(other) def coerce(other) logger.trace("Coercing #{self} as a request from #{other.class}") return [other, zoned_date_time] if other.respond_to?(:to_zoned_date_time) - return [DateTimeType.new(other), self] if other.respond_to?(:to_time) + + [DateTimeType.new(other), self] if other.respond_to?(:to_time) end # diff --git a/lib/openhab/core/types/open_closed_type.rb b/lib/openhab/core/types/open_closed_type.rb index 28402c8f4f..d0971c6d81 100644 --- a/lib/openhab/core/types/open_closed_type.rb +++ b/lib/openhab/core/types/open_closed_type.rb @@ -28,7 +28,8 @@ class OpenClosedType # @return [OpenClosedType] {OPEN} if {closed?}, {CLOSED} if {open?} def ! return CLOSED if open? - return OPEN if closed? + + OPEN if closed? end end end diff --git a/lib/openhab/core/types/string_type.rb b/lib/openhab/core/types/string_type.rb index f244b06838..26fc6ef088 100644 --- a/lib/openhab/core/types/string_type.rb +++ b/lib/openhab/core/types/string_type.rb @@ -63,7 +63,7 @@ def <=>(other) # def coerce(other) logger.trace("Coercing #{self} as a request from #{other.class}") - return [other.to_str, self] if other.respond_to?(:to_str) + [other.to_str, self] if other.respond_to?(:to_str) end # any method that exists on String gets forwarded to to_s diff --git a/lib/openhab/core/types/up_down_type.rb b/lib/openhab/core/types/up_down_type.rb index 0eb448df4f..aea3be9db4 100644 --- a/lib/openhab/core/types/up_down_type.rb +++ b/lib/openhab/core/types/up_down_type.rb @@ -37,7 +37,8 @@ class UpDownType # def ! return UP if down? - return DOWN if up? + + DOWN if up? end end end diff --git a/lib/openhab/core/value_cache.rb b/lib/openhab/core/value_cache.rb index 2e26d79c43..b91455bae1 100644 --- a/lib/openhab/core/value_cache.rb +++ b/lib/openhab/core/value_cache.rb @@ -107,10 +107,11 @@ def fetch(key, *default_value) # @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-assoc Hash#assoc def assoc(key) - [key, fetch(key) do - # return nil directly, without storing a value to the cache - return nil - end] + [key, + fetch(key) do + # return nil directly, without storing a value to the cache + return nil + end] end # @see https://docs.ruby-lang.org/en/master/Hash.html#method-i-dig Hash#dig diff --git a/lib/openhab/core_ext/java/duration.rb b/lib/openhab/core_ext/java/duration.rb index 401c69fb06..65f4826067 100644 --- a/lib/openhab/core_ext/java/duration.rb +++ b/lib/openhab/core_ext/java/duration.rb @@ -64,7 +64,8 @@ def <=>(other) # def coerce(other) return [other.seconds, self] if other.is_a?(Numeric) - return [other.to_i.seconds, self] if other.is_a?(Period) + + [other.to_i.seconds, self] if other.is_a?(Period) end { diff --git a/lib/openhab/core_ext/java/local_time.rb b/lib/openhab/core_ext/java/local_time.rb index 8ffba2190c..33667252fd 100644 --- a/lib/openhab/core_ext/java/local_time.rb +++ b/lib/openhab/core_ext/java/local_time.rb @@ -56,12 +56,14 @@ def parse(string, formatter = nil) return raw_parse(string, formatter) if formatter format = /(am|pm)$/i.match?(string) ? "h[:mm[:ss][.S]][ ]a" : "H[:mm[:ss][.S]]" - java_send(:parse, [java.lang.CharSequence, java.time.format.DateTimeFormatter], - string, java.time.format.DateTimeFormatterBuilder.new - .parse_case_insensitive - .parse_lenient - .append_pattern(format) - .to_formatter(java.util.Locale::ENGLISH)) + java_send(:parse, + [java.lang.CharSequence, java.time.format.DateTimeFormatter], + string, + java.time.format.DateTimeFormatterBuilder.new + .parse_case_insensitive + .parse_lenient + .append_pattern(format) + .to_formatter(java.util.Locale::ENGLISH)) end end diff --git a/lib/openhab/core_ext/java/month_day.rb b/lib/openhab/core_ext/java/month_day.rb index d1424f5454..8c4885ab4a 100644 --- a/lib/openhab/core_ext/java/month_day.rb +++ b/lib/openhab/core_ext/java/month_day.rb @@ -21,7 +21,8 @@ class << self # def parse(string) logger.trace("#{self.class}.parse #{string} (#{string.class})") - java_send(:parse, [java.lang.CharSequence, java.time.format.DateTimeFormatter], + java_send(:parse, + [java.lang.CharSequence, java.time.format.DateTimeFormatter], string.to_s, java.time.format.DateTimeFormatter.ofPattern("[--]M-d")) end diff --git a/lib/openhab/core_ext/java/period.rb b/lib/openhab/core_ext/java/period.rb index c7478982cc..b77dcebd54 100644 --- a/lib/openhab/core_ext/java/period.rb +++ b/lib/openhab/core_ext/java/period.rb @@ -47,7 +47,7 @@ def <=>(other) # @return [Array, nil] # def coerce(other) - return [other.seconds, to_i.seconds] if other.is_a?(Numeric) + [other.seconds, to_i.seconds] if other.is_a?(Numeric) end { diff --git a/lib/openhab/dsl/items/builder.rb b/lib/openhab/dsl/items/builder.rb index da4b008516..60774d61e2 100644 --- a/lib/openhab/dsl/items/builder.rb +++ b/lib/openhab/dsl/items/builder.rb @@ -270,7 +270,9 @@ def normalize_tags(*tags) # Homekit metadata (see {ItemBuilder#homekit}) # @param metadata [Hash] Generic metadata (see {ItemBuilder#metadata}) # @param state [State] Initial state - def initialize(type, name = nil, label = nil, + def initialize(type, + name = nil, + label = nil, provider:, dimension: nil, unit: nil, diff --git a/lib/openhab/dsl/rules/builder.rb b/lib/openhab/dsl/rules/builder.rb index eff7c2b96d..b91b4f832f 100644 --- a/lib/openhab/dsl/rules/builder.rb +++ b/lib/openhab/dsl/rules/builder.rb @@ -70,7 +70,8 @@ def rule(name = nil, id: nil, script: nil, binding: nil, &block) builder = BuilderDSL.new(binding || block.binding) builder.uid(id) builder.instance_exec(builder, &block) - builder.guard = Guard.new(run_context: builder.caller, only_if: builder.only_if, + builder.guard = Guard.new(run_context: builder.caller, + only_if: builder.only_if, not_if: builder.not_if) name ||= NameInference.infer_rule_name(builder) @@ -1559,8 +1560,12 @@ def event(topic, source: nil, types: nil, attach: nil) # @deprecated OH3.4 - OH3 config uses eventXXX vs OH4 uses `topic`, `source`, and `types` # See https://github.com/openhab/openhab-core/pull/3299 trigger("core.GenericEventTrigger", - eventTopic: topic, eventSource: source, eventTypes: types, # @deprecated OH3.4 - topic: topic, source: source, types: types, + eventTopic: topic, + eventSource: source, + eventTypes: types, # @deprecated OH3.4 + topic: topic, + source: source, + types: types, attach: attach) end @@ -1831,10 +1836,11 @@ def watch(path, glob: "*", for: %i[created deleted modified], attach: nil) types = [binding.local_variable_get(:for)].flatten WatchHandler::WatchTriggerHandlerFactory.instance # ensure it's registered - trigger(WatchHandler::WATCH_TRIGGER_MODULE_ID, path: path.to_s, - types: types.map(&:to_s), - glob: glob.to_s, - attach: attach) + trigger(WatchHandler::WATCH_TRIGGER_MODULE_ID, + path: path.to_s, + types: types.map(&:to_s), + glob: glob.to_s, + attach: attach) end # @!endgroup diff --git a/lib/openhab/dsl/rules/triggers/conditions/generic.rb b/lib/openhab/dsl/rules/triggers/conditions/generic.rb index de970fb746..92a43ab926 100644 --- a/lib/openhab/dsl/rules/triggers/conditions/generic.rb +++ b/lib/openhab/dsl/rules/triggers/conditions/generic.rb @@ -29,7 +29,7 @@ def initialize(from: nil, to: nil, command: nil) # @param [Hash] inputs inputs from trigger # @return [true, false] if the conditions passed (and therefore the block was run) # - def process(mod:, inputs:) # rubocop:disable Lint/UnusedMethodArgument - mod is unused here but required + def process(mod:, inputs:) logger.trace("Checking #{inputs} against condition trigger #{self}") unless check_value(Conditions.old_state_from(inputs), @from) && check_value(Conditions.new_state_from(inputs), @to) && diff --git a/lib/openhab/dsl/things/builder.rb b/lib/openhab/dsl/things/builder.rb index 935d1f2460..27abe6dae3 100644 --- a/lib/openhab/dsl/things/builder.rb +++ b/lib/openhab/dsl/things/builder.rb @@ -187,7 +187,8 @@ def build configuration = Core::Configuration.new(config) if thing_type self.class.thing_factory_helper.apply_default_configuration( - configuration, thing_type, + configuration, + thing_type, self.class.config_description_registry ) end @@ -200,7 +201,8 @@ def build if thing_type # can't use with_channels, or it will wipe out custom channels from above - self.class.thing_factory_helper.create_channels(thing_type, uid, + self.class.thing_factory_helper.create_channels(thing_type, + uid, self.class.config_description_registry).each do |channel| builder.with_channel(channel) end diff --git a/lib/openhab/osgi.rb b/lib/openhab/osgi.rb index aecef7d0b4..c7a77715b3 100644 --- a/lib/openhab/osgi.rb +++ b/lib/openhab/osgi.rb @@ -46,7 +46,7 @@ def register_service(instance, *interfaces, **properties) bundle = org.osgi.framework.FrameworkUtil.get_bundle(interfaces.first.java_class) bundle.bundle_context.register_service( - interfaces.map(&:java_class).map(&:name).to_java(java.lang.String), + interfaces.map { |i| i.java_class.name }.to_java(java.lang.String), instance, java.util.Hashtable.new(properties) ) diff --git a/lib/openhab/rspec/karaf.rb b/lib/openhab/rspec/karaf.rb index d93847b18b..b1c38ce7e0 100644 --- a/lib/openhab/rspec/karaf.rb +++ b/lib/openhab/rspec/karaf.rb @@ -154,7 +154,9 @@ def launch_karaf klass.field_accessor :classLoader, :activatorManager klass.field_writer :framework klass.field_reader :LOG - org.apache.karaf.main.ConfigProperties.field_reader :props, :defaultBundleStartlevel, :karafEtc, + org.apache.karaf.main.ConfigProperties.field_reader :props, + :defaultBundleStartlevel, + :karafEtc, :defaultStartLevel klass.class_eval do def send_private(method_name, *args) @@ -472,7 +474,8 @@ def set_up_bundle_listener thf = Mocks::ThingHandlerFactory.instance bundle = org.osgi.framework.FrameworkUtil.get_bundle(org.openhab.core.thing.Thing.java_class) Mocks::BundleResolver.instance.register_class(thf.class, bundle) - bundle.bundle_context.register_service(org.openhab.core.thing.binding.ThingHandlerFactory.java_class, thf, + bundle.bundle_context.register_service(org.openhab.core.thing.binding.ThingHandlerFactory.java_class, + thf, nil) end end diff --git a/lib/openhab/rspec/openhab/core/actions.rb b/lib/openhab/rspec/openhab/core/actions.rb index 30b651f284..a7d1190479 100644 --- a/lib/openhab/rspec/openhab/core/actions.rb +++ b/lib/openhab/rspec/openhab/core/actions.rb @@ -3,7 +3,6 @@ module OpenHAB module Core module Actions - # rubocop:disable Lint/UnusedMethodArgument # redefine these to do nothing so that rules won't fail module_function @@ -31,8 +30,6 @@ def play_stream(url, sink: nil) end end end - - # rubocop:enable Lint/UnusedMethodArgument end end end diff --git a/openhab-scripting.gemspec b/openhab-scripting.gemspec index 85695f4385..6cc1b41e50 100644 --- a/openhab-scripting.gemspec +++ b/openhab-scripting.gemspec @@ -36,13 +36,12 @@ Gem::Specification.new do |spec| spec.add_development_dependency "guard-yard", "~> 2.2" spec.add_development_dependency "httparty", "~> 0.20" spec.add_development_dependency "irb", "~> 1.4" - spec.add_development_dependency "nokogiri", "~> 1.13.9" + spec.add_development_dependency "nokogiri", "~> 1.13" spec.add_development_dependency "persistent_httparty", "~> 0.1" spec.add_development_dependency "process_exists", "~> 0.2" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.11" - spec.add_development_dependency "rubocop", "~> 1.8" - spec.add_development_dependency "rubocop-performance", "~> 1.11" + spec.add_development_dependency "rubocop-inst" spec.add_development_dependency "rubocop-rake", "~> 0.6" spec.add_development_dependency "rubocop-rspec", "~> 2.11" spec.add_development_dependency "timecop", "~> 0.9" diff --git a/rakelib/openhab.rake b/rakelib/openhab.rake index cfb7287d0f..78761f9eaf 100644 --- a/rakelib/openhab.rake +++ b/rakelib/openhab.rake @@ -71,7 +71,7 @@ namespace :openhab do # There can be a delay between when openHAB is running and ready to process commands def ready?(fail_on_error: false) - return unless running? + return false unless running? command = "#{@karaf_client} 'system:start-level'" @@ -181,10 +181,10 @@ namespace :openhab do state(task.name) do mkdir_p gem_home mkdir_p ruby_lib_dir - services_config = ERB.new <<~SERVICES + services_config = ERB.new <<~TEXT org.openhab.automation.jrubyscripting:gem_home=<%= gem_home %> org.openhab.automation.jrubyscripting:rubylib=<%= ruby_lib_dir %> - SERVICES + TEXT File.write(@services_config_file, services_config.result) end end diff --git a/spec/openhab/core/items/group_item_spec.rb b/spec/openhab/core/items/group_item_spec.rb index 32be6ea4ca..725c4bd1e8 100644 --- a/spec/openhab/core/items/group_item_spec.rb +++ b/spec/openhab/core/items/group_item_spec.rb @@ -42,7 +42,8 @@ describe "#members" do it "is enumerable" do expect(Temperatures.members.count).to be 3 - expect(Temperatures.members.map(&:label)).to match_array ["Bedroom Temperature", "Den Temperature", + expect(Temperatures.members.map(&:label)).to match_array ["Bedroom Temperature", + "Den Temperature", "Living Room Temperature"] end @@ -57,14 +58,18 @@ number_item "Kitchen_Temp", group: Temperatures number_item "Basement_Temp" end - expect(Temperatures.members.map(&:name)).to match_array %w[Bedroom_Temp Den_Temp Kitchen_Temp + expect(Temperatures.members.map(&:name)).to match_array %w[Bedroom_Temp + Den_Temp + Kitchen_Temp LivingRoom_Temp] end it "can be added to an array" do expect([Temperatures] + LivingRoom.members).to match_array [Temperatures, LivingRoom_Temp] expect(LivingRoom.members + [Temperatures]).to match_array [Temperatures, LivingRoom_Temp] - expect(LivingRoom.members + GroundFloor.members).to match_array [LivingRoom_Temp, Bedroom_Temp, Den_Temp, + expect(LivingRoom.members + GroundFloor.members).to match_array [LivingRoom_Temp, + Bedroom_Temp, + Den_Temp, LivingRoom] end end diff --git a/spec/openhab/core/items/semantics_spec.rb b/spec/openhab/core/items/semantics_spec.rb index d3e17f8b2d..2ab422420d 100644 --- a/spec/openhab/core/items/semantics_spec.rb +++ b/spec/openhab/core/items/semantics_spec.rb @@ -24,7 +24,7 @@ end group_item "LivingRoom_Light2_Bulb", tags: [Semantics::Lightbulb, "CustomTag"] do dimmer_item "LivingRoom_Light2_Brightness", tags: [Semantics::Control, Semantics::Level] - color_item "LivingRoom_LIght2_Color", tags: [Semantics::Control, Semantics::Light] + color_item "LivingRoom_Light2_Color", tags: [Semantics::Control, Semantics::Light] end switch_item "LivingRoom_Motion", tag: Semantics::MotionDetector end @@ -225,7 +225,7 @@ def points(*args) LivingRoom_Light1_Color, LivingRoom_Light1_Custom, LivingRoom_Light2_Brightness, - LivingRoom_LIght2_Color, + LivingRoom_Light2_Color, LivingRoom_Motion ] ) @@ -235,7 +235,7 @@ def points(*args) describe "#groups" do it "gets all groups" do expect([LivingRoom_Light1_Custom, - LivingRoom_LIght2_Color, + LivingRoom_Light2_Color, LivingRoom_Light1_Bulb].groups).to match_array([ gMyGroup, gLivingRoom, @@ -248,7 +248,7 @@ def points(*args) describe "#all_groups" do it "gets all groups recursively" do expect([LivingRoom_Light1_Custom, - LivingRoom_LIght2_Color, + LivingRoom_Light2_Color, LivingRoom_Light1_Bulb].all_groups).to match_array([ gMyGroup, LivingRoom_Light1_Bulb, @@ -328,7 +328,9 @@ def points(*args) end it "returns the created tags as an array" do - created = Semantics.add(ArrayTag1: :Equipment, ArrayTag2: :Location, ArrayTag3: :Point, + created = Semantics.add(ArrayTag1: :Equipment, + ArrayTag2: :Location, + ArrayTag3: :Point, LivingRoom: Semantics::Room) expect(created).to match_array([Semantics::ArrayTag1, Semantics::ArrayTag2, Semantics::ArrayTag3]) @@ -337,7 +339,9 @@ def points(*args) end it "supports specifying label, synonyms, and description for the tag" do - Semantics.add(Detailed: Semantics::Equipment, label: "Label 1", synonyms: "Synonym 2", + Semantics.add(Detailed: Semantics::Equipment, + label: "Label 1", + synonyms: "Synonym 2", description: "Description 3") expect(Semantics::Detailed.label).to eq "Label 1" expect(Semantics.lookup("Synonym 2")).to eql Semantics::Detailed diff --git a/spec/openhab/core/things/thing_spec.rb b/spec/openhab/core/things/thing_spec.rb index 5fecebb68a..8d40a8f4ff 100644 --- a/spec/openhab/core/things/thing_spec.rb +++ b/spec/openhab/core/things/thing_spec.rb @@ -13,7 +13,7 @@ describe "things" do it "provides access to all things" do - expect(things.map(&:uid).map(&:to_s)).to include("astro:sun:home") + expect(things.map { |t| t.uid.to_s }).to include("astro:sun:home") end it "supports [] lookup" do diff --git a/spec/openhab/core/timer_spec.rb b/spec/openhab/core/timer_spec.rb index 8d585eae07..f0938a4e24 100644 --- a/spec/openhab/core/timer_spec.rb +++ b/spec/openhab/core/timer_spec.rb @@ -8,7 +8,7 @@ fired = false t = after(0.1.seconds) do |timer| fired = true - expect(timer).to be t # rubocop:disable RSpec/ExpectInHook + expect(timer).to be t end expect(t).not_to be_a(OpenHAB::RSpec::Mocks::Timer) unless self.class.mock_timers? expect(fired).to be false diff --git a/spec/openhab/dsl/rules/builder_spec.rb b/spec/openhab/dsl/rules/builder_spec.rb index 3dc2256648..3d6a629671 100644 --- a/spec/openhab/dsl/rules/builder_spec.rb +++ b/spec/openhab/dsl/rules/builder_spec.rb @@ -1080,7 +1080,9 @@ def self.generate(name, cron_expression, *every_args, attach: nil, **kwargs) generate("uses cron for :seconds", "* * * ? * ? *", :second) generate("passes through attachment", "* * * ? * ? *", :second, attach: 1) generate("can use durations", "*/5 * * ? * ? *", 5.seconds) - generate("can use MonthDay and LocalTime", "0 0 12 17 11 ? *", MonthDay.parse("11-17"), + generate("can use MonthDay and LocalTime", + "0 0 12 17 11 ? *", + MonthDay.parse("11-17"), at: LocalTime.parse("12:00")) generate("can use MonthDay as a string", "0 0 12 17 11 ? *", "11-17", at: LocalTime.parse("12:00")) generate("can use LocalTime a string", "0 0 12 17 11 ? *", MonthDay.parse("11-17"), at: "12:00") @@ -1328,8 +1330,9 @@ def test_it(filename, watch_args:, expected: true, check: nil) end it "doesn't monitor changes inside subdirectories" do - test_it(config_folder / "tmp" / test_file, expected: false, - watch_args: [config_folder, { glob: test_file, for: :created }]) + test_it(config_folder / "tmp" / test_file, + expected: false, + watch_args: [config_folder, { glob: test_file, for: :created }]) end end diff --git a/spec/openhab/dsl/things/builder_spec.rb b/spec/openhab/dsl/things/builder_spec.rb index afd50e1e26..ca0e8f6449 100644 --- a/spec/openhab/dsl/things/builder_spec.rb +++ b/spec/openhab/dsl/things/builder_spec.rb @@ -34,7 +34,7 @@ end end expect(home = things["astro:sun:home"]).not_to be_nil - expect(home.channels.map(&:uid).map(&:to_s)).to include("astro:sun:home:channeltest") + expect(home.channels.map { |c| c.uid.to_s }).to include("astro:sun:home:channeltest") channel = home.channels.find { |c| c.uid.id == "channeltest" } expect(channel.configuration.properties).to have_key("config1") expect(channel.configuration.get("config1")).to eq "testconfig" diff --git a/spec/openhab/dsl_spec.rb b/spec/openhab/dsl_spec.rb index 9771b4e80b..2b4c92432a 100644 --- a/spec/openhab/dsl_spec.rb +++ b/spec/openhab/dsl_spec.rb @@ -252,8 +252,8 @@ unit("°C") do expect(f - (20 | "°C") < 2).to be true - expect((f - 2).format("%.1f %unit%")).to eq "19.1 °C" # rubocop:disable Style/FormatStringToken - expect((c + f).format("%.1f %unit%")).to eq "44.1 °C" # rubocop:disable Style/FormatStringToken + expect((f - 2).format("%.1f %unit%")).to eq "19.1 °C" + expect((c + f).format("%.1f %unit%")).to eq "44.1 °C" expect(f - 2 < 20).to be true expect(2 + c == 25).to be true expect(2 * c == 46).to be true diff --git a/spec/openhab/log_spec.rb b/spec/openhab/log_spec.rb index 5b2b60226e..c85a60830c 100644 --- a/spec/openhab/log_spec.rb +++ b/spec/openhab/log_spec.rb @@ -62,7 +62,7 @@ def logger_name run do after(1.second) do executed = true - expect(logger.name).to match(/^org\.openhab\.automation\.jrubyscripting\.rule\.log_spec\.rb:(?:\d+)$/) # rubocop:disable RSpec/ExpectInHook + expect(logger.name).to match(/^org\.openhab\.automation\.jrubyscripting\.rule\.log_spec\.rb:(?:\d+)$/) end end end @@ -108,7 +108,7 @@ def logger_name executed = false after(1.second) do executed = true - expect(logger.name).to eql file_logger_name # rubocop:disable RSpec/ExpectInHook + expect(logger.name).to eql file_logger_name end time_travel_and_execute_timers(5.seconds) diff --git a/spec/openhab/rspec/helpers_spec.rb b/spec/openhab/rspec/helpers_spec.rb index 529bb36858..4e2605c66a 100644 --- a/spec/openhab/rspec/helpers_spec.rb +++ b/spec/openhab/rspec/helpers_spec.rb @@ -5,8 +5,10 @@ describe "load_rules" do it "respects start levels" do allow(RSpec.configuration).to receive(:openhab_automation_search_paths).and_return(["automation"]) - allow(Dir).to receive(:[]).and_return(%w[automation/filea.rb automation/sl30/filec.rb - automation/filea.sl20.rb automation/sl30/fileb.rb]) + allow(Dir).to receive(:[]).and_return(%w[automation/filea.rb + automation/sl30/filec.rb + automation/filea.sl20.rb + automation/sl30/fileb.rb]) # rubocop:disable RSpec/SubjectStub expect(subject).to receive(:load).with("automation/filea.sl20.rb").ordered diff --git a/spec/openhab/rspec/item_spec.rb b/spec/openhab/rspec/item_spec.rb index aa659b6f8c..e9a11eb24c 100644 --- a/spec/openhab/rspec/item_spec.rb +++ b/spec/openhab/rspec/item_spec.rb @@ -5,7 +5,7 @@ # Has to be in after(:all) so that the top-level after hook has run; # this example group explicitly has a single spec after(:all) do # rubocop:disable RSpec/BeforeAfterAll - expect(items["MyItem"]).to be_nil # rubocop:disable RSpec/ExpectInHook + expect(items["MyItem"]).to be_nil end it "cleans up all items created in a spec" do diff --git a/spec/openhab/rspec/rule_spec.rb b/spec/openhab/rspec/rule_spec.rb index 7947d4acd5..aea1cbc1dd 100644 --- a/spec/openhab/rspec/rule_spec.rb +++ b/spec/openhab/rspec/rule_spec.rb @@ -4,7 +4,7 @@ context "with in-spec created rules" do # Has to be in before/after(:all) so that the top-level after hook has run; # this example group explicitly has a single spec - # rubocop:disable RSpec/BeforeAfterAll, RSpec/ExpectInHook + # rubocop:disable RSpec/BeforeAfterAll before(:all) do rule id: "out-of-spec-rule" do every :day diff --git a/templates/default/module/setup.rb b/templates/default/module/setup.rb index cd00f72eea..f867abfbe1 100644 --- a/templates/default/module/setup.rb +++ b/templates/default/module/setup.rb @@ -1,13 +1,26 @@ # frozen_string_literal: true def init - sections :header, :box_info, :pre_docstring, T("docstring"), :children, - :constant_summary, [T("docstring")], :inherited_constants, - :attribute_summary, [:item_summary], :inherited_attributes, - :method_summary, [T("docstring"), :item_summary], :inherited_methods, - :methodmissing, [T("method_details")], - :attribute_details, [T("method_details")], - :method_details_list, [T("method_details")] + sections :header, + :box_info, + :pre_docstring, + T("docstring"), + :children, + :constant_summary, + [T("docstring")], + :inherited_constants, + :attribute_summary, + [:item_summary], + :inherited_attributes, + :method_summary, + [T("docstring"), :item_summary], + :inherited_methods, + :methodmissing, + [T("method_details")], + :attribute_details, + [T("method_details")], + :method_details_list, + [T("method_details")] end def groups(list, type = "Method")