From 2565ccc783b44c7fc0ae5ef335e094fecc474632 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Tue, 30 Aug 2016 22:32:36 -0300 Subject: [PATCH] Apply rubocop suggestions. --- .hound.yml | 110 ------------------------------ .rubocop.yml | 15 +++- Rakefile | 8 ++- browser.gemspec | 1 + lib/browser/alipay.rb | 1 + lib/browser/detect_version.rb | 4 +- lib/browser/device.rb | 4 +- lib/browser/generic.rb | 2 +- lib/browser/internet_explorer.rb | 2 +- lib/browser/micro_messenger.rb | 2 +- lib/browser/middleware.rb | 2 +- lib/browser/platform.rb | 4 +- lib/browser/platform/mac.rb | 2 +- lib/browser/testing.rb | 4 +- lib/browser/version.rb | 2 +- test/browser_test.rb | 7 +- test/unit/accept_language_test.rb | 9 ++- test/unit/alipay_test.rb | 2 - test/unit/generic_test.rb | 1 + test/unit/meta_test.rb | 1 + 20 files changed, 51 insertions(+), 132 deletions(-) delete mode 100644 .hound.yml diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index 00624028..00000000 --- a/.hound.yml +++ /dev/null @@ -1,110 +0,0 @@ -Style/ClassCheck: - EnforcedStyle: kind_of? - -Metrics/LineLength: - Max: 80 - -Style/BlockDelimiters: - Enabled: false - -Style/RegexpLiteral: - Enabled: false - -Metrics/AbcSize: - Enabled: false - -Style/PerlBackrefs: - Enabled: false - -ClassLength: - Enabled: false - -CyclomaticComplexity: - Enabled: false - -Documentation: - Enabled: false - -Encoding: - Enabled: false - -FileName: - Enabled: false - -IfUnlessModifier: - Enabled: false - -MethodLength: - Enabled: false - -ModuleFunction: - Enabled: false - -OneLineConditional: - Enabled: false - -ParameterLists: - Enabled: false - -Proc: - Enabled: false - -SingleLineBlockParams: - Enabled: false - -VariableInterpolation: - Enabled: false - -TrailingComma: - Enabled: false - -WhileUntilModifier: - Enabled: false - -PredicateName: - NamePrefixBlacklist: - - is_ - -StringLiterals: - EnforcedStyle: double_quotes - SupportedStyles: - - single_quotes - - double_quotes - -DotPosition: - EnforcedStyle: leading - -SpaceBeforeBlockBraces: - EnforcedStyle: space - -SpaceInsideBlockBraces: - EnforcedStyle: no_space - -DoubleNegation: - Enabled: false - -SpaceInsideBlockBraces: - SpaceBeforeBlockParameters: false - -SpaceInsideHashLiteralBraces: - Enabled: false - -PercentLiteralDelimiters: - PreferredDelimiters: - '%': '[]' - '%i': '[]' - '%q': '[]' - '%Q': '[]' - '%r': '[]' - '%s': '[]' - '%w': '[]' - '%W': '[]' - '%x': '[]' - -Style/CollectionMethods: - PreferredMethods: - collect: 'map' - collect!: 'map!' - inject: 'reduce' - detect: 'find' - find_all: 'select' diff --git a/.rubocop.yml b/.rubocop.yml index 6a2a49f8..ef1eba5d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,16 @@ +AllCops: + Exclude: + - "bin/**/*" + - "gemfiles/**/*" + - "vendor/**/*" + - "Gemfile" + - "Rakefile" + - "*.gemspec" + - "config.ru" + +Style/Alias: + EnforcedStyle: prefer_alias_method + Style/FrozenStringLiteralComment: EnforcedStyle: always @@ -58,7 +71,7 @@ SingleLineBlockParams: VariableInterpolation: Enabled: false -TrailingComma: +Style/TrailingCommaInLiteral: Enabled: false WhileUntilModifier: diff --git a/Rakefile b/Rakefile index 7735150e..69a5e2fa 100644 --- a/Rakefile +++ b/Rakefile @@ -12,6 +12,12 @@ Rake::TestTask.new(:test) do |t| t.ruby_opts = %w[-rubygems] end +require "rubocop/rake_task" +desc "Run rubocop" +task :rubocop do + RuboCop::RakeTask.new +end + desc "Run specs against all gemfiles" task "test:all" do %w[ @@ -23,4 +29,4 @@ task "test:all" do end end -task default: "test" +task default: [:test, :rubocop] diff --git a/browser.gemspec b/browser.gemspec index 7ef31596..0dd048a7 100644 --- a/browser.gemspec +++ b/browser.gemspec @@ -28,4 +28,5 @@ Gem::Specification.new do |s| s.add_development_dependency "pry-meta" s.add_development_dependency "minitest-autotest" s.add_development_dependency "codeclimate-test-reporter" + s.add_development_dependency "rubocop" end diff --git a/lib/browser/alipay.rb b/lib/browser/alipay.rb index 14879b21..0cc52bea 100644 --- a/lib/browser/alipay.rb +++ b/lib/browser/alipay.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Browser class Alipay < Base def id diff --git a/lib/browser/detect_version.rb b/lib/browser/detect_version.rb index 1cb04e49..e285b4f9 100644 --- a/lib/browser/detect_version.rb +++ b/lib/browser/detect_version.rb @@ -11,11 +11,11 @@ def detect_version?(actual_version, expected_version) actual_version = parse_version(actual_version) Gem::Requirement.create(expected_version) - .satisfied_by?(Gem::Version.create(actual_version)) + .satisfied_by?(Gem::Version.create(actual_version)) end def parse_version(version) - version.kind_of?(Numeric) ? "#{version}" : version + version.kind_of?(Numeric) ? version.to_s : version end end end diff --git a/lib/browser/device.rb b/lib/browser/device.rb index 5ef226b9..c16ea4ed 100644 --- a/lib/browser/device.rb +++ b/lib/browser/device.rb @@ -52,8 +52,8 @@ def initialize(ua) def subject @subject ||= self.class.matchers - .map {|matcher| matcher.new(ua) } - .find(&:match?) + .map {|matcher| matcher.new(ua) } + .find(&:match?) end def id diff --git a/lib/browser/generic.rb b/lib/browser/generic.rb index e90c4cf0..cd6c2ea7 100644 --- a/lib/browser/generic.rb +++ b/lib/browser/generic.rb @@ -4,7 +4,7 @@ class Generic < Base NAMES = { "QuickTime" => "QuickTime", "CoreMedia" => "Apple CoreMedia" - } + }.freeze def id :generic diff --git a/lib/browser/internet_explorer.rb b/lib/browser/internet_explorer.rb index 4c768524..672dbcf1 100644 --- a/lib/browser/internet_explorer.rb +++ b/lib/browser/internet_explorer.rb @@ -8,7 +8,7 @@ class InternetExplorer < Base "6.0" => "10", "7.0" => "11", "8.0" => "12" - } + }.freeze def id :ie diff --git a/lib/browser/micro_messenger.rb b/lib/browser/micro_messenger.rb index a6c507af..35bc2eb1 100644 --- a/lib/browser/micro_messenger.rb +++ b/lib/browser/micro_messenger.rb @@ -17,4 +17,4 @@ def match? ua =~ /MicroMessenger/i end end -end \ No newline at end of file +end diff --git a/lib/browser/middleware.rb b/lib/browser/middleware.rb index 43342432..7afd24ae 100644 --- a/lib/browser/middleware.rb +++ b/lib/browser/middleware.rb @@ -11,7 +11,7 @@ class Middleware ACCEPT_REGEX = %r[(text/html|\*/\*)] def initialize(app, &block) - fail ArgumentError, "Browser::Middleware requires a block" unless block + raise ArgumentError, "Browser::Middleware requires a block" unless block @app = app @block = block diff --git a/lib/browser/platform.rb b/lib/browser/platform.rb index d9d373d6..afa8fbcf 100644 --- a/lib/browser/platform.rb +++ b/lib/browser/platform.rb @@ -44,8 +44,8 @@ def initialize(ua) def subject @subject ||= self.class.matchers - .map {|matcher| matcher.new(ua) } - .find(&:match?) + .map {|matcher| matcher.new(ua) } + .find(&:match?) end def adobe_air? diff --git a/lib/browser/platform/mac.rb b/lib/browser/platform/mac.rb index dd0946b8..86056557 100644 --- a/lib/browser/platform/mac.rb +++ b/lib/browser/platform/mac.rb @@ -3,7 +3,7 @@ module Browser class Platform class Mac < Base def version - (ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").gsub("_", ".") + (ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").tr("_", ".") end def name diff --git a/lib/browser/testing.rb b/lib/browser/testing.rb index 9b3009e8..cb86c6ad 100644 --- a/lib/browser/testing.rb +++ b/lib/browser/testing.rb @@ -15,7 +15,9 @@ def self.bot_user_agents end def self.search_engine_user_agents - @search_engine_user_agents ||= YAML.load_file(Browser.root.join("test/ua_search_engines.yml")) + @search_engine_user_agents ||= begin + YAML.load_file(Browser.root.join("test/ua_search_engines.yml")) + end end def self.[](key) diff --git a/lib/browser/version.rb b/lib/browser/version.rb index 8aa77cf6..6e47409c 100644 --- a/lib/browser/version.rb +++ b/lib/browser/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Browser - VERSION = "2.2.0" + VERSION = "2.2.0".freeze end diff --git a/test/browser_test.rb b/test/browser_test.rb index 31c7eded..28e31863 100644 --- a/test/browser_test.rb +++ b/test/browser_test.rb @@ -124,8 +124,11 @@ class BrowserTest < Minitest::Test end test "returns all known languages" do - browser = Browser.new("", accept_language: "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3") - assert_equal ["en-US", "en", "pt-BR", "pt"], browser.accept_language.map(&:full) + accept_language = "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3" + browser = Browser.new("", accept_language: accept_language) + languages = browser.accept_language.map(&:full) + + assert_equal ["en-US", "en", "pt-BR", "pt"], languages end test "removes duplicate items" do diff --git a/test/unit/accept_language_test.rb b/test/unit/accept_language_test.rb index 01667598..4abad5a3 100644 --- a/test/unit/accept_language_test.rb +++ b/test/unit/accept_language_test.rb @@ -62,7 +62,8 @@ def assert_language(item, expect = {}) end test "parses complex set" do - result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4,*;q=0.1") + accept_language = "fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4,*;q=0.1" + result = Browser::AcceptLanguage.parse(accept_language) assert_language result[0], code: "fr", region: "CA", quality: 1.0 assert_language result[1], code: "fr", region: nil, quality: 0.8 @@ -72,7 +73,8 @@ def assert_language(item, expect = {}) end test "handles random white spaces" do - result = Browser::AcceptLanguage.parse("fr-CA, fr;q=0.8, en-US;q=0.6,en;q=0.4, *;q=0.1") + accept_language = "fr-CA, fr;q=0.8, en-US;q=0.6,en;q=0.4, *;q=0.1" + result = Browser::AcceptLanguage.parse(accept_language) assert_language result[0], code: "fr", region: "CA", quality: 1.0 assert_language result[1], code: "fr", region: nil, quality: 0.8 @@ -82,7 +84,8 @@ def assert_language(item, expect = {}) end test "sorts based on quality" do - result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5") + accept_language = "fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5" + result = Browser::AcceptLanguage.parse(accept_language) assert_language result[0], code: "fr", region: "CA", quality: 1.0 assert_language result[1], code: "en", region: "US", quality: 0.6 diff --git a/test/unit/alipay_test.rb b/test/unit/alipay_test.rb index 6eafa0a0..8c975ad5 100644 --- a/test/unit/alipay_test.rb +++ b/test/unit/alipay_test.rb @@ -4,8 +4,6 @@ class AlipayTest < Minitest::Test test "detects alipay iOS" do browser = Browser.new(Browser["ALIPAY_IOS"]) - puts browser.id - puts browser.name assert_equal :alipay, browser.id assert browser.alipay? diff --git a/test/unit/generic_test.rb b/test/unit/generic_test.rb index 789060ce..9f99b647 100644 --- a/test/unit/generic_test.rb +++ b/test/unit/generic_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "test_helper" class GenericTest < Minitest::Test diff --git a/test/unit/meta_test.rb b/test/unit/meta_test.rb index c5d072ec..f0362912 100644 --- a/test/unit/meta_test.rb +++ b/test/unit/meta_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "test_helper" class MetaTest < Minitest::Test