diff --git a/.codeclimate.yml b/.codeclimate.yml index f37d3e4..f2bdc89 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,8 +1,9 @@ +prepare: + fetch: + - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/.rubocop.yml engines: shellcheck: enabled: true - bundler-audit: - enabled: true reek: enabled: true rubocop: diff --git a/.rubocop.yml b/.rubocop.yml index 3a38ee1..6d6ab7b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,49 +1,3 @@ -inherit_from: .rubocop_todo.yml - -AllCops: - Exclude: - - "spec/dummy/**/*" -Style/AndOr: - EnforcedStyle: conditionals -Style/CaseIndentation: - IndentOneStep: true -Style/Documentation: - Enabled: false -Style/EmptyMethod: - EnforcedStyle: expanded -Style/MethodDefParentheses: - EnforcedStyle: require_no_parentheses -Style/NumericLiterals: - Enabled: false -Style/PercentLiteralDelimiters: - PreferredDelimiters: - "%w": "[]" - "%W": "[]" - "%i": "[]" - "%I": "[]" - "%r": "()" -Style/SafeNavigation: - Enabled: false -Style/SignalException: - EnforcedStyle: semantic -Style/SingleLineBlockParams: - Enabled: false -Style/SpaceInsideHashLiteralBraces: - EnforcedStyle: no_space -Style/StringLiterals: - EnforcedStyle: double_quotes -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes -Style/VariableNumber: - EnforcedStyle: snake_case -Metrics/BlockLength: - Exclude: - - "**/*.gemspec" - - "spec/**/*" -Metrics/LineLength: - Max: 100 - Exclude: - - "lib/navigator/menu.rb" - - "spec/lib/menu_spec.rb" -Metrics/ParameterLists: - Max: 3 +inherit_from: + - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/.rubocop.yml + - .rubocop_todo.yml diff --git a/lib/navigator/menu.rb b/lib/navigator/menu.rb index f3585db..d475af9 100644 --- a/lib/navigator/menu.rb +++ b/lib/navigator/menu.rb @@ -3,11 +3,17 @@ module Navigator # Renders a HTML menu. class Menu + # rubocop:disable Metrics/LineLength def self.allowed_methods /^(div|section|header|h[1-6]|nav|ul|li|a|img|b|em|s|small|span|strong|sub|sup|form|label|select|option|input|button)$/ end - def initialize template, tag: "ul", attributes: {}, activator: Navigator::TagActivator.new, &block + def initialize template, + tag: "ul", + attributes: {}, + activator: Navigator::TagActivator.new, + &block + @template = template @tag = Navigator::Tag.new tag, attributes: attributes, activator: activator @menu_activator = activator @@ -36,12 +42,22 @@ def image url, alt = nil, attributes: {}, activator: menu_activator add "img", attributes: modified_attributes, activator: activator end - def item content = nil, url, item_attributes: {}, link_attributes: {}, activator: menu_activator, &block + def item content = nil, + url, + item_attributes: {}, + link_attributes: {}, + activator: menu_activator, + &block + modified_item_attributes = item_attributes.clone activate_item_attributes! modified_item_attributes, url, activator add "li", attributes: modified_item_attributes, activator: activator do - link content, url, attributes: link_attributes, activator: Navigator::TagActivator.new, &block + link content, + url, + attributes: link_attributes, + activator: Navigator::TagActivator.new, + &block end end @@ -72,7 +88,10 @@ def method_allowed? name def activate_item_attributes! attributes, url, activator return unless url == activator.search_value - attributes[activator.target_key] = [attributes[activator.target_key], activator.target_value].compact * " " + + attributes[activator.target_key] = [attributes[activator.target_key], activator.target_value] + .compact + .join " " end end end diff --git a/spec/lib/menu_spec.rb b/spec/lib/menu_spec.rb index 2c99c05..819954c 100644 --- a/spec/lib/menu_spec.rb +++ b/spec/lib/menu_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" +# rubocop:disable Metrics/LineLength RSpec.describe Navigator::Menu do let(:erb_handler) { ActionView::Template::Handlers::ERB.new } let(:template) { ActionView::Template.new "", "Example", erb_handler, {} }