umts-custom-cops 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4430301fe3d124d7942336cc0ddf0b9d18a7b9a
4
- data.tar.gz: 1b65dfa2a42003c2eaeaefdadeb5a6f013552961
3
+ metadata.gz: 1df012c79bb3fa27472fe1cb80e133488b056119
4
+ data.tar.gz: c85c7c9e7797b13e72e8dd978eab30e3bf6a507b
5
5
  SHA512:
6
- metadata.gz: 12647f91b2e596676b933cb1780803bd05d766902eab3f07b8a6ecfdc6f4e9e92909e2dbe37ec4bdb1ed1df8f5bb9b0cc7d5cdf4309196f97ad73cd7c97d4024
7
- data.tar.gz: 65487853b78ccc60061dee5774ecf61f7c27eac7b11f5849c4efe513a918636d586a7c1d8400bd302fe8790ce888386235f95c40f25509965ae706f7131f82ab
6
+ metadata.gz: d834ed868ac58e710d1f8d0873f3ee9c76bb3eca0b1ae43efb7d23562c9339484973dc8d7f847ac189c988805a3137fb0099c3b98de3dd7cdd54b30ac096f958
7
+ data.tar.gz: 0a030250913339bead54f12d73b28dc68d8178edb0cd4441d2d3d8f91942784f745cc2ad7fc8153ba94ec0789bbfecdefb3a045ecda4febda7be1b08008bba5c
@@ -0,0 +1,10 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+
4
+ Style/Documentation:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+ - 'lib/umts-custom-cops/version.rb'
8
+
9
+ Style/FileName:
10
+ Enabled: false
@@ -0,0 +1,24 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-01-14 16:44:47 -0500 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 25
12
+
13
+ # Offense count: 1
14
+ Metrics/CyclomaticComplexity:
15
+ Max: 9
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: CountComments.
19
+ Metrics/MethodLength:
20
+ Max: 13
21
+
22
+ # Offense count: 1
23
+ Metrics/PerceivedComplexity:
24
+ Max: 10
data/README.md CHANGED
@@ -24,7 +24,15 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- TODO: Instructions on adding custom cops.
27
+ Add to your `rubocop.yml`:
28
+
29
+ $ require: umts-custom-cops
30
+
31
+ Or on the command line:
32
+
33
+ $ rubocop --require=umts-custom-cops
34
+
35
+ You may enable/disable them just as with any other cop.
28
36
 
29
37
  ## Development
30
38
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
8
  task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "custom/cops"
3
+ require 'bundler/setup'
4
+ require 'custom/cops'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "custom/cops"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,4 +1,4 @@
1
1
  require 'umts-custom-cops/version'
2
2
 
3
- require 'umts-custom-cops/be_for_singleton'
3
+ require 'umts-custom-cops/be_matcher_for_non_duplicable_types'
4
4
  require 'umts-custom-cops/predicate_method_matcher'
@@ -1,8 +1,13 @@
1
1
  module RuboCop
2
2
  module Cop
3
3
  module UmtsCustomCops
4
- class BeForSingleton < Cop
5
- MSG = 'Prefer `be` matcher to `eq` or `eql` for singleton types.'
4
+ # Prefer the easier-to-read be matcher for non-duplicable types.
5
+ #
6
+ # See the specs for examples.
7
+
8
+ # rubocop:disable Metrics/AbcSize
9
+ class BeMatcherForNonDuplicableTypes < Cop
10
+ MSG = 'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'
6
11
 
7
12
  OFFENSE_TYPE_CHECKS = %i(true_type?
8
13
  false_type?
@@ -21,14 +26,11 @@ module RuboCop
21
26
  return unless %i(to not_to).include? node.method_name
22
27
  return unless node.child_nodes &&
23
28
  node.child_nodes.first.method_name == :expect
24
-
25
29
  matcher = node.child_nodes[1]
26
30
  return unless %i(eq eql).include? matcher.method_name
27
-
28
31
  args = matcher.child_nodes.first
29
- if OFFENSE_TYPE_CHECKS.find { |check| args.send check }
30
- add_offense node, :expression, MSG
31
- end
32
+ return unless OFFENSE_TYPE_CHECKS.find { |check| args.send check }
33
+ add_offense node, :expression, MSG
32
34
  end
33
35
  end
34
36
  end
@@ -3,32 +3,28 @@ require 'pry-byebug'
3
3
  module RuboCop
4
4
  module Cop
5
5
  module UmtsCustomCops
6
+ # See the specs for examples.
6
7
  class PredicateMethodMatcher < Cop
7
8
  MSG = 'Prefer predicate matcher over checking the return value of a predicate method.'
8
9
 
9
10
  BOOLEAN_EQUALITY_MATCHERS = %i(be_true be_false)
10
11
  GENERIC_EQUALITY_MATCHERS = %i(be eq eql equal)
11
12
 
12
-
13
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
14
+ # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
13
15
  def on_send(node)
14
16
  return unless %i(to not_to).include? node.method_name
15
-
16
17
  return unless node.child_nodes
17
18
  expectation = node.child_nodes.first
18
19
  return unless expectation.method_name == :expect
19
-
20
20
  match_value = expectation.child_nodes.first
21
21
  return unless match_value.method_name.to_s.end_with? '?'
22
-
23
22
  matcher = node.child_nodes[1]
24
23
  if GENERIC_EQUALITY_MATCHERS.include? matcher.method_name
25
24
  matcher_arg = matcher.child_nodes.first
26
25
  return unless matcher_arg.true_type? || matcher_arg.false_type?
27
- else
28
- return unless BOOLEAN_EQUALITY_MATCHERS.include? matcher.method_name
26
+ else return unless BOOLEAN_EQUALITY_MATCHERS.include? matcher.method_name
29
27
  end
30
-
31
-
32
28
  add_offense node, :expression, MSG
33
29
  end
34
30
  end
@@ -1,3 +1,3 @@
1
1
  module UmtsCustomCops
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
@@ -4,34 +4,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'umts-custom-cops/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "umts-custom-cops"
7
+ spec.name = 'umts-custom-cops'
8
8
  spec.version = UmtsCustomCops::VERSION
9
- spec.authors = ["UMass Transit Services"]
10
- spec.email = ["transit-it@admin.umass.edu"]
9
+ spec.authors = ['UMass Transit Services']
10
+ spec.email = ['transit-it@admin.umass.edu']
11
11
 
12
- spec.summary = %q{Custom Rails-specific Rubocop cops
13
- for our internal development purposes}
14
- spec.homepage = "https://github.com/umts/custom-cops"
15
- spec.license = "MIT"
12
+ spec.summary = 'Custom Rails-specific Rubocop cops
13
+ for our internal development purposes'
14
+ spec.homepage = 'https://github.com/umts/custom-cops'
15
+ spec.license = 'MIT'
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
18
  # delete this section to allow pushing this gem to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
22
  end
24
23
 
25
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
26
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
27
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
27
+ spec.require_paths = ['lib']
29
28
 
30
- spec.add_dependency "rspec", "~> 3.0"
29
+ spec.add_dependency 'rspec', '~> 3.0'
31
30
  spec.add_dependency 'rubocop', '0.35.1'
32
31
 
33
- spec.add_development_dependency "bundler", "~> 1.11"
34
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency 'bundler', '~> 1.11'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
35
34
  spec.add_development_dependency 'simplecov'
36
35
  spec.add_development_dependency 'pry-byebug'
37
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umts-custom-cops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - UMass Transit Services
@@ -104,6 +104,8 @@ files:
104
104
  - ".gitignore"
105
105
  - ".gitmodules"
106
106
  - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".rubocop_todo.yml"
107
109
  - ".ruby-version"
108
110
  - ".travis.yml"
109
111
  - Gemfile
@@ -113,7 +115,7 @@ files:
113
115
  - bin/console
114
116
  - bin/setup
115
117
  - lib/umts-custom-cops.rb
116
- - lib/umts-custom-cops/be_for_singleton.rb
118
+ - lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb
117
119
  - lib/umts-custom-cops/predicate_method_matcher.rb
118
120
  - lib/umts-custom-cops/version.rb
119
121
  - umts-custom-cops.gemspec