umts-custom-cops 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4430301fe3d124d7942336cc0ddf0b9d18a7b9a
4
+ data.tar.gz: 1b65dfa2a42003c2eaeaefdadeb5a6f013552961
5
+ SHA512:
6
+ metadata.gz: 12647f91b2e596676b933cb1780803bd05d766902eab3f07b8a6ecfdc6f4e9e92909e2dbe37ec4bdb1ed1df8f5bb9b0cc7d5cdf4309196f97ad73cd7c97d4024
7
+ data.tar.gz: 65487853b78ccc60061dee5774ecf61f7c27eac7b11f5849c4efe513a918636d586a7c1d8400bd302fe8790ce888386235f95c40f25509965ae706f7131f82ab
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ vendor/rubocop
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/rubocop"]
2
+ path = vendor/rubocop
3
+ url = https://github.com/bbatsov/rubocop.git
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.7
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm: 2.1.2
3
+ before_install: gem install bundler -v 1.11.2
4
+ script: bundle exec rake
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - transit-it@admin.umass.edu
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in custom-cops.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 David Faulkenberry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # UmtsCustomCops
2
+
3
+ [![Build Status](https://travis-ci.org/umts/custom-cops.svg?branch=master)](https://travis-ci.org/umts/custom-cops)
4
+
5
+ Custom Rubocops, currently all related to RSpec, used for UMass Transit's internal Rails development purposes.
6
+
7
+ Primary contributor is @dfaulken.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'umts-custom-cops'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install umts-custom-cops
24
+
25
+ ## Usage
26
+
27
+ TODO: Instructions on adding custom cops.
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ To run the spec files, you'll need Rubocop's spec support methods. In order to achieve this, set up RuboCop as a git submodule:
36
+
37
+ $ git submodule add -f https://github.com/bbatsov/rubocop
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/umts/custom-cops.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "custom/cops"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ module RuboCop
2
+ module Cop
3
+ module UmtsCustomCops
4
+ class BeForSingleton < Cop
5
+ MSG = 'Prefer `be` matcher to `eq` or `eql` for singleton types.'
6
+
7
+ OFFENSE_TYPE_CHECKS = %i(true_type?
8
+ false_type?
9
+ nil_type?
10
+ int_type?
11
+ float_type?)
12
+
13
+ def autocorrect(node)
14
+ lambda do |corrector|
15
+ matcher = node.child_nodes[1]
16
+ corrector.replace matcher.loc.selector, 'be'
17
+ end
18
+ end
19
+
20
+ def on_send(node)
21
+ return unless %i(to not_to).include? node.method_name
22
+ return unless node.child_nodes &&
23
+ node.child_nodes.first.method_name == :expect
24
+
25
+ matcher = node.child_nodes[1]
26
+ return unless %i(eq eql).include? matcher.method_name
27
+
28
+ args = matcher.child_nodes.first
29
+ if OFFENSE_TYPE_CHECKS.find { |check| args.send check }
30
+ add_offense node, :expression, MSG
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'pry-byebug'
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module UmtsCustomCops
6
+ class PredicateMethodMatcher < Cop
7
+ MSG = 'Prefer predicate matcher over checking the return value of a predicate method.'
8
+
9
+ BOOLEAN_EQUALITY_MATCHERS = %i(be_true be_false)
10
+ GENERIC_EQUALITY_MATCHERS = %i(be eq eql equal)
11
+
12
+
13
+ def on_send(node)
14
+ return unless %i(to not_to).include? node.method_name
15
+
16
+ return unless node.child_nodes
17
+ expectation = node.child_nodes.first
18
+ return unless expectation.method_name == :expect
19
+
20
+ match_value = expectation.child_nodes.first
21
+ return unless match_value.method_name.to_s.end_with? '?'
22
+
23
+ matcher = node.child_nodes[1]
24
+ if GENERIC_EQUALITY_MATCHERS.include? matcher.method_name
25
+ matcher_arg = matcher.child_nodes.first
26
+ return unless matcher_arg.true_type? || matcher_arg.false_type?
27
+ else
28
+ return unless BOOLEAN_EQUALITY_MATCHERS.include? matcher.method_name
29
+ end
30
+
31
+
32
+ add_offense node, :expression, MSG
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module UmtsCustomCops
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'umts-custom-cops/version'
2
+
3
+ require 'umts-custom-cops/be_for_singleton'
4
+ require 'umts-custom-cops/predicate_method_matcher'
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'umts-custom-cops/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "umts-custom-cops"
8
+ spec.version = UmtsCustomCops::VERSION
9
+ spec.authors = ["UMass Transit Services"]
10
+ spec.email = ["transit-it@admin.umass.edu"]
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"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
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."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "rspec", "~> 3.0"
31
+ spec.add_dependency 'rubocop', '0.35.1'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.11"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency 'simplecov'
36
+ spec.add_development_dependency 'pry-byebug'
37
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: umts-custom-cops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - UMass Transit Services
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.35.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.35.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - transit-it@admin.umass.edu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".gitmodules"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/umts-custom-cops.rb
116
+ - lib/umts-custom-cops/be_for_singleton.rb
117
+ - lib/umts-custom-cops/predicate_method_matcher.rb
118
+ - lib/umts-custom-cops/version.rb
119
+ - umts-custom-cops.gemspec
120
+ homepage: https://github.com/umts/custom-cops
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ allowed_push_host: https://rubygems.org
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Custom Rails-specific Rubocop cops for our internal development purposes
145
+ test_files: []