Skip to content

Commit

Permalink
switch to rubocop-inst's base set of rubocop rules
Browse files Browse the repository at this point in the history
it already contains most of my personal preferences, so that then
our rubocop config can be even smaller

Signed-off-by: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Sep 8, 2023
1 parent 85b7ac0 commit 3ed2192
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 93 deletions.
37 changes: 5 additions & 32 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
inherit_gem:
rubocop-inst:
- rubocop.yml
- rubocop-rspec.yml

require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

Expand All @@ -23,9 +27,6 @@ Bundler/GemFilename:
Exclude:
- lib/openhab/dsl/gems.rb

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec

Layout/LineLength:
AllowedPatterns:
- "# @example" # YARD example titles can't be broken up onto multiple lines.
Expand All @@ -38,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
Expand All @@ -63,8 +54,6 @@ RSpec/IdenticalEqualityAssertion:
- spec/openhab/core/types/*_spec.rb
RSpec/IndexedLet:
Enabled: false
RSpec/MatchArray:
Enabled: false
RSpec/MessageSpies:
Enabled: false
RSpec/MultipleExpectations:
Expand All @@ -76,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
Expand All @@ -97,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
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ GEM
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
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)
Expand Down Expand Up @@ -299,8 +302,7 @@ DEPENDENCIES
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)
Expand Down
7 changes: 5 additions & 2 deletions lib/openhab/core/actions/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
4 changes: 3 additions & 1 deletion lib/openhab/core/items/semantics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/openhab/core/things/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/openhab/core/value_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions lib/openhab/core_ext/java/local_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/openhab/core_ext/java/month_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/openhab/dsl/items/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def normalize_tags(*tags)
# Homekit metadata (see {ItemBuilder#homekit})
# @param metadata [Hash<String, 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,
Expand Down
20 changes: 13 additions & 7 deletions lib/openhab/dsl/rules/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/openhab/dsl/rules/triggers/conditions/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
6 changes: 4 additions & 2 deletions lib/openhab/dsl/things/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/openhab/rspec/karaf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/openhab/rspec/openhab/core/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,8 +30,6 @@ def play_stream(url, sink: nil)
end
end
end

# rubocop:enable Lint/UnusedMethodArgument
end
end
end
3 changes: 1 addition & 2 deletions openhab-scripting.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Gem::Specification.new do |spec|
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"
Expand Down
4 changes: 2 additions & 2 deletions rakelib/openhab.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions spec/openhab/core/items/group_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/openhab/core/items/semantics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/openhab/core/timer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3ed2192

Please sign in to comment.