umts-custom-cops 0.2.0 → 1.0.0

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: 1df012c79bb3fa27472fe1cb80e133488b056119
4
- data.tar.gz: c85c7c9e7797b13e72e8dd978eab30e3bf6a507b
2
+ SHA256:
3
+ metadata.gz: 3fd3babbd34390821e6966e35cc99538218c43bceb35b5dc4dc888711d811d38
4
+ data.tar.gz: 439c6e906a47df2bacb02ac0f4023c96409ffa0534feb8da3e23a588ad54a678
5
5
  SHA512:
6
- metadata.gz: d834ed868ac58e710d1f8d0873f3ee9c76bb3eca0b1ae43efb7d23562c9339484973dc8d7f847ac189c988805a3137fb0099c3b98de3dd7cdd54b30ac096f958
7
- data.tar.gz: 0a030250913339bead54f12d73b28dc68d8178edb0cd4441d2d3d8f91942784f745cc2ad7fc8153ba94ec0789bbfecdefb3a045ecda4febda7be1b08008bba5c
6
+ metadata.gz: 6924bc7f455be47fe691f52418bce0550b2de075e4b8c95e6b0a2090b8d214db36f9923a4d47240f935111bb01869f6f37ebd61016163421a0fb02ed272afa51
7
+ data.tar.gz: c91ae1f325772c354ab34c9fcea65b13705265e62f38444824bc5156843fe01ad9056f0fb5db0655e23ec57eae760ec6433065a98dbe5750d5b5355b7c6dc1d0
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,8 +1,24 @@
1
1
  language: ruby
2
- rvm: 2.1.2
3
- before_install: gem install bundler -v 1.11.2
4
- script: bundle exec rake
2
+ rvm:
3
+ - 2.5.8
4
+ - 2.6.5
5
+ - 2.7.2
6
+ - 3.0.0
7
+ env: CODECLIMATE_REPO_TOKEN=c356c22cc5b342d3cba9a1fb9d71b63b52de9b9daa1f54c07f959f90da05c8ff
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
5
19
  notifications:
6
20
  email:
21
+ on_success: change
22
+ on_failure: change
7
23
  recipients:
8
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,10 +1,15 @@
1
1
  # UmtsCustomCops
2
2
 
3
- [![Build Status](https://travis-ci.org/umts/custom-cops.svg?branch=master)](https://travis-ci.org/umts/custom-cops)
3
+ Custom Rubocops, currently all related to RSpec, used for UMass Transit's
4
+ internal Rails development purposes.
4
5
 
5
- Custom Rubocops, currently all related to RSpec, used for UMass Transit's internal Rails development purposes.
6
+ A lot of the ideas for this came from some reading of the rubocop source
7
+ code, so thanks to the RuboCop team for making it public.
6
8
 
7
- Primary contributor is @dfaulken.
9
+ [![Build Status][travis-badge]][travis]
10
+ [![Test Coverage][coverage-badge]][codeclimate]
11
+ [![Code Climate][gpa-badge]][codeclimate]
12
+ [![Issue Count][issue-badge]][codeclimate]
8
13
 
9
14
  ## Installation
10
15
 
@@ -26,7 +31,9 @@ Or install it yourself as:
26
31
 
27
32
  Add to your `rubocop.yml`:
28
33
 
29
- $ require: umts-custom-cops
34
+ ```xml
35
+ require: umts-custom-cops
36
+ ```
30
37
 
31
38
  Or on the command line:
32
39
 
@@ -36,18 +43,29 @@ You may enable/disable them just as with any other cop.
36
43
 
37
44
  ## Development
38
45
 
39
- 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.
40
-
41
- 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).
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
47
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
48
+ prompt that will allow you to experiment.
42
49
 
43
- 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:
44
-
45
- $ git submodule add -f https://github.com/bbatsov/rubocop
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To
51
+ release a new version, update the version number in `version.rb`, and then run
52
+ `bundle exec rake release`, which will create a git tag for the version, push
53
+ git commits and tags, and push the `.gem` file to
54
+ [rubygems.org](https://rubygems.org).
46
55
 
47
56
  ## Contributing
48
57
 
49
- Bug reports and pull requests are welcome on GitHub at https://github.com/umts/custom-cops.
58
+ Bug reports and pull requests are welcome on GitHub at
59
+ https://github.com/umts/custom-cops.
50
60
 
51
61
  ## License
52
62
 
53
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
63
+ The gem is available as open source under the terms of the
64
+ [MIT License](http://opensource.org/licenses/MIT).
65
+
66
+ [travis]: https://travis-ci.org/umts/custom-cops
67
+ [codeclimate]: https://codeclimate.com/github/umts/custom-cops/coverage
68
+ [travis-badge]: https://travis-ci.org/umts/custom-cops.svg?branch=master
69
+ [coverage-badge]: https://codeclimate.com/github/umts/custom-cops/badges/coverage.svg
70
+ [gpa-badge]: https://codeclimate.com/github/umts/custom-cops/badges/gpa.svg
71
+ [issue-badge]: https://codeclimate.com/github/umts/custom-cops/badges/issue_count.svg
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,3 +1,5 @@
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'
@@ -1,19 +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?
16
- float_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
17
23
 
18
24
  def autocorrect(node)
19
25
  lambda do |corrector|
@@ -23,14 +29,9 @@ module RuboCop
23
29
  end
24
30
 
25
31
  def on_send(node)
26
- return unless %i(to not_to).include? node.method_name
27
- return unless node.child_nodes &&
28
- node.child_nodes.first.method_name == :expect
29
- matcher = node.child_nodes[1]
30
- return unless %i(eq eql).include? matcher.method_name
31
- args = matcher.child_nodes.first
32
- return unless OFFENSE_TYPE_CHECKS.find { |check| args.send check }
33
- add_offense node, :expression, MSG
32
+ return unless eq_on_non_duplicable_type? node
33
+
34
+ add_offense node, location: :expression, message: MSG
34
35
  end
35
36
  end
36
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.0'
4
+ VERSION = '1.0.0'
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
 
@@ -16,21 +17,22 @@ Gem::Specification.new do |spec|
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
19
  # 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
20
+ raise <<~MSG unless spec.respond_to?(:metadata)
21
+ RubyGems 2.0 or newer is required to protect against public gem pushes.
22
+ MSG
23
+
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
25
 
24
26
  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
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_dependency 'rspec', '~> 3.0'
30
- spec.add_dependency 'rubocop', '0.35.1'
29
+ spec.required_ruby_version = '>= 2.5.0'
31
30
 
32
- spec.add_development_dependency 'bundler', '~> 1.11'
33
- spec.add_development_dependency 'rake', '~> 10.0'
34
- spec.add_development_dependency 'simplecov'
31
+ spec.add_dependency 'rubocop', '~> 1.10'
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
35
34
  spec.add_development_dependency 'pry-byebug'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'simplecov'
36
38
  end
metadata CHANGED
@@ -1,87 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umts-custom-cops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
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-01-14 00:00:00.000000000 Z
11
+ date: 2021-02-19 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'
26
+ version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rubocop
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.35.1
34
- type: :runtime
33
+ version: '2.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.1.4
37
+ type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - '='
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.1'
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: 0.35.1
46
+ version: 2.1.4
41
47
  - !ruby/object:Gem::Dependency
42
- name: bundler
48
+ name: pry-byebug
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
- version: '1.11'
53
+ version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "~>"
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '1.11'
60
+ version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '10.0'
67
+ version: '13.0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '10.0'
74
+ version: '13.0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: simplecov
76
+ name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: '3.0'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ">="
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0'
88
+ version: '3.0'
83
89
  - !ruby/object:Gem::Dependency
84
- name: pry-byebug
90
+ name: simplecov
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - ">="
@@ -105,8 +111,6 @@ files:
105
111
  - ".gitmodules"
106
112
  - ".rspec"
107
113
  - ".rubocop.yml"
108
- - ".rubocop_todo.yml"
109
- - ".ruby-version"
110
114
  - ".travis.yml"
111
115
  - Gemfile
112
116
  - LICENSE.txt
@@ -132,15 +136,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
136
  requirements:
133
137
  - - ">="
134
138
  - !ruby/object:Gem::Version
135
- version: '0'
139
+ version: 2.5.0
136
140
  required_rubygems_version: !ruby/object:Gem::Requirement
137
141
  requirements:
138
142
  - - ">="
139
143
  - !ruby/object:Gem::Version
140
144
  version: '0'
141
145
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.4.8
146
+ rubygems_version: 3.0.1
144
147
  signing_key:
145
148
  specification_version: 4
146
149
  summary: Custom Rails-specific Rubocop cops for our internal development purposes
data/.rubocop_todo.yml DELETED
@@ -1,24 +0,0 @@
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/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.7