umts-custom-cops 0.1.0 → 0.2.0
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 +10 -0
- data/.rubocop_todo.yml +24 -0
- data/README.md +9 -1
- data/Rakefile +4 -2
- data/bin/console +3 -3
- data/lib/umts-custom-cops.rb +1 -1
- data/lib/umts-custom-cops/{be_for_singleton.rb → be_matcher_for_non_duplicable_types.rb} +9 -7
- data/lib/umts-custom-cops/predicate_method_matcher.rb +4 -8
- data/lib/umts-custom-cops/version.rb +1 -1
- data/umts-custom-cops.gemspec +14 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df012c79bb3fa27472fe1cb80e133488b056119
|
4
|
+
data.tar.gz: c85c7c9e7797b13e72e8dd978eab30e3bf6a507b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d834ed868ac58e710d1f8d0873f3ee9c76bb3eca0b1ae43efb7d23562c9339484973dc8d7f847ac189c988805a3137fb0099c3b98de3dd7cdd54b30ac096f958
|
7
|
+
data.tar.gz: 0a030250913339bead54f12d73b28dc68d8178edb0cd4441d2d3d8f91942784f745cc2ad7fc8153ba94ec0789bbfecdefb3a045ecda4febda7be1b08008bba5c
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -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
|
-
|
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
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
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
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/umts-custom-cops.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Cop
|
3
3
|
module UmtsCustomCops
|
4
|
-
|
5
|
-
|
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
|
-
|
30
|
-
|
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
|
data/umts-custom-cops.gemspec
CHANGED
@@ -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 =
|
7
|
+
spec.name = 'umts-custom-cops'
|
8
8
|
spec.version = UmtsCustomCops::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['UMass Transit Services']
|
10
|
+
spec.email = ['transit-it@admin.umass.edu']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
for our internal development purposes
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
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'] =
|
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 =
|
25
|
+
spec.bindir = 'exe'
|
27
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
27
|
+
spec.require_paths = ['lib']
|
29
28
|
|
30
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency 'rspec', '~> 3.0'
|
31
30
|
spec.add_dependency 'rubocop', '0.35.1'
|
32
31
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
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.
|
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/
|
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
|