From f421bc3bdc404ce83a9b967e5d5c86eb933aaddb Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 30 Jun 2017 12:41:35 +0200 Subject: [PATCH 1/5] RuboCop 0.49.1; rake task; linting --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 14 +------------- Gemfile | 8 ++++++-- Rakefile | 7 +++++-- lib/rainbow/color.rb | 12 ++++++++++-- lib/rainbow/null_presenter.rb | 4 ++++ lib/rainbow/presenter.rb | 4 ++++ 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 35ed256..45a2cbf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,9 @@ inherit_from: .rubocop_todo.yml AllCops: + DisplayCopNames: true + DisplayStyleGuide: true + TargetRubyVersion: "2.1" Exclude: - "spec/**/*" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 35267f5..2e0f2cc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-15 22:22:19 +0200 using RuboCop version 0.48.1. +# on 2017-06-30 12:37:52 +0200 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,12 +14,6 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Max: 9 -# Offense count: 2 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 85 - # Offense count: 1 # Configuration parameters: CountComments. Metrics/MethodLength: @@ -33,9 +27,3 @@ Metrics/ModuleLength: # Offense count: 1 Metrics/PerceivedComplexity: Max: 8 - -# Offense count: 2 -Style/MethodMissing: - Exclude: - - 'lib/rainbow/null_presenter.rb' - - 'lib/rainbow/presenter.rb' diff --git a/Gemfile b/Gemfile index 07e80a7..236553c 100644 --- a/Gemfile +++ b/Gemfile @@ -3,12 +3,16 @@ source 'https://rubygems.org' # Specify your gem's dependencies in rainbow.gemspec gemspec -gem 'coveralls', require: false gem 'rake' -gem 'rspec' + +group :test do + gem 'coveralls', require: false + gem 'rspec' +end group :development do gem 'mutant-rspec' + gem 'rubocop', '~> 0.49.1' end group :guard do diff --git a/Rakefile b/Rakefile index 8754e40..b542ef5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,9 @@ require "bundler/gem_tasks" + require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new -RSpec::Core::RakeTask.new(:spec) +require 'rubocop/rake_task' +RuboCop::RakeTask.new -task :default => :spec +task default: %i[spec rubocop] diff --git a/lib/rainbow/color.rb b/lib/rainbow/color.rb index 1ab35e8..4140c0c 100644 --- a/lib/rainbow/color.rb +++ b/lib/rainbow/color.rb @@ -76,10 +76,14 @@ def self.color_names NAMES.keys end + def self.valid_names + color_names.join(', ') + end + def initialize(ground, name) unless Named.color_names.include?(name) raise ArgumentError, - "Unknown color name, valid names: #{Named.color_names.join(', ')}" + "Unknown color name, valid names: #{self.class.valid_names}" end super(ground, NAMES[name]) @@ -122,10 +126,14 @@ def self.color_names NAMES.keys end + def self.valid_names + color_names.join(', ') + end + def initialize(ground, name) unless X11Named.color_names.include?(name) raise ArgumentError, - "Unknown color name, valid names: #{X11Named.color_names.join(', ')}" + "Unknown color name, valid names: #{self.class.valid_names}" end super(ground, *NAMES[name]) diff --git a/lib/rainbow/null_presenter.rb b/lib/rainbow/null_presenter.rb index e330792..9cf79b5 100644 --- a/lib/rainbow/null_presenter.rb +++ b/lib/rainbow/null_presenter.rb @@ -80,6 +80,10 @@ def method_missing(method_name, *args) end end + def respond_to_missing?(method_name, *args) + Color::X11Named.color_names.include?(method_name) && args.empty? || super + end + alias foreground color alias fg color alias bg background diff --git a/lib/rainbow/presenter.rb b/lib/rainbow/presenter.rb index 47b03e4..05c8a75 100644 --- a/lib/rainbow/presenter.rb +++ b/lib/rainbow/presenter.rb @@ -122,6 +122,10 @@ def method_missing(method_name, *args) end end + def respond_to_missing?(method_name, *args) + Color::X11Named.color_names.include?(method_name) && args.empty? || super + end + private def wrap_with_sgr(codes) #:nodoc: From d51e5ab4ea63b3f1e22f9491e6d8c6cb5bdcb3b5 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 30 Jun 2017 12:46:09 +0200 Subject: [PATCH 2/5] Gemfile: RuboCop in :test AND :development group --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 236553c..f8d70cc 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,9 @@ end group :development do gem 'mutant-rspec' +end + +group :test, :development do gem 'rubocop', '~> 0.49.1' end From 44ca6e308ae3ce2feda903c1a30fc6318ccc6e3a Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 30 Jun 2017 12:49:14 +0200 Subject: [PATCH 3/5] RuboCop: crlf rule - See https://github.com/bbatsov/ruby-style-guide\#crlf --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 864cd2f..1535489 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,9 @@ install: build: off +init: + - git config --global core.autocrlf true + test_script: - bundle exec rake From 8edff9e20da49b4194669f4d87d195ba5068dc55 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 30 Jun 2017 14:12:20 +0200 Subject: [PATCH 4/5] RuboCop: exclude vendor folder --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 45a2cbf..641894d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,8 @@ inherit_from: .rubocop_todo.yml AllCops: DisplayCopNames: true DisplayStyleGuide: true + Exclude: + - 'vendor/**/*' TargetRubyVersion: "2.1" Exclude: From d31c0314373e66658dc3ee31cd1880066bafd1b8 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sun, 2 Jul 2017 12:45:59 +0200 Subject: [PATCH 5/5] RuboCop config typo --- .rubocop.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 641894d..0f706cb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,12 +3,10 @@ inherit_from: .rubocop_todo.yml AllCops: DisplayCopNames: true DisplayStyleGuide: true - Exclude: - - 'vendor/**/*' - TargetRubyVersion: "2.1" Exclude: - "spec/**/*" + - "vendor/**/*" Documentation: Enabled: false