umts-custom-cops 0.2.1 → 1.0.1

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
- SHA1:
3
- metadata.gz: b3f10c56d08bacec50c43fa2244120f3247896b0
4
- data.tar.gz: 81465aa93b24c577a4f10c359fc7af483b1dbf29
2
+ SHA256:
3
+ metadata.gz: 36171c1c65fdaa89d9f51ac853054bdfb1b70fba4c7cc45703558601e6cb15fa
4
+ data.tar.gz: 242a501b29292aa62c2f9164d318de11366585d59ed7f219e27dbb882c5a2726
5
5
  SHA512:
6
- metadata.gz: c5c6fbaf56ab748a55412364234c5d92aab4a6cf4cecee45028b247f42f30b889f3b2d38775cf5fb56cc4d39b1e807befdbf25b04307c9ddc11cb53a1e62152e
7
- data.tar.gz: 741e057de97f12880eaebedead827efcfb986e61b88d3c92201bc214feddabc38dbdd24ddef2bbd8d73e7a60b276b5b1a30b367700956976b77d6f73c1fd0b98
6
+ metadata.gz: 9beee0751e12708e8b8929304525859a083cf730efbab77a709c7af054403156c5a920b8d9d80536670d338470438f896fe752a6fc03097bcb32f0f0febd9ed9
7
+ data.tar.gz: e1cdd4323024aa66c17ce2c0d0bce44dfdcc4165cd3a4d7e66f7ea713dd18809522ac6b94a5459fa919a60d759b231868623c297cda530aa98b5d7f059c8b961
data/.rubocop.yml CHANGED
@@ -1,10 +1,19 @@
1
- Metrics/LineLength:
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 2.5
5
+
6
+ Layout/LineLength:
2
7
  Max: 100
3
8
 
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - 'spec/**/*'
12
+
4
13
  Style/Documentation:
5
14
  Exclude:
6
15
  - 'spec/**/*'
7
16
  - 'lib/umts-custom-cops/version.rb'
8
17
 
9
- Style/FileName:
18
+ Naming/FileName:
10
19
  Enabled: false
data/.travis.yml CHANGED
@@ -1,12 +1,24 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.7
4
- - 2.2.4
5
- - 2.3.0
3
+ - 2.5.8
4
+ - 2.6.5
5
+ - 2.7.2
6
+ - 3.0.0
6
7
  env: CODECLIMATE_REPO_TOKEN=c356c22cc5b342d3cba9a1fb9d71b63b52de9b9daa1f54c07f959f90da05c8ff
7
- before_install: gem install bundler
8
- script: bundle exec rake
8
+ before_install:
9
+ - gem update --system
10
+ - gem install bundler
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+ script:
16
+ - bundle exec rake
17
+ after_script:
18
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
9
19
  notifications:
10
20
  email:
21
+ on_success: change
22
+ on_failure: change
11
23
  recipients:
12
24
  - transit-it@admin.umass.edu
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in custom-cops.gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 David Faulkenberry
3
+ Copyright (c) 2020 UMass Transit Services
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,60 +1,37 @@
1
1
  # UmtsCustomCops
2
2
 
3
- Custom Rubocops, currently all related to RSpec, used for UMass Transit's internal Rails development purposes.
3
+ **This gem is no longer under development.** All of the cops contained in this
4
+ gem are also available in the [rubocop-rspec][rr] gem.
4
5
 
5
- Primary contributor is @dfaulken.
6
+ ## Migrating to rubocop-rspec
6
7
 
7
- A lot of the ideas for this came from some reading of the rubocop source code, so thanks to the RuboCop team for making it public.
8
+ * Remove `gem 'umts-custom-cops'` from your Gemfile
9
+ * Add `gem 'rubocop-rspec'` to your Gemfile
10
+ * Remove `require: umts-custom-cops` from your `.rubocop.yml` file
11
+ * Add `require: rubocop-rspec` to your `.rubocop.yml` file
8
12
 
9
- [![Build Status](https://travis-ci.org/umts/custom-cops.svg?branch=master)](https://travis-ci.org/umts/custom-cops)
10
- [![Test Coverage](https://codeclimate.com/github/umts/custom-cops/badges/coverage.svg)](https://codeclimate.com/github/umts/custom-cops/coverage)
11
- [![Code Climate](https://codeclimate.com/github/umts/custom-cops/badges/gpa.svg)](https://codeclimate.com/github/umts/custom-cops)
12
- [![Issue Count](https://codeclimate.com/github/umts/custom-cops/badges/issue_count.svg)](https://codeclimate.com/github/umts/custom-cops)
13
+ If you _only_ want a version of the two cops provided by this gem, you can
14
+ add the following to your `.rubocop.yml` file:
13
15
 
14
- ## Installation
16
+ ```yml
17
+ RSpec:
18
+ Enabled: false
15
19
 
16
- Add this line to your application's Gemfile:
20
+ RSpec/BeEql:
21
+ Enabled: true
17
22
 
18
- ```ruby
19
- gem 'umts-custom-cops'
23
+ RSpec/PredicateMatcher:
24
+ Enabled: true
20
25
  ```
21
26
 
22
- And then execute:
27
+ Also, if you have a custom `.yml` file to get this gem to work under
28
+ CodeClimate, you will not need to do that with `rubocop-rspec`. It is included
29
+ in the CodeClimate engine.
23
30
 
24
- $ bundle
25
-
26
- Or install it yourself as:
27
-
28
- $ gem install umts-custom-cops
29
-
30
- ## Usage
31
-
32
- Add to your `rubocop.yml`:
33
-
34
- ```xml
35
- require: umts-custom-cops
36
- ```
37
-
38
- Or on the command line:
39
-
40
- $ rubocop --require=umts-custom-cops
41
-
42
- You may enable/disable them just as with any other cop.
43
-
44
- ## Development
45
-
46
- 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.
47
-
48
- 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).
49
-
50
- 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:
51
-
52
- $ git submodule add -f https://github.com/bbatsov/rubocop
53
-
54
- ## Contributing
55
-
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/umts/custom-cops.
57
31
 
58
32
  ## License
59
33
 
60
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+ The gem is available as open source under the terms of the
35
+ [MIT License](http://opensource.org/licenses/MIT).
36
+
37
+ [rr]: https://github.com/rubocop/rubocop-rspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
data/bin/console CHANGED
@@ -1,14 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
- require 'custom/cops'
5
+ require 'umts-custom-cops'
5
6
 
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
7
+ require 'pry'
8
+ Pry.start
data/bin/setup CHANGED
@@ -3,6 +3,5 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
+ gem install bundler -v "$(cat .bundler.version)"
6
7
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'umts-custom-cops/version'
2
4
 
3
5
  require 'umts-custom-cops/be_matcher_for_non_duplicable_types'
4
6
  require 'umts-custom-cops/predicate_method_matcher'
7
+
8
+ warn "'umts-custom-cops' is deprecated. Use 'rubocop-rspec' instead"
@@ -1,18 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
1
5
  module RuboCop
2
6
  module Cop
3
7
  module UmtsCustomCops
4
8
  # Prefer the easier-to-read be matcher for non-duplicable types.
5
9
  #
6
10
  # See the specs for examples.
7
-
8
- # rubocop:disable Metrics/AbcSize
9
11
  class BeMatcherForNonDuplicableTypes < Cop
10
12
  MSG = 'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'
11
13
 
12
- OFFENSE_TYPE_CHECKS = %i(true_type?
13
- false_type?
14
- nil_type?
15
- int_type?)
14
+ def_node_matcher :eq_on_non_duplicable_type?, <<-PATTERN
15
+ (send
16
+ _expectation {:to :not_to}
17
+ (send
18
+ _context {:eq :eql}
19
+ {true false nil}
20
+ )
21
+ )
22
+ PATTERN
16
23
 
17
24
  def autocorrect(node)
18
25
  lambda do |corrector|
@@ -22,14 +29,9 @@ module RuboCop
22
29
  end
23
30
 
24
31
  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 }
32
- add_offense node, :expression, MSG
32
+ return unless eq_on_non_duplicable_type? node
33
+
34
+ add_offense node, location: :expression, message: MSG
33
35
  end
34
36
  end
35
37
  end
@@ -1,31 +1,43 @@
1
- require 'pry-byebug'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
2
4
 
3
5
  module RuboCop
4
6
  module Cop
5
7
  module UmtsCustomCops
6
8
  # See the specs for examples.
7
9
  class PredicateMethodMatcher < Cop
8
- MSG = 'Prefer predicate matcher over checking the return value of a predicate method.'
10
+ MESSAGE =
11
+ 'Prefer predicate matcher over checking the return value of a predicate method.'
12
+
13
+ def_node_matcher :generic_equality_expectation, <<-PATTERN
14
+ (send
15
+ (send _context :expect
16
+ (send ... $_expectation)
17
+ ) {:to :not_to}
18
+ (send _context {:be :eq :eql :equal}
19
+ {true false}
20
+ )
21
+ )
22
+ PATTERN
9
23
 
10
- BOOLEAN_EQUALITY_MATCHERS = %i(be_true be_false)
11
- GENERIC_EQUALITY_MATCHERS = %i(be eq eql equal)
24
+ def_node_matcher :boolean_equality_expectation, <<-PATTERN
25
+ (send
26
+ (send _context :expect
27
+ (send ... $_expectation)
28
+ ) {:to :not_to}
29
+ (send _context {:be_true :be_false})
30
+ )
31
+ PATTERN
12
32
 
13
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
14
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
15
33
  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
34
+ ends_with_question_mark = ->(method) { method.to_s.end_with? '?' }
35
+
36
+ if generic_equality_expectation(node, &ends_with_question_mark) ||
37
+ boolean_equality_expectation(node, &ends_with_question_mark)
38
+
39
+ add_offense node, location: :expression, message: MESSAGE
27
40
  end
28
- add_offense node, :expression, MSG
29
41
  end
30
42
  end
31
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UmtsCustomCops
2
- VERSION = '0.2.1'
4
+ VERSION = '1.0.1'
3
5
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'umts-custom-cops/version'
5
6
 
@@ -14,24 +15,34 @@ Gem::Specification.new do |spec|
14
15
  spec.homepage = 'https://github.com/umts/custom-cops'
15
16
  spec.license = 'MIT'
16
17
 
18
+ spec.post_install_message = <<~PIM
19
+ umts-custom-cops is no longer under development, and all functionality
20
+ provided by this gem can also be found in the `rubocop-rspec` gem. See
21
+ the README file:
22
+
23
+ https://github.com/umts/custom-cops/blob/master/README.md
24
+
25
+ for migration instructions.
26
+ PIM
27
+
17
28
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
29
  # 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 fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
- end
30
+ raise <<~MSG unless spec.respond_to?(:metadata)
31
+ RubyGems 2.0 or newer is required to protect against public gem pushes.
32
+ MSG
33
+
34
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
35
 
24
36
  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
37
  spec.require_paths = ['lib']
28
38
 
29
- spec.add_dependency 'rspec', '~> 3.0'
30
- spec.add_dependency 'rubocop', '0.37.2'
39
+ spec.required_ruby_version = '>= 2.5.0'
31
40
 
32
- spec.add_development_dependency 'bundler', '~> 1.11'
33
- spec.add_development_dependency 'codeclimate-test-reporter'
34
- spec.add_development_dependency 'rake', '~> 10.0'
35
- spec.add_development_dependency 'simplecov'
41
+ spec.add_dependency 'rubocop', '~> 1.10'
42
+
43
+ spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
36
44
  spec.add_development_dependency 'pry-byebug'
45
+ spec.add_development_dependency 'rake', '~> 13.0'
46
+ spec.add_development_dependency 'rspec', '~> 3.0'
47
+ spec.add_development_dependency 'simplecov'
37
48
  end
metadata CHANGED
@@ -1,59 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umts-custom-cops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.1
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: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2021-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '1.10'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
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.37.2
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 0.37.2
26
+ version: '1.10'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '1.11'
33
+ version: '2.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.1.4
48
37
  type: :development
49
38
  prerelease: false
50
39
  version_requirements: !ruby/object:Gem::Requirement
51
40
  requirements:
52
41
  - - "~>"
53
42
  - !ruby/object:Gem::Version
54
- version: '1.11'
43
+ version: '2.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.1.4
55
47
  - !ruby/object:Gem::Dependency
56
- name: codeclimate-test-reporter
48
+ name: pry-byebug
57
49
  requirement: !ruby/object:Gem::Requirement
58
50
  requirements:
59
51
  - - ">="
@@ -72,30 +64,30 @@ dependencies:
72
64
  requirements:
73
65
  - - "~>"
74
66
  - !ruby/object:Gem::Version
75
- version: '10.0'
67
+ version: '13.0'
76
68
  type: :development
77
69
  prerelease: false
78
70
  version_requirements: !ruby/object:Gem::Requirement
79
71
  requirements:
80
72
  - - "~>"
81
73
  - !ruby/object:Gem::Version
82
- version: '10.0'
74
+ version: '13.0'
83
75
  - !ruby/object:Gem::Dependency
84
- name: simplecov
76
+ name: rspec
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
- - - ">="
79
+ - - "~>"
88
80
  - !ruby/object:Gem::Version
89
- version: '0'
81
+ version: '3.0'
90
82
  type: :development
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
- - - ">="
86
+ - - "~>"
95
87
  - !ruby/object:Gem::Version
96
- version: '0'
88
+ version: '3.0'
97
89
  - !ruby/object:Gem::Dependency
98
- name: pry-byebug
90
+ name: simplecov
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
101
93
  - - ">="
@@ -136,7 +128,14 @@ licenses:
136
128
  - MIT
137
129
  metadata:
138
130
  allowed_push_host: https://rubygems.org
139
- post_install_message:
131
+ post_install_message: |
132
+ umts-custom-cops is no longer under development, and all functionality
133
+ provided by this gem can also be found in the `rubocop-rspec` gem. See
134
+ the README file:
135
+
136
+ https://github.com/umts/custom-cops/blob/master/README.md
137
+
138
+ for migration instructions.
140
139
  rdoc_options: []
141
140
  require_paths:
142
141
  - lib
@@ -144,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
143
  requirements:
145
144
  - - ">="
146
145
  - !ruby/object:Gem::Version
147
- version: '0'
146
+ version: 2.5.0
148
147
  required_rubygems_version: !ruby/object:Gem::Requirement
149
148
  requirements:
150
149
  - - ">="
151
150
  - !ruby/object:Gem::Version
152
151
  version: '0'
153
152
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.2.2
153
+ rubygems_version: 3.0.1
156
154
  signing_key:
157
155
  specification_version: 4
158
156
  summary: Custom Rails-specific Rubocop cops for our internal development purposes