umts-custom-cops 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: 044fe565baad9c46631ea18dcc645b02246e9ad088cbf3c58f3ca0f9ebee4c3e
4
- data.tar.gz: 52956058a332e2fc828f2e87df13b055460a408925aa34cca31e1af705c45764
3
+ metadata.gz: 0fbb1c2d13025ac5c23b36646f630f2571a66c8b6ba71f6683100d501ab6ca05
4
+ data.tar.gz: 77b825c0656260d685a9cd10bddd88d87a704c4f474fb33ec1edd8492b6cdf29
5
5
  SHA512:
6
- metadata.gz: a5c7d94c411fa00072104f71ea830ecc2f07ece44eb0cbadcfc02711fb61a47bc9caad1bdf3adfc211b9bb60535e4efb6529f14b019cc468c7c51769011d16d8
7
- data.tar.gz: c85baae025d53d56ac122589898e6d13eb288c4713b6dc0e1bc72734d24bf4c68c128762c863396e2c97a8dd6bfdf03dbca78f40952ea62046a28dc1b26a6855
6
+ metadata.gz: 90031daef0f9f0caa15e40ff450a3ef997134bca280620448985b00b111e00d16f0f5bd5e379d050984920feac5a8b93d57e17ddef133f75b7c9712dce67e4d8
7
+ data.tar.gz: 9e5e4e9658d45bb5566fa14592c8dd6c3c8e54d51987a7b857cefae8270e3d25c6f089ef1309db407d9b4acda8e33a9f4c8ea62bba347ead35c1f9b1fafbfe97
data/.rubocop.yml CHANGED
@@ -1,10 +1,14 @@
1
1
  Metrics/LineLength:
2
2
  Max: 100
3
3
 
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+
4
8
  Style/Documentation:
5
9
  Exclude:
6
10
  - 'spec/**/*'
7
11
  - 'lib/umts-custom-cops/version.rb'
8
12
 
9
- Style/FileName:
13
+ Naming/FileName:
10
14
  Enabled: false
data/bin/console CHANGED
@@ -1,14 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'custom/cops'
4
+ require 'umts-custom-cops'
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
6
+ require 'pry'
7
+ Pry.start
@@ -1,18 +1,23 @@
1
+ require 'rubocop'
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module UmtsCustomCops
4
6
  # Prefer the easier-to-read be matcher for non-duplicable types.
5
7
  #
6
8
  # See the specs for examples.
7
-
8
- # rubocop:disable Metrics/AbcSize
9
9
  class BeMatcherForNonDuplicableTypes < Cop
10
- MSG = 'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'
10
+ MSG = 'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'.freeze
11
11
 
12
- OFFENSE_TYPE_CHECKS = %i(true_type?
13
- false_type?
14
- nil_type?
15
- int_type?)
12
+ def_node_matcher :eq_on_non_duplicable_type?, <<-PATTERN
13
+ (send
14
+ _expectation {:to :not_to}
15
+ (send
16
+ _context {:eq :eql}
17
+ {true false nil int}
18
+ )
19
+ )
20
+ PATTERN
16
21
 
17
22
  def autocorrect(node)
18
23
  lambda do |corrector|
@@ -22,13 +27,8 @@ module RuboCop
22
27
  end
23
28
 
24
29
  def on_send(node)
25
- return unless %i(to not_to).include? node.method_name
26
- return unless node.child_nodes &&
27
- node.child_nodes.first.method_name == :expect
28
- matcher = node.child_nodes[1]
29
- return unless %i(eq eql).include? matcher.method_name
30
- args = matcher.child_nodes.first
31
- return unless OFFENSE_TYPE_CHECKS.find { |check| args.send check }
30
+ return unless eq_on_non_duplicable_type? node
31
+
32
32
  add_offense node, location: :expression, message: MSG
33
33
  end
34
34
  end
@@ -1,31 +1,41 @@
1
- require 'pry-byebug'
1
+ require 'rubocop'
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
5
  module UmtsCustomCops
6
6
  # See the specs for examples.
7
7
  class PredicateMethodMatcher < Cop
8
- MSG = 'Prefer predicate matcher over checking the return value of a predicate method.'
8
+ MESSAGE =
9
+ 'Prefer predicate matcher over checking the return value of a predicate method.'.freeze
9
10
 
10
- BOOLEAN_EQUALITY_MATCHERS = %i(be_true be_false)
11
- GENERIC_EQUALITY_MATCHERS = %i(be eq eql equal)
11
+ def_node_matcher :generic_equality_expectation, <<-PATTERN
12
+ (send
13
+ (send _context :expect
14
+ (send ... $_expectation)
15
+ ) {:to :not_to}
16
+ (send _context {:be :eq :eql :equal}
17
+ {true false}
18
+ )
19
+ )
20
+ PATTERN
21
+
22
+ def_node_matcher :boolean_equality_expectation, <<-PATTERN
23
+ (send
24
+ (send _context :expect
25
+ (send ... $_expectation)
26
+ ) {:to :not_to}
27
+ (send _context {:be_true :be_false})
28
+ )
29
+ PATTERN
12
30
 
13
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
14
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
15
31
  def on_send(node)
16
- return unless %i(to not_to).include? node.method_name
17
- return unless node.child_nodes
18
- expectation = node.child_nodes.first
19
- return unless expectation.method_name == :expect
20
- match_value = expectation.child_nodes.first
21
- return unless match_value.method_name.to_s.end_with? '?'
22
- matcher = node.child_nodes[1]
23
- if GENERIC_EQUALITY_MATCHERS.include? matcher.method_name
24
- matcher_arg = matcher.child_nodes.first
25
- return unless matcher_arg.true_type? || matcher_arg.false_type?
26
- else return unless BOOLEAN_EQUALITY_MATCHERS.include? matcher.method_name
32
+ ends_with_question_mark = ->(method) { method.to_s.end_with? '?' }
33
+
34
+ if generic_equality_expectation(node, &ends_with_question_mark) ||
35
+ boolean_equality_expectation(node, &ends_with_question_mark)
36
+
37
+ add_offense node, location: :expression, message: MESSAGE
27
38
  end
28
- add_offense node, location: :expression, message: MSG
29
39
  end
30
40
  end
31
41
  end
@@ -1,3 +1,3 @@
1
1
  module UmtsCustomCops
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'.freeze
3
3
  end
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'umts-custom-cops/version'
5
4
 
@@ -22,8 +21,6 @@ Gem::Specification.new do |spec|
22
21
  end
23
22
 
24
23
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
24
  spec.require_paths = ['lib']
28
25
 
29
26
  spec.add_dependency 'rspec', '~> 3.0'
@@ -31,7 +28,7 @@ Gem::Specification.new do |spec|
31
28
 
32
29
  spec.add_development_dependency 'bundler', File.open('.bundler.version').read.strip
33
30
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
31
+ spec.add_development_dependency 'pry-byebug'
34
32
  spec.add_development_dependency 'rake', '~> 10.0'
35
33
  spec.add_development_dependency 'simplecov'
36
- spec.add_development_dependency 'pry-byebug'
37
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umts-custom-cops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - UMass Transit Services
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-02 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -67,35 +67,35 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: pry-byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '10.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '10.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry-byebug
98
+ name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="