umts-custom-cops 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/bin/console +3 -10
- data/lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb +14 -14
- data/lib/umts-custom-cops/predicate_method_matcher.rb +28 -18
- data/lib/umts-custom-cops/version.rb +1 -1
- data/umts-custom-cops.gemspec +2 -5
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fbb1c2d13025ac5c23b36646f630f2571a66c8b6ba71f6683100d501ab6ca05
|
4
|
+
data.tar.gz: 77b825c0656260d685a9cd10bddd88d87a704c4f474fb33ec1edd8492b6cdf29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90031daef0f9f0caa15e40ff450a3ef997134bca280620448985b00b111e00d16f0f5bd5e379d050984920feac5a8b93d57e17ddef133f75b7c9712dce67e4d8
|
7
|
+
data.tar.gz: 9e5e4e9658d45bb5566fa14592c8dd6c3c8e54d51987a7b857cefae8270e3d25c6f089ef1309db407d9b4acda8e33a9f4c8ea62bba347ead35c1f9b1fafbfe97
|
data/.rubocop.yml
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
|
-
require 'custom
|
4
|
+
require 'umts-custom-cops'
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
26
|
-
|
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 '
|
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
|
-
|
8
|
+
MESSAGE =
|
9
|
+
'Prefer predicate matcher over checking the return value of a predicate method.'.freeze
|
9
10
|
|
10
|
-
|
11
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
data/umts-custom-cops.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
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.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- UMass Transit Services
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
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:
|
70
|
+
name: pry-byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
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:
|
98
|
+
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|